Search in sources :

Example 1 with Session

use of ch.cyberduck.core.Session 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 Session

use of ch.cyberduck.core.Session in project cyberduck by iterate-ch.

the class DefaultSessionPoolTest method testCheckReconnectApplicationFailure.

@Test
public void testCheckReconnectApplicationFailure() throws Exception {
    final AtomicBoolean interrupt = new AtomicBoolean();
    final Host bookmark = new Host(new TestProtocol());
    final TestLoginConnectionService connect = new TestLoginConnectionService() {

        @Override
        public boolean check(final Session<?> session, final CancelCallback callback) {
            return true;
        }
    };
    final DefaultSessionPool pool = new DefaultSessionPool(connect, new DefaultVaultRegistry(new DisabledPasswordCallback()), new DisabledTranscriptListener(), bookmark, new GenericObjectPool<Session>(new PooledSessionFactory(connect, new DisabledX509TrustManager(), new DefaultX509KeyManager(), bookmark, new DefaultVaultRegistry(new DisabledPasswordCallback())) {

        @Override
        public Session create() {
            return new NullSession(bookmark) {

                @Override
                public void interrupt() throws BackgroundException {
                    interrupt.set(true);
                    super.interrupt();
                }
            };
        }
    }));
    final Session<?> session = pool.borrow(BackgroundActionState.running);
    pool.release(session, new BackgroundException("m", "d"));
    assertFalse(interrupt.get());
}
Also used : DisabledX509TrustManager(ch.cyberduck.core.ssl.DisabledX509TrustManager) TestProtocol(ch.cyberduck.core.TestProtocol) NullSession(ch.cyberduck.core.NullSession) Host(ch.cyberduck.core.Host) DisabledTranscriptListener(ch.cyberduck.core.DisabledTranscriptListener) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestLoginConnectionService(ch.cyberduck.core.TestLoginConnectionService) DefaultVaultRegistry(ch.cyberduck.core.vault.DefaultVaultRegistry) CancelCallback(ch.cyberduck.core.threading.CancelCallback) DisabledPasswordCallback(ch.cyberduck.core.DisabledPasswordCallback) DefaultX509KeyManager(ch.cyberduck.core.ssl.DefaultX509KeyManager) BackgroundException(ch.cyberduck.core.exception.BackgroundException) NullSession(ch.cyberduck.core.NullSession) Session(ch.cyberduck.core.Session) Test(org.junit.Test)

Example 3 with Session

use of ch.cyberduck.core.Session in project cyberduck by iterate-ch.

the class DefaultSessionPoolTest method testCheckReconnectSocketFailure.

@Test
public void testCheckReconnectSocketFailure() throws Exception {
    final AtomicBoolean interrupt = new AtomicBoolean();
    final Host bookmark = new Host(new TestProtocol());
    final TestLoginConnectionService connect = new TestLoginConnectionService() {

        @Override
        public boolean check(final Session<?> session, final CancelCallback callback) {
            return true;
        }
    };
    final DefaultSessionPool pool = new DefaultSessionPool(connect, new DefaultVaultRegistry(new DisabledPasswordCallback()), new DisabledTranscriptListener(), bookmark, new GenericObjectPool<Session>(new PooledSessionFactory(connect, new DisabledX509TrustManager(), new DefaultX509KeyManager(), bookmark, new DefaultVaultRegistry(new DisabledPasswordCallback())) {

        @Override
        public Session create() {
            return new NullSession(bookmark) {

                @Override
                public void interrupt() throws BackgroundException {
                    interrupt.set(true);
                    super.interrupt();
                }
            };
        }
    }));
    final Session<?> session = pool.borrow(BackgroundActionState.running);
    pool.release(session, new BackgroundException("m", new SocketException("m")));
    assertTrue(interrupt.get());
}
Also used : SocketException(java.net.SocketException) DisabledX509TrustManager(ch.cyberduck.core.ssl.DisabledX509TrustManager) TestProtocol(ch.cyberduck.core.TestProtocol) NullSession(ch.cyberduck.core.NullSession) Host(ch.cyberduck.core.Host) DisabledTranscriptListener(ch.cyberduck.core.DisabledTranscriptListener) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestLoginConnectionService(ch.cyberduck.core.TestLoginConnectionService) DefaultVaultRegistry(ch.cyberduck.core.vault.DefaultVaultRegistry) CancelCallback(ch.cyberduck.core.threading.CancelCallback) DisabledPasswordCallback(ch.cyberduck.core.DisabledPasswordCallback) DefaultX509KeyManager(ch.cyberduck.core.ssl.DefaultX509KeyManager) BackgroundException(ch.cyberduck.core.exception.BackgroundException) NullSession(ch.cyberduck.core.NullSession) Session(ch.cyberduck.core.Session) Test(org.junit.Test)

Example 4 with Session

use of ch.cyberduck.core.Session in project cyberduck by iterate-ch.

the class SingleTransferWorkerTest method testUploadPrepareOverrideRootDoesNotExist.

