use of ch.cyberduck.core.ListService in project cyberduck by iterate-ch.
the class MoveWorker method run.
@Override
public Map<Path, Path> run(final Session<?> session) throws BackgroundException {
final Session<?> destination = target.borrow(new BackgroundActionState() {
@Override
public boolean isCanceled() {
return MoveWorker.this.isCanceled();
}
@Override
public boolean isRunning() {
return true;
}
});
try {
final Move feature = session.getFeature(Move.class).withTarget(destination);
if (log.isDebugEnabled()) {
log.debug(String.format("Run with feature %s", feature));
}
final ListService list = session.getFeature(ListService.class);
// sort ascending by timestamp to move older versions first
final Map<Path, Path> sorted = new TreeMap<>(new VersionsComparator(true));
sorted.putAll(files);
final Map<Path, Path> result = new HashMap<>();
for (Map.Entry<Path, Path> entry : sorted.entrySet()) {
if (this.isCanceled()) {
throw new ConnectionCanceledException();
}
final Map<Path, Path> recursive = this.compile(feature, list, entry.getKey(), entry.getValue());
if (log.isDebugEnabled()) {
log.debug(String.format("Compiled recursive list %s", recursive));
}
for (Map.Entry<Path, Path> r : recursive.entrySet()) {
if (r.getKey().isDirectory() && !feature.isRecursive(r.getKey(), r.getValue())) {
log.warn(String.format("Move operation is not recursive. Create directory %s", r.getValue()));
// Create directory unless copy implementation is recursive
result.put(r.getKey(), session.getFeature(Directory.class).mkdir(r.getValue(), new TransferStatus().withRegion(r.getKey().attributes().getRegion())));
} else {
final TransferStatus status = this.status(session, r);
result.put(r.getKey(), feature.move(r.getKey(), r.getValue(), status, new Delete.Callback() {
@Override
public void delete(final Path file) {
listener.message(MessageFormat.format(LocaleFactory.localizedString("Deleting {0}", "Status"), file.getName()));
}
}, callback));
}
}
// Find previous folders to be deleted
final List<Path> folders = recursive.entrySet().stream().filter(f -> !feature.isRecursive(f.getKey(), f.getValue())).collect(Collectors.toCollection(ArrayList::new)).stream().map(Map.Entry::getKey).filter(Path::isDirectory).collect(Collectors.toCollection(ArrayList::new));
if (!folders.isEmpty()) {
// Must delete inverse
Collections.reverse(folders);
final Delete delete = session.getFeature(Delete.class);
for (Path folder : folders) {
log.warn(String.format("Delete source directory %s", folder));
final TransferStatus status = new TransferStatus().withLockId(this.getLockId(folder));
delete.delete(Collections.singletonMap(folder, status), callback, new Delete.DisabledCallback());
}
}
}
return result;
} finally {
target.release(destination, null);
}
}
use of ch.cyberduck.core.ListService 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.ListService in project cyberduck by iterate-ch.
the class FTPDefaultListServiceTest method testListDefaultFlag.
@Test
public void testListDefaultFlag() throws Exception {
final ListService list = new FTPDefaultListService(session, new CompositeFileEntryParser(Collections.singletonList(new UnixFTPEntryParser())), FTPListService.Command.lista);
final Path directory = new FTPWorkdirService(session).find();
final Path file = new Path(directory, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
new FTPTouchFeature(session).touch(file, new TransferStatus());
assertTrue(list.list(directory, new DisabledListProgressListener()).contains(file));
new FTPDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
use of ch.cyberduck.core.ListService in project cyberduck by iterate-ch.
the class FTPListServiceTest method testListIOFailureStat.
@Test(expected = ConnectionTimeoutException.class)
public void testListIOFailureStat() throws Exception {
final FTPListService service = new FTPListService(session, null, TimeZone.getDefault());
service.remove(FTPListService.Command.lista);
service.remove(FTPListService.Command.mlsd);
final AtomicBoolean set = new AtomicBoolean();
service.implementations.put(FTPListService.Command.stat, new ListService() {
@Override
public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException {
if (set.get()) {
fail();
}
set.set(true);
throw new ConnectionTimeoutException("t", new SocketTimeoutException());
}
});
final Path directory = new FTPWorkdirService(session).find();
final AttributedList<Path> list = service.list(directory, new DisabledListProgressListener());
}
use of ch.cyberduck.core.ListService in project cyberduck by iterate-ch.
the class FTPMlsdListServiceTest method testList.
@Test
public void testList() throws Exception {
final ListService list = new FTPMlsdListService(session);
final Path directory = new FTPWorkdirService(session).find();
assertFalse(list.list(directory, new DisabledListProgressListener()).isEmpty());
}
Aggregations