@Override public boolean find(final Path file) throws BackgroundException { try { // Look for metadata file to exist when searching for folder return delegate.withCache(new CryptoPathCache(cache)).find(vault.encrypt(session, file, file.isDirectory())); } catch(NotfoundException e) { return false; } }
final Directory mkdir = session._getFeature(Directory.class); final Find find = session._getFeature(Find.class); if(!find.find(metadataRoot)) { mkdir.mkdir(metadataRoot, null, new TransferStatus()); if(!find.find(firstLevel)) { mkdir.mkdir(firstLevel, null, new TransferStatus()); if(!find.find(secondLevel)) { mkdir.mkdir(secondLevel, null, new TransferStatus()); if(!find.find(metadataFile)) { new ContentWriter(session).write(metadataFile, longFileNameBytes);
final Find find = session._getFeature(Find.class); final Path dataRoot = new Path(f, "d", f.getType()); if(find.find(dataRoot)) { for(Path d : session._getFeature(ListService.class).list(dataRoot, new DisabledListProgressListener()).toList()) { metadata.addAll(session._getFeature(ListService.class).list(d, new DisabledListProgressListener()).toList()); if(find.find(metaRoot)) { for(Path m : session._getFeature(ListService.class).list(metaRoot, new DisabledListProgressListener()).toList()) { for(Path m2 : session._getFeature(ListService.class).list(m, new DisabledListProgressListener()).toList()) {
/** * Skip files that already exist on the server. */ @Override public boolean accept(final Path file, final Local local, final TransferStatus parent) throws BackgroundException { if(parent.isExists()) { if(local.isFile()) { if(find.withCache(cache).find(file)) { if(log.isInfoEnabled()) { log.info(String.format("Skip file %s", file)); } return false; } } } return super.accept(file, local, parent); } }
@Override public Path mkdir(final Path folder, final String region, final TransferStatus status) throws BackgroundException { final String directoryId = random.random(); final Path encrypt = vault.encrypt(session, folder, directoryId, false); // Create metadata file for directory final Path directoryMetadataFile = vault.encrypt(session, folder, true); if(log.isDebugEnabled()) { log.debug(String.format("Write metadata %s for folder %s", directoryMetadataFile, folder)); } new ContentWriter(session).write(directoryMetadataFile, directoryId.getBytes(Charset.forName("UTF-8"))); final Path intermediate = encrypt.getParent(); if(!session._getFeature(Find.class).find(intermediate)) { session._getFeature(Directory.class).mkdir(intermediate, region, new TransferStatus()); } // Write header final Cryptor cryptor = vault.getCryptor(); final FileHeader header = cryptor.fileHeaderCryptor().create(); status.setHeader(cryptor.fileHeaderCryptor().encryptHeader(header)); status.setNonces(new RandomNonceGenerator()); final Path target = proxy.mkdir(encrypt, region, status); // Implementation may return new copy of attributes without encryption attributes target.attributes().setDirectoryId(directoryId); target.attributes().setDecrypted(encrypt.attributes().getDecrypted()); // Make reference of encrypted path in attributes of decrypted file point to metadata file final Path decrypt = vault.decrypt(session, vault.encrypt(session, target, true)); decrypt.attributes().setVersionId(target.attributes().getVersionId()); return decrypt; }
@Override public boolean find(final Path file) throws BackgroundException { final Vault vault = registry.find(session, file); if(vault.equals(Vault.DISABLED)) { if(autodetect) { final Path directory = file.getParent(); final Path key = new Path(directory, DefaultVaultRegistry.DEFAULT_MASTERKEY_FILE_NAME, EnumSet.of(Path.Type.file)); if(proxy.withCache(cache).find(key)) { if(log.isInfoEnabled()) { log.info(String.format("Found master key %s", key)); } try { if(log.isInfoEnabled()) { log.info(String.format("Found vault %s", directory)); } return lookup.load(directory, DefaultVaultRegistry.DEFAULT_MASTERKEY_FILE_NAME, DefaultVaultRegistry.DEFAULT_PEPPER).getFeature(session, Find.class, proxy) .withCache(cache) .find(file); } catch(VaultUnlockCancelException e) { // Continue } } } } return vault.getFeature(session, Find.class, proxy) .withCache(cache) .find(file); }
@Override public List<TransferItem> list(final Session<?> session, final Path directory, final Local local, final ListProgressListener listener) throws BackgroundException { if(log.isDebugEnabled()) { log.debug(String.format("Children for %s", directory)); } final Set<TransferItem> children = new HashSet<TransferItem>(); final Find finder = session.getFeature(Find.class, new DefaultFindFeature(session)).withCache(cache); if(finder.find(directory)) { children.addAll(download.list(session, directory, local, listener)); } if(local.exists()) { children.addAll(upload.list(session, directory, local, listener)); } return new ArrayList<TransferItem>(children); }
@Override public Append append(final Path file, final Long length, final Cache<Path> cache) throws BackgroundException { if(finder.withCache(cache).find(file)) { final PathAttributes attr = attributes.withCache(cache).find(file); return new Append(attr.getSize()).withChecksum(attr.getChecksum()); } return Write.notfound; } }
@Override public Append append(final Path file, final Long length, final Cache<Path> cache) throws BackgroundException { if(finder.withCache(cache).find(file)) { final PathAttributes attr = attributes.withCache(cache).find(file); return new Append(false, true).withSize(attr.getSize()).withChecksum(attr.getChecksum()); } return Write.notfound; }
@Override public Append append(final Path file, final Long length, final Cache<Path> cache) throws BackgroundException { if(finder.withCache(cache).find(file)) { final PathAttributes attributes = this.attributes.withCache(cache).find(file); return new Append(false, true).withSize(attributes.getSize()).withChecksum(attributes.getChecksum()); } return Write.notfound; }
@Override public Append append(final Path file, final Long length, final Cache<Path> cache) throws BackgroundException { if(finder.withCache(cache).find(file)) { final PathAttributes attr = this.attributes.withCache(cache).find(file); return new Append(false, true).withSize(attr.getSize()).withChecksum(attr.getChecksum()); } return Write.notfound; }
@Override public Append append(final Path file, final Long length, final Cache<Path> cache) throws BackgroundException { if(finder.withCache(cache).find(file)) { final PathAttributes attr = attributes.withCache(cache).find(file); return new Append(false, true).withSize(attr.getSize()).withChecksum(attr.getChecksum()); } return Write.notfound; }
@Override public Append append(final Path file, final Long length, final Cache<Path> cache) throws BackgroundException { if(finder.withCache(cache).find(file)) { final PathAttributes attributes = this.attributes.withCache(cache).find(file); return new Append(false, true).withSize(attributes.getSize()).withChecksum(attributes.getChecksum()); } return Write.notfound; }
@Override public Append append(final Path file, final Long length, final Cache<Path> cache) throws BackgroundException { if(finder.withCache(cache).find(file)) { final PathAttributes attr = attributes.withCache(cache).find(file); return new Append(false, true).withSize(attr.getSize()).withChecksum(attr.getChecksum()); } return Write.notfound; } }
@Override public Append append(final Path file, final Long length, final Cache<Path> cache) throws BackgroundException { if(finder.withCache(cache).find(file)) { final PathAttributes attr = attributes.withCache(cache).find(file); return new Append(false, true).withSize(attr.getSize()).withChecksum(attr.getChecksum()); } return Write.notfound; }
/** * Manta does not support raw append operations. */ @Override public Append append(final Path file, final Long length, final Cache<Path> cache) throws BackgroundException { if(finder.withCache(cache).find(file)) { final PathAttributes attr = attributes.withCache(cache).find(file); return new Append(false, true).withSize(attr.getSize()).withChecksum(attr.getChecksum()); } return Write.notfound; }
@Override public Append append(final Path file, final Long length, final Cache<Path> cache) throws BackgroundException { if(finder.withCache(cache).find(file)) { final PathAttributes attr = attributes.withCache(cache).find(file); return new Append(false, true).withSize(attr.getSize()).withChecksum(attr.getChecksum()); } return Write.notfound; }
@Override public Append append(final Path file, final Long length, final Cache<Path> cache) throws BackgroundException { if(finder.withCache(cache).find(file)) { final PathAttributes attr = attributes.withCache(cache).find(file); return new Append(false, true).withSize(attr.getSize()).withChecksum(attr.getChecksum()); } return Write.notfound; }
@Override public Append append(final Path file, final Long length, final Cache<Path> cache) throws BackgroundException { if(finder.withCache(cache).find(vault.encrypt(session, file))) { final PathAttributes attributes = this.attributes.withCache(cache).find(vault.encrypt(session, file)); return new Append(false, true).withSize(attributes.getSize()).withChecksum(attributes.getChecksum()); } return Write.notfound; }
/** * Rename existing file on server if there is a conflict. */ @Override public void apply(final Path file, final Local local, final TransferStatus status, final ProgressListener listener) throws BackgroundException { // Rename existing file before putting new file in place if(status.isExists()) { Path rename; do { final String proposal = MessageFormat.format(PreferencesFactory.get().getProperty("queue.upload.file.rename.format"), FilenameUtils.getBaseName(file.getName()), UserDateFormatterFactory.get().getMediumFormat(System.currentTimeMillis(), false).replace(Path.DELIMITER, '-').replace(':', '-'), StringUtils.isNotBlank(file.getExtension()) ? String.format(".%s", file.getExtension()) : StringUtils.EMPTY); rename = new Path(file.getParent(), proposal, file.getType()); } while(find.withCache(cache).find(rename)); if(log.isInfoEnabled()) { log.info(String.format("Rename existing file %s to %s", file, rename)); } move.move(file, rename, new TransferStatus().exists(false), new Delete.DisabledCallback(), new DisabledConnectionCallback()); if(log.isDebugEnabled()) { log.debug(String.format("Clear exist flag for file %s", file)); } status.setExists(false); } super.apply(file, local, status, listener); } }