Skip to content

Instantly share code, notes, and snippets.

@alexkli
Created January 30, 2017 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexkli/1efcd4f3f7bb36801229e282fa0d2f55 to your computer and use it in GitHub Desktop.
Save alexkli/1efcd4f3f7bb36801229e282fa0d2f55 to your computer and use it in GitHub Desktop.
import org.apache.jackrabbit.oak.spi.commit.CommitInfo
import org.apache.jackrabbit.oak.spi.commit.EmptyHook
import org.apache.jackrabbit.oak.spi.state.NodeStore
import org.apache.jackrabbit.oak.commons.PathUtils
def removeNodes(def session, String fileWithPaths) {
println "Reading paths from ${fileWithPaths}..."
new File(fileWithPaths).eachLine { path ->
println "Removing node ${path}"
NodeStore ns = session.store
def nb = ns.root.builder()
def aBuilder = nb
for(p in PathUtils.elements(path)) { aBuilder = aBuilder.getChildNode(p) }
if(aBuilder.exists()) {
aBuilder.remove()
ns.merge(nb, EmptyHook.INSTANCE, CommitInfo.EMPTY)
} else {
println "Node ${path} doesn't exist"
}
}
}
@alexkli
Copy link
Author

alexkli commented Jan 30, 2017

Same as rmNode() script but allows to delete multiple paths in one go.

Uses a file with multiple paths as input, which might have been created using childCount.groovy and paths filtered out using

grep "warning unable to read node " childCountOutput.txt | cut -b 29- > broken-paths.txt

Run in oak-run console with

:load  https://gist.github.com/alexkli/1efcd4f3f7bb36801229e282fa0d2f55/raw/0d9554b116d2d7b72bc7ed5bf7e80bd7b6c4a9a8/removeNodes.groovy
removeNodes(session, "broken-paths.txt")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment