@Override public Path copy(final Path source, final Path copy, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { if(registry.find(session, source).equals(Vault.DISABLED)) { return registry.find(session, copy).getFeature(session, Copy.class, proxy).withTarget(destination).copy(source, copy, status, callback); } else if(registry.find(session, copy).equals(Vault.DISABLED)) { return registry.find(session, source).getFeature(session, Copy.class, proxy).withTarget(destination).copy(source, copy, status, callback); } else { // Move files inside vault. May use server side copy. return registry.find(session, copy).getFeature(session, Copy.class, proxy).withTarget(destination).copy(source, copy, status, callback); } }
@Override public boolean isRecursive(final Path source, final Path copy) { try { if(registry.find(session, source, false).equals(Vault.DISABLED)) { return registry.find(session, copy, false).getFeature(session, Copy.class, proxy).withTarget(destination).isRecursive(source, copy); } else if(registry.find(session, copy, false).equals(Vault.DISABLED)) { return registry.find(session, source, false).getFeature(session, Copy.class, proxy).withTarget(destination).isRecursive(source, copy); } return registry.find(session, copy).getFeature(session, Copy.class, proxy).withTarget(destination).isRecursive(source, copy); } catch(VaultUnlockCancelException e) { return proxy.isRecursive(source, copy); } }
@Override public boolean isSupported(final Path source, final Path copy) { try { if(registry.find(session, source, false).equals(Vault.DISABLED)) { return registry.find(session, copy, false).getFeature(session, Copy.class, proxy).withTarget(destination).isSupported(source, copy); } else if(registry.find(session, copy, false).equals(Vault.DISABLED)) { return registry.find(session, source, false).getFeature(session, Copy.class, proxy).withTarget(destination).isSupported(source, copy); } return registry.find(session, copy).getFeature(session, Copy.class, proxy).withTarget(destination).isSupported(source, copy); } catch(VaultUnlockCancelException e) { return proxy.isSupported(source, copy); } }
@Override public Path move(final Path source, final Path target, final TransferStatus status, final Delete.Callback delete, final ConnectionCallback callback) throws BackgroundException { final Vault vault = registry.find(session, source); if(vault.equals(registry.find(session, target, false))) { if(log.isDebugEnabled()) { log.debug(String.format("Move %s to %s inside vault %s", source, target, vault)); } // Move files inside vault return vault.getFeature(session, Move.class, proxy).move(source, target, status, delete, callback); } else { // Moving files from or into vault requires to pass through encryption features using copy operation final Path copy = session.getFeature(Copy.class).withTarget(destination).copy(source, target, status, callback); // Delete source file after copy is complete session.getFeature(Delete.class).delete(Collections.singletonList(source), callback, delete); return copy; } }
@Override public boolean isSupported(final Path source, final Path copy) { if(vault.contains(source) && vault.contains(copy)) { return proxy.withTarget(target).isSupported(source, copy); } return new DefaultCopyFeature(session).withTarget(target).isSupported(source, copy); }
final Copy copy = session.getFeature(Copy.class).withTarget(destination); final ListService list = session.getFeature(ListService.class); final Map<Path, Path> result = new HashMap<>();
@Override public Path copy(final Path source, final Path copy, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { if(vault.contains(copy)) { // Write header to be reused in writer final Cryptor cryptor = vault.getCryptor(); final FileHeader header = cryptor.fileHeaderCryptor().create(); status.setHeader(cryptor.fileHeaderCryptor().encryptHeader(header)); status.setNonces(new RandomNonceGenerator()); } if(vault.contains(source) && vault.contains(copy)) { return vault.decrypt(session, proxy.withTarget(target).copy( vault.contains(source) ? vault.encrypt(session, source) : source, vault.contains(copy) ? vault.encrypt(session, copy) : copy, status, callback)); } else { // Copy files from or into vault requires to pass through encryption features final Path target = new DefaultCopyFeature(session).withTarget(this.target).copy( vault.contains(source) ? vault.encrypt(session, source) : source, vault.contains(copy) ? vault.encrypt(session, copy) : copy, status, callback); if(vault.contains(copy)) { return vault.decrypt(session, target); } return target; } }