@Test
public void testUploadPrepareOverrideRootDoesNotExist() throws Exception {
    final Path child = new Path("/t/c", EnumSet.of(Path.Type.file));
    final Path root = new Path("/t", EnumSet.of(Path.Type.directory)) {

        @Override
        public Path getParent() {
            return new Path("/", EnumSet.of(Path.Type.directory));
        }
    };
    final NullLocal local = new NullLocal("l") {

        @Override
        public AttributedList<Local> list() {
            AttributedList<Local> l = new AttributedList<Local>();
            l.add(new NullLocal(this.getAbsolute(), "c") {

                @Override
                public boolean exists() {
                    return true;
                }
            });
            return l;
        }

        @Override
        public boolean exists() {
            return true;
        }
    };
    final Transfer t = new UploadTransfer(new Host(new TestProtocol()), root, local) {

        @Override
        public void transfer(final Session<?> source, final Session<?> destination, final Path file, Local local, final TransferOptions options, final TransferStatus overall, final TransferStatus segment, final ConnectionCallback connectionCallback, final ProgressListener listener, final StreamListener streamListener) {
        // 
        }
    };
    final NullSession session = new NullSession(new Host(new TestProtocol()));
    final SingleTransferWorker worker = new SingleTransferWorker(session, session, t, new TransferOptions(), new TransferSpeedometer(t), new DisabledTransferPrompt() {

        @Override
        public TransferAction prompt(final TransferItem file) {
            return TransferAction.overwrite;
        }
    }, new DisabledTransferErrorCallback(), new DisabledProgressListener(), new DisabledStreamListener(), new DisabledLoginCallback(), new DisabledNotificationService()) {

        @Override
        public Future<TransferStatus> transfer(final TransferItem item, final TransferAction action) throws BackgroundException {
            if (item.remote.equals(root)) {
                assertTrue(this.getCache().isCached(new TransferItem(root, local)));
            }
            super.transfer(new TransferItem(item.remote, new NullLocal("l") {

                @Override
                public AttributedList<Local> list() {
                    AttributedList<Local> l = new AttributedList<Local>();
                    l.add(new NullLocal(this.getAbsolute(), "c"));
                    return l;
                }
            }), action);
            assertFalse(this.getCache().isCached(new TransferItem(child, local)));
            return null;
        }
    };
    worker.run(session);
    assertFalse(worker.getCache().isCached(new TransferItem(child, local)));
}
Also used : TestProtocol(ch.cyberduck.core.TestProtocol) TransferAction(ch.cyberduck.core.transfer.TransferAction) NullSession(ch.cyberduck.core.NullSession) TransferOptions(ch.cyberduck.core.transfer.TransferOptions) NullLocal(ch.cyberduck.core.NullLocal) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) StreamListener(ch.cyberduck.core.io.StreamListener) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) DisabledTransferErrorCallback(ch.cyberduck.core.transfer.DisabledTransferErrorCallback) Path(ch.cyberduck.core.Path) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) DisabledNotificationService(ch.cyberduck.core.notification.DisabledNotificationService) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) NullLocal(ch.cyberduck.core.NullLocal) Local(ch.cyberduck.core.Local) Host(ch.cyberduck.core.Host) DisabledTransferPrompt(ch.cyberduck.core.transfer.DisabledTransferPrompt) AttributedList(ch.cyberduck.core.AttributedList) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) ListProgressListener(ch.cyberduck.core.ListProgressListener) ProgressListener(ch.cyberduck.core.ProgressListener) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) UploadTransfer(ch.cyberduck.core.transfer.UploadTransfer) Transfer(ch.cyberduck.core.transfer.Transfer) DownloadTransfer(ch.cyberduck.core.transfer.DownloadTransfer) UploadTransfer(ch.cyberduck.core.transfer.UploadTransfer) ConnectionCallback(ch.cyberduck.core.ConnectionCallback) TransferSpeedometer(ch.cyberduck.core.transfer.TransferSpeedometer) TransferItem(ch.cyberduck.core.transfer.TransferItem) NullSession(ch.cyberduck.core.NullSession) Session(ch.cyberduck.core.Session) Test(org.junit.Test)

Example 5 with Session

use of ch.cyberduck.core.Session in project cyberduck by iterate-ch.

the class SingleTransferWorkerTest method testDownloadPrepareOverride.

