@Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { return delegate.list(vault.encrypt(session, directory), new DecryptingListProgressListener(session, vault, listener)); }
@Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { try { return delegate.list(directory, new ProxyListProgressListener(finder, listener)); } catch(VaultFoundListCanceledException finder) { final Vault cryptomator = finder.getVault(); if(log.isInfoEnabled()) { log.info(String.format("Found vault %s", cryptomator)); } return delegate.list(cryptomator.encrypt(session, directory), new DecryptingListProgressListener(session, cryptomator, listener.reset())); } }
@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("List children for %s", directory)); } final AttributedList<Path> list = session.getFeature(ListService.class).list(directory, listener).filter(comparator, filter); final Path copy = mapping.get(directory); for(Path p : list) { mapping.put(p, new Path(copy, p.getName(), p.getType(), p.attributes())); } final List<TransferItem> nullified = new ArrayList<TransferItem>(); for(Path p : list) { nullified.add(new TransferItem(p)); } return nullified; }
@Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { try { final Vault vault = registry.find(session, directory); if(vault.contains(directory)) { return vault.getFeature(session, ListService.class, proxy).list(directory, listener); } if(autodetect) { return new VaultFinderListService(session, proxy, new VaultFinderListProgressListener(lookup)).list(directory, listener); } return proxy.list(directory, listener); } catch(VaultUnlockCancelException e) { log.warn(String.format("Canceled loading vault %s. %s", e.getVault(), e.getDetail())); throw e; } }
@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("List children for %s", directory)); } if(directory.isSymbolicLink() && new DownloadSymlinkResolver(roots).resolve(directory)) { if(log.isDebugEnabled()) { log.debug(String.format("Do not list children for symbolic link %s", directory)); } return Collections.emptyList(); } else { final AttributedList<Path> list; if(cache.isCached(directory)) { list = cache.get(directory); } else { list = session.getFeature(ListService.class).list(directory, listener); cache.put(directory, list); } final List<TransferItem> children = new ArrayList<TransferItem>(); // Return copy with filtered result only for(Path f : new AttributedList<Path>(list.filter(comparator, filter))) { children.add(new TransferItem(f, LocalFactory.get(local, f.getName()))); } return children; } }
protected void write(final Session<?> session, final Metadata feature, final Path file) throws BackgroundException { if(this.isCanceled()) { throw new ConnectionCanceledException(); } // Read online metadata (storing non-edited metadata entries) final Map<String, String> update = new HashMap<>(file.attributes().getMetadata()); // Purge removed entries update.entrySet().removeIf(entry -> !metadata.containsKey(entry.getKey())); // iterate all metadata entries and for(Map.Entry<String, String> entry : metadata.entrySet()) { // check if update is non-null (should not) && entry value is not null if(entry.getValue() != null) { // update update.put(entry.getKey(), entry.getValue()); } } // If anything has changed save metadata, otherwise continue and do for everything underneath this directory if(!update.equals(file.attributes().getMetadata())) { listener.message(MessageFormat.format(LocaleFactory.localizedString("Writing metadata of {0}", "Status"), file.getName())); feature.setMetadata(file, update); } if(file.isDirectory()) { if(callback.recurse(file, LocaleFactory.localizedString("Metadata", "Info"))) { for(Path child : session.getFeature(ListService.class).list(file, new WorkerListProgressListener(this, listener))) { this.write(session, feature, child); } } } }
protected void write(final Session<?> session, final UnixPermission feature, final Path file, final Permission permission) throws BackgroundException { listener.message(MessageFormat.format(LocaleFactory.localizedString("Changing permission of {0} to {1}", "Status"), file.getName(), permission)); feature.setUnixPermission(file, permission); if(file.isDirectory()) { if(callback.recurse(file, permission)) { for(Path child : session.getFeature(ListService.class).list(file, new WorkerListProgressListener(this, listener))) { this.write(session, feature, child, permission); } } } }
protected Map<Path, Path> compile(final Move move, final ListService list, final Path source, final Path target) throws BackgroundException { // Compile recursive list final Map<Path, Path> recursive = new LinkedHashMap<>(); recursive.put(source, target); if(source.isDirectory()) { if(!move.isRecursive(source, target)) { // sort ascending by timestamp to move older versions first final AttributedList<Path> children = list.list(source, new WorkerListProgressListener(this, listener)). filter(new TimestampComparator(true)); for(Path child : children) { if(this.isCanceled()) { throw new ConnectionCanceledException(); } recursive.putAll(this.compile(move, list, child, new Path(target, child.getName(), child.getType()))); } } } return recursive; }
@Override public AttributedList<Path> run(final Session<?> session) throws BackgroundException { try { if(this.isCached()) { final AttributedList<Path> list = cache.get(directory); listener.chunk(directory, list); return list; } final ListService service = session.getFeature(ListService.class).withCache(cache); return service.list(directory, listener); } catch(ListCanceledException e) { return e.getChunk(); } }
@Override public AttributedList<Path> search(final Path workdir, final Filter<Path> filter, final ListProgressListener listener) throws BackgroundException { final AttributedList<Path> list; if(!cache.isCached(workdir)) { list = session.getFeature(ListService.class).list(workdir, new SearchListProgressListener(filter, listener)).filter(filter); } else { list = cache.get(workdir).filter(filter); } listener.chunk(workdir, list); return list; }
protected Map<Path, Path> compile(final Copy copy, final ListService list, final Path source, final Path target) throws BackgroundException { // Compile recursive list final Map<Path, Path> recursive = new LinkedHashMap<>(); if(source.isFile() || source.isSymbolicLink()) { recursive.put(source, target); } else if(source.isDirectory()) { // Add parent before children recursive.put(source, target); if(!copy.isRecursive(source, target)) { // sort ascending by timestamp to copy older versions first final AttributedList<Path> children = list.list(source, new WorkerListProgressListener(this, listener)). filter(new TimestampComparator(true)); for(Path child : children) { if(this.isCanceled()) { throw new ConnectionCanceledException(); } recursive.putAll(this.compile(copy, list, child, new Path(target, child.getName(), child.getType()))); } } } return recursive; }
protected void write(final Session<?> session, final Redundancy feature, final Path file) throws BackgroundException { if(this.isCanceled()) { throw new ConnectionCanceledException(); } if(!level.equals(file.attributes().getStorageClass())) { listener.message(MessageFormat.format(LocaleFactory.localizedString("Writing metadata of {0}", "Status"), file.getName())); feature.setClass(file, level); } if(file.isDirectory()) { if(callback.recurse(file, level)) { for(Path child : session.getFeature(ListService.class).list(file, new WorkerListProgressListener(this, listener))) { this.write(session, feature, child); } } } }
protected void write(final Session<?> session, final Encryption feature, final Path file) throws BackgroundException { if(this.isCanceled()) { throw new ConnectionCanceledException(); } listener.message(MessageFormat.format(LocaleFactory.localizedString("Writing metadata of {0}", "Status"), file.getName())); feature.setEncryption(file, algorithm); if(file.isDirectory()) { if(callback.recurse(file, algorithm)) { for(Path child : session.getFeature(ListService.class).list(file, new WorkerListProgressListener(this, listener))) { this.write(session, feature, child); } } } }
protected void write(final Session<?> session, final AclPermission feature, final Path file) throws BackgroundException { if(this.isCanceled()) { throw new ConnectionCanceledException(); } listener.message(MessageFormat.format(LocaleFactory.localizedString("Changing permission of {0} to {1}", "Status"), file.getName(), acl)); feature.setPermission(file, acl); if(file.isVolume()) { // No recursion when changing container ACL } else if(file.isDirectory()) { if(callback.recurse(file, acl)) { for(Path child : session.getFeature(ListService.class).list(file, new WorkerListProgressListener(this, listener))) { this.write(session, feature, child); } } } }
@Override public Permission getUnixPermission(final Path file) throws BackgroundException { try { return new FTPAttributesFinderFeature(session).find(file).getPermission(); } catch(InteroperabilityException e) { for(Path f : session.getFeature(ListService.class).list(file.getParent(), new DisabledListProgressListener())) { if(f.equals(file)) { return f.attributes().getPermission(); } } } throw new NotfoundException(file.getAbsolute()); }
/** * Calculates recursively the size of this path if a directory * Potentially lengthy operation * * @param p Directory or file * @return The size of the file or the sum of all containing files if a directory */ private long calculateSize(final Session<?> session, final Path p) throws BackgroundException { long size = 0; if(this.isCanceled()) { throw new ConnectionCanceledException(); } listener.message(MessageFormat.format(LocaleFactory.localizedString("Getting size of {0}", "Status"), p.getName())); if(p.isDirectory()) { for(Path next : session.getFeature(ListService.class).list(p, new WorkerListProgressListener(this, listener))) { size += this.calculateSize(session, next); } } else if(p.isFile()) { size += p.attributes().getSize(); total += size; this.update(total); } return size; }
@Override public Distribution run(final Session<?> session) throws BackgroundException { final DistributionConfiguration cdn = session.getFeature(DistributionConfiguration.class); for(Path file : this.getContainers(files)) { if(this.isCanceled()) { throw new ConnectionCanceledException(); } final Distribution distribution = cdn.read(file, method, prompt); if(cdn.getFeature(Index.class, distribution.getMethod()) != null) { // Make sure container items are cached for default root object. distribution.setRootDocuments(session.getFeature(ListService.class).list(containerService.getContainer(file), new DisabledListProgressListener()).toList()); } return distribution; } return this.initialize(); }
protected Path search(final Path file) throws BackgroundException { final AttributedList<Path> list; if(!cache.isCached(file.getParent())) { // Do not decrypt filenames to match with input list = session._getFeature(ListService.class).list(file.getParent(), new CachingListProgressListener(cache)); } else { list = cache.get(file.getParent()); } // Search with specific version and region final Path path = list.find(new DefaultPathPredicate(file)); if(path != null) { return path; } // Try to match path only as the version might have changed in the meantime return list.find(session.getCase() == Session.Case.insensitive ? new CaseInsensitivePathPredicate(file) : new SimplePathPredicate(file)); }
@Override public void login(final Proxy proxy, final LoginCallback prompt, final CancelCallback cancel) throws BackgroundException { final StorageCredentials credentials = client.getCredentials(); if(host.getCredentials().isPasswordAuthentication()) { // Update credentials ((StorageCredentialsAccountAndKey) credentials).updateKey(host.getCredentials().getPassword()); } else if(host.getCredentials().isTokenAuthentication()) { if(!StringUtils.equals(host.getCredentials().getToken(), ((StorageCredentialsSharedAccessSignature) credentials).getToken())) { this.interrupt(); this.open(proxy, new DisabledHostKeyCallback(), prompt); } } // Fetch reference for directory to check login credentials try { this.getFeature(ListService.class).list(new AzureHomeFinderService(this).find(), new DisabledListProgressListener() { @Override public void chunk(final Path parent, final AttributedList<Path> list) throws ListCanceledException { throw new ListCanceledException(list); } }); } catch(ListCanceledException e) { // Success } }
@Override public String getFileid(final Path file, final ListProgressListener listener) throws BackgroundException { if(StringUtils.isNotBlank(file.attributes().getVersionId())) { return file.attributes().getVersionId(); } if(cache.isCached(file.getParent())) { final AttributedList<Path> list = cache.get(file.getParent()); final Path found = list.find(new SimplePathPredicate(file)); if(null != found) { if(StringUtils.isNotBlank(found.attributes().getVersionId())) { return this.set(file, found.attributes().getVersionId()); } } } final AttributedList<Path> list = session._getFeature(ListService.class).list(file.getParent(), listener); final Path found = list.find(new SimplePathPredicate(file)); if(null == found) { throw new NotfoundException(file.getAbsolute()); } return this.set(file, found.attributes().getVersionId()); }