throw new VltException("Unable to commit changes.", e);
}
// get common ancestor
String localRoot = infos.getRootPath();
VltDirectory root = new VltDirectory(ctx, new File(localRoot));
// mount fs at the top most directory
if (root.isControlled()) {
ctx.setFsRoot(root);
}
int rootLen = ctx.getFsRoot().length();
// create transaction with all changes
VaultFsTransaction tx = ctx.getFileSystem(ctx.getMountpoint()).startTransaction();
ctx.printMessage("Collecting commit information...");
for (VltTree.Info i: infos.infos()) {
i.dir.prepareCommit(tx, i.names, nonRecursive, force);
}
// do commit (assuming all files from the same repo)
ctx.printMessage("Transmitting file data...");
List<TransactionImpl.Info> txInfos;
try {
txInfos = new ArrayList<TransactionImpl.Info>(tx.commit());
} catch (Exception e) {
throw new VltException("Error while committing", e);
}
// sort them deepest first
Collections.sort(txInfos, new Comparator<TransactionImpl.Info>(){
private final PathComparator pc = new PathComparator();
public int compare(TransactionImpl.Info o1, TransactionImpl.Info o2) {
return -pc.compare(o1.getPath(), o2.getPath());
}
});
// updating entries
infos.clear();
for (TransactionImpl.Info info: txInfos) {
if (info.getType() == TransactionImpl.Type.ERROR) {
ctx.printMessage("Could not process " + info.getPath());
continue;
}
String fileName = Text.getName(info.getPath());
// get vlt directory
String dirPath = Text.getRelativeParent(info.getPath(), 1);
if (dirPath.length() > rootLen && !localRoot.endsWith(dirPath)) {
// calculate the fs-root relative path, in case the repo was not mounted at jcr:root
dirPath = dirPath.substring(rootLen + 1);
} else if (dirPath.length() < rootLen) {
// dir path outside of the mounted repo. special case
dirPath = "";
fileName = "";
} else {
dirPath = "";
}
File localDir = new File(localRoot, dirPath);
if (!localDir.exists()) {
// directory was already deleted, just print message and continue
File file = new File(localDir, fileName);
ctx.printAction(file.getPath(), FileAction.DELETED, null);
continue;
}
VltDirectory dir = new VltDirectory(ctx, localDir);
// check if local file is a directory
File localFile = new File(localDir, fileName);
if (localFile.isDirectory()) {
dir = new VltDirectory(ctx, localFile);
} else {
dir.updateComitted(info.getPath(), fileName);
}
// remember directory
infos.put(dir);
}