@Test
public void testDownloadPrepareOverride() throws Exception {
    final Path child = new Path("/t/c", EnumSet.of(Path.Type.file));
    final Path root = new Path("/t", EnumSet.of(Path.Type.directory));
    final NullLocal local = new NullLocal("l") {

        @Override
        public boolean exists() {
            return true;
        }

        @Override
        public boolean isDirectory() {
            return true;
        }

        @Override
        public boolean isFile() {
            return false;
        }

        @Override
        public AttributedList<Local> list() {
            return AttributedList.emptyList();
        }
    };
    final Transfer t = new DownloadTransfer(new Host(new TestProtocol()), root, local) {

        @Override
        public void transfer(final Session<?> source, final Session<?> destination, final Path file, Local local, final TransferOptions options, final TransferStatus overall, final TransferStatus segment, final ConnectionCallback connectionCallback, final ProgressListener listener, final StreamListener streamListener) {
            if (file.equals(root)) {
                assertTrue(segment.isExists());
            } else {
                assertFalse(segment.isExists());
            }
        }

        @Override
        public AbstractDownloadFilter filter(final Session<?> source, final Session<?> destination, final TransferAction action, final ProgressListener listener) {
            return super.filter(source, destination, action, listener).withAttributes(new AttributesFinder() {

                @Override
                public PathAttributes find(final Path file, final ListProgressListener listener) {
                    return file.attributes();
                }
            });
        }
    };
    final NullSession session = new NullSession(new Host(new TestProtocol())) {

        @Override
        public AttributedList<Path> list(final Path file, final ListProgressListener listener) {
            final AttributedList<Path> children = new AttributedList<Path>();
            children.add(child);
            return children;
        }
    };
    final SingleTransferWorker worker = new SingleTransferWorker(session, session, t, new TransferOptions(), new TransferSpeedometer(t), new DisabledTransferPrompt() {

        @Override
        public TransferAction prompt(final TransferItem file) {
            return TransferAction.overwrite;
        }
    }, new DisabledTransferErrorCallback(), new DisabledProgressListener(), new DisabledStreamListener(), new DisabledLoginCallback(), new DisabledNotificationService()) {

        @Override
        public Future<TransferStatus> transfer(final TransferItem item, final TransferAction action) throws BackgroundException {
            if (item.remote.equals(root)) {
                assertTrue(this.getCache().isCached(new TransferItem(root, local)));
            }
            super.transfer(new TransferItem(item.remote, new NullLocal("l")), action);
            if (item.remote.equals(root)) {
                assertFalse(this.getCache().isCached(new TransferItem(root, local)));
            }
            return null;
        }
    };
    worker.run(session);
    assertFalse(worker.getCache().isCached(new TransferItem(child, local)));
    assertTrue(worker.getCache().isEmpty());
}
Also used : TestProtocol(ch.cyberduck.core.TestProtocol) TransferAction(ch.cyberduck.core.transfer.TransferAction) AttributesFinder(ch.cyberduck.core.features.AttributesFinder) NullSession(ch.cyberduck.core.NullSession) TransferOptions(ch.cyberduck.core.transfer.TransferOptions) NullLocal(ch.cyberduck.core.NullLocal) DownloadTransfer(ch.cyberduck.core.transfer.DownloadTransfer) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) ListProgressListener(ch.cyberduck.core.ListProgressListener) StreamListener(ch.cyberduck.core.io.StreamListener) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) DisabledTransferErrorCallback(ch.cyberduck.core.transfer.DisabledTransferErrorCallback) Path(ch.cyberduck.core.Path) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) DisabledNotificationService(ch.cyberduck.core.notification.DisabledNotificationService) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) PathAttributes(ch.cyberduck.core.PathAttributes) NullLocal(ch.cyberduck.core.NullLocal) Local(ch.cyberduck.core.Local) Host(ch.cyberduck.core.Host) DisabledTransferPrompt(ch.cyberduck.core.transfer.DisabledTransferPrompt) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) ListProgressListener(ch.cyberduck.core.ListProgressListener) ProgressListener(ch.cyberduck.core.ProgressListener) AttributedList(ch.cyberduck.core.AttributedList) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) UploadTransfer(ch.cyberduck.core.transfer.UploadTransfer) Transfer(ch.cyberduck.core.transfer.Transfer) DownloadTransfer(ch.cyberduck.core.transfer.DownloadTransfer) ConnectionCallback(ch.cyberduck.core.ConnectionCallback) TransferSpeedometer(ch.cyberduck.core.transfer.TransferSpeedometer) TransferItem(ch.cyberduck.core.transfer.TransferItem) NullSession(ch.cyberduck.core.NullSession) Session(ch.cyberduck.core.Session) Test(org.junit.Test)

Aggregations

Session (ch.cyberduck.core.Session)39 Test (org.junit.Test)33 Host (ch.cyberduck.core.Host)32 NullSession (ch.cyberduck.core.NullSession)20 TestProtocol (ch.cyberduck.core.TestProtocol)20 DisabledProgressListener (ch.cyberduck.core.DisabledProgressListener)18 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)16 Path (ch.cyberduck.core.Path)16 DefaultX509KeyManager (ch.cyberduck.core.ssl.DefaultX509KeyManager)15 DisabledX509TrustManager (ch.cyberduck.core.ssl.DisabledX509TrustManager)14 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)13 IntegrationTest (ch.cyberduck.test.IntegrationTest)13 ListProgressListener (ch.cyberduck.core.ListProgressListener)10 DisabledCancelCallback (ch.cyberduck.core.DisabledCancelCallback)9 DisabledPasswordCallback (ch.cyberduck.core.DisabledPasswordCallback)9 DisabledTranscriptListener (ch.cyberduck.core.DisabledTranscriptListener)9 Local (ch.cyberduck.core.Local)9 TestLoginConnectionService (ch.cyberduck.core.TestLoginConnectionService)9 BackgroundException (ch.cyberduck.core.exception.BackgroundException)9 Delete (ch.cyberduck.core.features.Delete)9