in vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/Importer.java [1044:1199]
private ImportInfoImpl commit(Session session, TxInfo info) throws RepositoryException, IOException {
log.trace("committing {}", info.path);
ImportInfoImpl imp = null;
if (info.artifacts == null) {
log.debug("S {}", info.path);
} else if (info.artifacts.isEmpty()) {
// intermediate directory, check if node exists and filter
// matches. in this case remove the node (bug #25370)
// but only if intermediate is not processed yet (bug #42562)
if (filter.contains(info.path) && session.nodeExists(info.path) && info.isIntermediate < 2) {
Node node = session.getNode(info.path);
imp = new ImportInfoImpl();
if (aclManagement.isACLNode(node)) {
// Judging from isACLNode behavior, this part only applies
// to "rep:Policy" nodes so no need for special handling of CUG case.
if (opts.getAccessControlHandling() == AccessControlHandling.OVERWRITE
|| opts.getAccessControlHandling() == AccessControlHandling.CLEAR) {
imp.onDeleted(info.path);
aclManagement.clearACL(node.getParent());
}
} else {
if (filter.getImportMode(info.path) == ImportMode.REPLACE) {
imp.onDeleted(info.path);
node.remove();
} else {
imp.onNop(info.path);
}
}
}
} else if (info.artifacts.getPrimaryData() !=null && info.artifacts.size() == 1) {
// simple case, only 1 primary artifact
Node node = info.getParentNode(session);
if (node == null) {
imp = new ImportInfoImpl();
imp.onError(info.path, new IllegalStateException("Parent node not found."));
} else {
imp = genericHandler.accept(opts, isStrictByDefault, filter, node, info.artifacts.getPrimaryData().getRelativePath(), info.artifacts);
if (imp == null) {
throw new IllegalStateException("generic handler did not accept " + info.path);
}
}
} else if (info.artifacts.getDirectory() != null) {
String prefix = info.parent == null ? info.name : info.name + "/";
for (TxInfo child: info.children().values()) {
// add the directory artifacts as hint to this one.
if (child.artifacts == null) {
// in this case it's some deleted intermediate directory???
String path = prefix + child.name;
info.artifacts.add(new HintArtifact(path));
} else {
for (Artifact a: child.artifacts.values()) {
String path = prefix + a.getRelativePath();
info.artifacts.add(new HintArtifact(path));
}
}
}
Node node = info.getParentNode(session);
if (node == null) {
imp = new ImportInfoImpl();
imp.onError(info.path, new IllegalStateException("Parent node not found."));
} else {
if (info.isIntermediate == 2) {
// skip existing intermediate
log.trace("skipping intermediate node at {}", info.path);
} else if (info.artifacts.getPrimaryData() == null) {
// create nt:folder node if not exists
imp = folderHandler.accept(opts, isStrictByDefault, filter, node, info.name, info.artifacts);
if (imp == null) {
throw new IllegalStateException("folder handler did not accept " + info.path);
}
} else {
imp = genericHandler.accept(opts, isStrictByDefault, filter, node, info.artifacts.getDirectory().getRelativePath(), info.artifacts);
if (imp == null) {
throw new IllegalStateException("generic handler did not accept " + info.path);
}
}
}
} else if (info.artifacts.size(ArtifactType.FILE) > 0) {
Node node = info.getParentNode(session);
if (node == null) {
imp = new ImportInfoImpl();
imp.onError(info.path, new IllegalStateException("Parent node not found."));
} else {
imp = fileHandler.accept(opts, isStrictByDefault, filter, node, info.name, info.artifacts);
if (imp == null) {
throw new IllegalStateException("file handler did not accept " + info.path);
}
}
} else {
throw new UnsupportedOperationException("ArtifactSet not supported: " + info.artifacts);
}
if (imp != null) {
for (Map.Entry<String, ImportInfo.Info> entry: imp.getInfos().entrySet()) {
String path = entry.getKey();
ImportInfo.Type type = entry.getValue().getType();
if (type != ImportInfoImpl.Type.DEL) {
// mark intermediates as processed
TxInfo im = intermediates.remove(path);
if (im != null) {
log.debug("P {}", path);
removedIntermediates.put(path, im);
im.isIntermediate = 2;
}
}
switch (type) {
case CRE:
track("A", path);
break;
case DEL:
track("D", path);
break;
case MOD:
track("U", path);
break;
case NOP:
track("-", path);
break;
case REP:
track("R", path);
break;
case MIS:
track("!", path);
break;
case ERR:
Exception error = entry.getValue().getError();
if (error == null) {
track("E", path);
} else {
track(error, path);
}
hasErrors = true;
if (firstException == null) {
firstException = new PackageException("Error creating/updating node " + path, error);
}
break;
}
// see if any child nodes need to be reordered and remember namelist.
// only restore order if in filter scope if freshly created
NodeNameList nameList = entry.getValue().getNameList();
if (nameList != null && (filter.contains(path) || type == ImportInfo.Type.CRE)) {
TxInfo subInfo = info.findChild(path);
if (subInfo != null) {
subInfo.nameList = nameList;
}
}
}
// remap the child tree in case some of the nodes where moved during import (e.g. authorizable)
// todo: this could be a problem during error recovery
info = info.remap(imp.getRemapped());
}
log.trace("committed {}", info.path);
return imp;
}