Search in sources :

Example 1 with ListService

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);
    }
}
Also used : Path(ch.cyberduck.core.Path) CachingFindFeature(ch.cyberduck.core.CachingFindFeature) Move(ch.cyberduck.core.features.Move) Delete(ch.cyberduck.core.features.Delete) CachingAttributesFinderFeature(ch.cyberduck.core.CachingAttributesFinderFeature) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) HashMap(java.util.HashMap) ListService(ch.cyberduck.core.ListService) StringUtils(org.apache.commons.lang3.StringUtils) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ConnectionCanceledException(ch.cyberduck.core.exception.ConnectionCanceledException) Cache(ch.cyberduck.core.Cache) Map(java.util.Map) Find(ch.cyberduck.core.features.Find) AttributesFinder(ch.cyberduck.core.features.AttributesFinder) Session(ch.cyberduck.core.Session) AttributedList(ch.cyberduck.core.AttributedList) LocaleFactory(ch.cyberduck.core.LocaleFactory) MappingMimeTypeService(ch.cyberduck.core.MappingMimeTypeService) TimestampComparator(ch.cyberduck.ui.comparator.TimestampComparator) BackgroundException(ch.cyberduck.core.exception.BackgroundException) DefaultAttributesFinderFeature(ch.cyberduck.core.shared.DefaultAttributesFinderFeature) Collectors(java.util.stream.Collectors) BackgroundActionState(ch.cyberduck.core.threading.BackgroundActionState) Objects(java.util.Objects) List(java.util.List) Logger(org.apache.logging.log4j.Logger) TreeMap(java.util.TreeMap) SessionPool(ch.cyberduck.core.pool.SessionPool) Path(ch.cyberduck.core.Path) ProgressListener(ch.cyberduck.core.ProgressListener) DefaultFindFeature(ch.cyberduck.core.shared.DefaultFindFeature) Directory(ch.cyberduck.core.features.Directory) ConnectionCallback(ch.cyberduck.core.ConnectionCallback) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) Delete(ch.cyberduck.core.features.Delete) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ConnectionCanceledException(ch.cyberduck.core.exception.ConnectionCanceledException) BackgroundActionState(ch.cyberduck.core.threading.BackgroundActionState) TreeMap(java.util.TreeMap) ListService(ch.cyberduck.core.ListService) ConnectionCallback(ch.cyberduck.core.ConnectionCallback) Move(ch.cyberduck.core.features.Move) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 2 with ListService

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());
}
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 3 with ListService

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());
}
Also used : Path(ch.cyberduck.core.Path) Delete(ch.cyberduck.core.features.Delete) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) UnixFTPEntryParser(org.apache.commons.net.ftp.parser.UnixFTPEntryParser) CompositeFileEntryParser(ch.cyberduck.core.ftp.parser.CompositeFileEntryParser) ListService(ch.cyberduck.core.ListService) FTPDeleteFeature(ch.cyberduck.core.ftp.FTPDeleteFeature) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) FTPWorkdirService(ch.cyberduck.core.ftp.FTPWorkdirService) FTPTouchFeature(ch.cyberduck.core.ftp.FTPTouchFeature) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest) AbstractFTPTest(ch.cyberduck.core.ftp.AbstractFTPTest)

Example 4 with ListService

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());
}
Also used : Path(ch.cyberduck.core.Path) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) ListService(ch.cyberduck.core.ListService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ConnectionTimeoutException(ch.cyberduck.core.exception.ConnectionTimeoutException) SocketTimeoutException(java.net.SocketTimeoutException) AttributedList(ch.cyberduck.core.AttributedList) ListProgressListener(ch.cyberduck.core.ListProgressListener) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) FTPWorkdirService(ch.cyberduck.core.ftp.FTPWorkdirService) BackgroundException(ch.cyberduck.core.exception.BackgroundException) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest) AbstractFTPTest(ch.cyberduck.core.ftp.AbstractFTPTest)

Example 5 with ListService

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());
}
Also used : ListService(ch.cyberduck.core.ListService) Path(ch.cyberduck.core.Path) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) FTPWorkdirService(ch.cyberduck.core.ftp.FTPWorkdirService) AbstractFTPTest(ch.cyberduck.core.ftp.AbstractFTPTest) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Aggregations

ListService (ch.cyberduck.core.ListService)12 Path (ch.cyberduck.core.Path)12 DisabledListProgressListener (ch.cyberduck.core.DisabledListProgressListener)7 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)7 IntegrationTest (ch.cyberduck.test.IntegrationTest)7 Test (org.junit.Test)7 AbstractFTPTest (ch.cyberduck.core.ftp.AbstractFTPTest)6 FTPWorkdirService (ch.cyberduck.core.ftp.FTPWorkdirService)6 Delete (ch.cyberduck.core.features.Delete)5 AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)4 FTPTouchFeature (ch.cyberduck.core.ftp.FTPTouchFeature)4 AttributedList (ch.cyberduck.core.AttributedList)3 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)3 BackgroundException (ch.cyberduck.core.exception.BackgroundException)3 ConnectionCanceledException (ch.cyberduck.core.exception.ConnectionCanceledException)3 FTPDeleteFeature (ch.cyberduck.core.ftp.FTPDeleteFeature)3 CompositeFileEntryParser (ch.cyberduck.core.ftp.parser.CompositeFileEntryParser)3 LinkedHashMap (java.util.LinkedHashMap)3 ListProgressListener (ch.cyberduck.core.ListProgressListener)2 Directory (ch.cyberduck.core.features.Directory)2