private void prepareCommit()

in vault-vlt/src/main/java/org/apache/jackrabbit/vault/vlt/VltDirectory.java [263:334]


    private void prepareCommit(VaultFsTransaction tx, VaultFile remoteDir,
                               VltFile file, boolean nonRecursive, boolean force)
            throws VltException {
        VaultFile remoteFile;
        try {
            remoteFile = remoteDir == null
                    ? null
                    : remoteDir.getChild(file.getName());
        } catch (RepositoryException e) {
            throw ctx.exception(file.getPath(), "Error while retrieving status", e);
        }

        if (file.status(remoteFile) != FileAction.VOID && !force) {
            throw ctx.error(file.getPath(), "Some files need to be updated first." +
                    " Specify --force to overwrite remote files.");
        }
        try {
            switch (file.getStatus()) {
                case MODIFIED:
                    FileInputSource fis = new FileInputSource(file.getFile());
                    if (file.isBinary()) {
                        fis.setLineSeparator(LineOutputStream.LS_BINARY);
                    }
                    tx.modify(remoteFile, fis);
                    ctx.printMessage("sending....", file);
                    break;
                case DELETED:
                    tx.delete(remoteFile);
                    ctx.printMessage("deleting...", file);
                    break;
                case ADDED:
                    String path = this.getEntries().getPath();
                    if (path.endsWith("/")) {
                        path += file.getName();
                    } else {
                        path += "/" + file.getName();
                    }
                    if (file.canDescend()) {
                        tx.mkdir(path);
                    } else {
                        fis = new FileInputSource(file.getFile());
                        if (file.isBinary()) {
                            fis.setLineSeparator(LineOutputStream.LS_BINARY);
                        }
                        VaultFileOutput out = tx.add(path, fis);
                        // set the content type hint
                        out.setContentType(file.getContentType());
                    }
                    ctx.printMessage("adding.....", file);
                    break;
                default:
                    // ignore
            }
        } catch (IOException e) {
            ctx.exception(file.getPath(), "Error while preparing commit.", e);
        } catch (RepositoryException e) {
            ctx.exception(file.getPath(), "Error while preparing commit.", e);
        }

        if (file.canDescend() && !nonRecursive) {
            VltDirectory dir = file.descend();
            if (dir.isControlled()) {
                // add all files in this directory
                VaultFile remDir = dir.getRemoteDirectory(ctx);
                for (VltFile child: dir.getFiles()) {
                    dir.prepareCommit(tx, remDir, child, nonRecursive, force);
                }
                dir.saveEntries();
            }
            dir.close();
        }
    }