Search in sources :

Example 1 with Trash

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());
}
Also used : Delete(ch.cyberduck.core.features.Delete) ListService(ch.cyberduck.core.ListService) Path(ch.cyberduck.core.Path) ConnectionCanceledException(ch.cyberduck.core.exception.ConnectionCanceledException) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) ArrayList(java.util.ArrayList) Trash(ch.cyberduck.core.features.Trash) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with Trash

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);
    }
}
Also used : Path(ch.cyberduck.core.Path) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) Vault(ch.cyberduck.core.features.Vault) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) HashMap(java.util.HashMap) Trash(ch.cyberduck.core.features.Trash)

Aggregations

Path (ch.cyberduck.core.Path)2 Trash (ch.cyberduck.core.features.Trash)2 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)2 LinkedHashMap (java.util.LinkedHashMap)2 ListService (ch.cyberduck.core.ListService)1 ConnectionCanceledException (ch.cyberduck.core.exception.ConnectionCanceledException)1 Delete (ch.cyberduck.core.features.Delete)1 Vault (ch.cyberduck.core.features.Vault)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1