use of ch.cyberduck.core.features.Trash in project cyberduck by iterate-ch.
the class DeleteWorker method run.
@Override
public List<Path> run(final Session<?> session) throws BackgroundException {
final Delete delete;
if (trash) {
if (null == session.getFeature(Trash.class)) {
log.warn(String.format("No trash feature available for %s", session));
delete = session.getFeature(Delete.class);
} else {
delete = session.getFeature(Trash.class);
}
} else {
delete = session.getFeature(Delete.class);
}
final ListService list = session.getFeature(ListService.class);
final Map<Path, TransferStatus> recursive = new LinkedHashMap<>();
for (Path file : files) {
if (this.isCanceled()) {
throw new ConnectionCanceledException();
}
recursive.putAll(this.compile(session.getHost(), delete, list, new WorkerListProgressListener(this, listener), file));
}
// Iterate again to delete any files that can be omitted when recursive operation is supported
if (delete.isRecursive()) {
recursive.keySet().removeIf(f -> recursive.keySet().stream().anyMatch(f::isChild));
}
delete.delete(recursive, prompt, new Delete.Callback() {
@Override
public void delete(final Path file) {
listener.message(MessageFormat.format(LocaleFactory.localizedString("Deleting {0}", "Status"), file.getName()));
}
});
return new ArrayList<>(recursive.keySet());
}
use of ch.cyberduck.core.features.Trash in project cyberduck by iterate-ch.
the class VaultRegistryTrashFeature method delete.
@Override
public void delete(final Map<Path, TransferStatus> files, final PasswordCallback prompt, final Callback callback) throws BackgroundException {
final Map<Vault, Map<Path, TransferStatus>> vaults = new HashMap<>();
for (Map.Entry<Path, TransferStatus> file : files.entrySet()) {
final Vault vault = registry.find(session, file.getKey());
final Map<Path, TransferStatus> sorted;
if (vaults.containsKey(vault)) {
sorted = vaults.get(vault);
} else {
sorted = new LinkedHashMap<>();
}
sorted.put(file.getKey(), file.getValue());
vaults.put(vault, sorted);
}
for (Map.Entry<Vault, Map<Path, TransferStatus>> entry : vaults.entrySet()) {
final Vault vault = entry.getKey();
final Trash feature = vault.getFeature(session, Trash.class, proxy);
feature.delete(entry.getValue(), prompt, callback);
}
}
Aggregations