Search in sources :

Example 1 with ListCanceledException

use of ch.cyberduck.core.exception.ListCanceledException in project cyberduck by iterate-ch.

the class FTPListResponseReaderTest method testLimit.

@Test(expected = ListCanceledException.class)
@Ignore
public void testLimit() throws Exception {
    final CompositeFileEntryParser parser = new FTPParserSelector().getParser("NETWARE  Type : L8");
    final AttributedList<Path> list = new FTPListResponseReader(parser).read(new Path("/", EnumSet.of(Path.Type.directory)), Collections.singletonList("lrwxrwxrwx    1 ftp      ftp            23 Feb 05 06:51 debian -> ../pool/4/mirror/debian"), new DisabledListProgressListener() {

        @Override
        public void chunk(final Path parent, AttributedList<Path> list) throws ListCanceledException {
            throw new ListCanceledException(AttributedList.<Path>emptyList());
        }
    });
}
Also used : FTPParserSelector(ch.cyberduck.core.ftp.FTPParserSelector) Path(ch.cyberduck.core.Path) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) CompositeFileEntryParser(ch.cyberduck.core.ftp.parser.CompositeFileEntryParser) ListCanceledException(ch.cyberduck.core.exception.ListCanceledException) Ignore(org.junit.Ignore) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 2 with ListCanceledException

use of ch.cyberduck.core.exception.ListCanceledException in project cyberduck by iterate-ch.

the class SessionListWorker method run.

@Override
public AttributedList<Path> run(final Session<?> session) throws BackgroundException {
    try {
        if (this.isCached()) {
            final AttributedList<Path> list = cache.get(directory);
            listener.chunk(directory, list);
            return list;
        }
        final ListService service = session.getFeature(ListService.class);
        if (log.isDebugEnabled()) {
            log.debug(String.format("Run with feature %s", service));
        }
        return service.list(directory, listener);
    } catch (ListCanceledException e) {
        return e.getChunk();
    }
}
Also used : Path(ch.cyberduck.core.Path) ListService(ch.cyberduck.core.ListService) ListCanceledException(ch.cyberduck.core.exception.ListCanceledException)

Example 3 with ListCanceledException

use of ch.cyberduck.core.exception.ListCanceledException in project cyberduck by iterate-ch.

the class S3AttributesFinderFeature method find.

@Override
public PathAttributes find(final Path file, final ListProgressListener listener) throws BackgroundException {
    if (file.isRoot()) {
        return PathAttributes.EMPTY;
    }
    if (containerService.isContainer(file)) {
        final PathAttributes attributes = new PathAttributes();
        attributes.setRegion(new S3LocationFeature(session, session.getClient().getRegionEndpointCache()).getLocation(file).getIdentifier());
        return attributes;
    }
    if (file.getType().contains(Path.Type.upload)) {
        final Write.Append append = new S3WriteFeature(session).append(file, new TransferStatus());
        if (append.append) {
            return new PathAttributes().withSize(append.size);
        }
        throw new NotfoundException(file.getAbsolute());
    }
    try {
        PathAttributes attr;
        final Path bucket = containerService.getContainer(file);
        try {
            attr = new S3AttributesAdapter().toAttributes(session.getClient().getVersionedObjectDetails(file.attributes().getVersionId(), bucket.isRoot() ? StringUtils.EMPTY : bucket.getName(), containerService.getKey(file)));
        } catch (ServiceException e) {
            switch(e.getResponseCode()) {
                case 405:
                    // Only DELETE method is allowed for delete markers
                    attr = new PathAttributes();
                    attr.setCustom(Collections.singletonMap(KEY_DELETE_MARKER, Boolean.TRUE.toString()));
                    attr.setDuplicate(true);
                    return attr;
            }
            throw new S3ExceptionMappingService().map("Failure to read attributes of {0}", e, file);
        }
        if (StringUtils.isNotBlank(attr.getVersionId())) {
            if (references) {
                try {
                    // Add references to previous versions
                    final AttributedList<Path> list = new S3VersionedObjectListService(session, true).list(file, new DisabledListProgressListener());
                    final Path versioned = list.find(new DefaultPathPredicate(new Path(file).withAttributes(attr)));
                    if (null != versioned) {
                        if (versioned.attributes().getCustom().containsKey(KEY_DELETE_MARKER)) {
                            attr.setCustom(Collections.singletonMap(KEY_DELETE_MARKER, Boolean.TRUE.toString()));
                        }
                        attr.setDuplicate(versioned.attributes().isDuplicate());
                        attr.setVersions(versioned.attributes().getVersions());
                    }
                } catch (InteroperabilityException | AccessDeniedException e) {
                    log.warn(String.format("Ignore failure %s reading object versions for %s", e, file));
                }
            } else {
                // Determine if latest version
                try {
                    // Duplicate if not latest version
                    final String latest = new S3AttributesAdapter().toAttributes(session.getClient().getObjectDetails(bucket.isRoot() ? StringUtils.EMPTY : bucket.getName(), containerService.getKey(file))).getVersionId();
                    if (null != latest) {
                        attr.setDuplicate(!latest.equals(attr.getVersionId()));
                    }
                } catch (ServiceException e) {
                    final BackgroundException failure = new S3ExceptionMappingService().map("Failure to read attributes of {0}", e, file);
                    if (failure instanceof NotfoundException) {
                        attr.setDuplicate(true);
                    } else {
                        throw failure;
                    }
                }
            }
        }
        return attr;
    } catch (NotfoundException e) {
        if (file.isDirectory()) {
            // File may be marked as placeholder but no placeholder file exists. Check for common prefix returned.
            try {
                new S3ObjectListService(session).list(file, new CancellingListProgressListener(), containerService.getKey(file), 1);
            } catch (ListCanceledException l) {
                // Found common prefix
                return PathAttributes.EMPTY;
            } catch (NotfoundException n) {
                throw e;
            }
            // Found common prefix
            return PathAttributes.EMPTY;
        }
        throw e;
    }
}
Also used : Write(ch.cyberduck.core.features.Write) Path(ch.cyberduck.core.Path) NotfoundException(ch.cyberduck.core.exception.NotfoundException) AccessDeniedException(ch.cyberduck.core.exception.AccessDeniedException) InteroperabilityException(ch.cyberduck.core.exception.InteroperabilityException) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) PathAttributes(ch.cyberduck.core.PathAttributes) CancellingListProgressListener(ch.cyberduck.core.CancellingListProgressListener) DefaultPathPredicate(ch.cyberduck.core.DefaultPathPredicate) ServiceException(org.jets3t.service.ServiceException) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) ListCanceledException(ch.cyberduck.core.exception.ListCanceledException) BackgroundException(ch.cyberduck.core.exception.BackgroundException)

Example 4 with ListCanceledException

use of ch.cyberduck.core.exception.ListCanceledException in project cyberduck by iterate-ch.

the class DAVSession method login.

@Override
public void login(final Proxy proxy, final LoginCallback prompt, final CancelCallback cancel) throws BackgroundException {
    final CredentialsProvider provider = new BasicCredentialsProvider();
    if (preferences.getBoolean("webdav.ntlm.windows.authentication.enable") && WinHttpClients.isWinAuthAvailable()) {
        provider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.NTLM), new WindowsCredentialsProvider(new BasicCredentialsProvider()).getCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.NTLM)));
        provider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.SPNEGO), new WindowsCredentialsProvider(new SystemDefaultCredentialsProvider()).getCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.SPNEGO)));
    } else {
        provider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.NTLM), new NTCredentials(host.getCredentials().getUsername(), host.getCredentials().getPassword(), preferences.getProperty("webdav.ntlm.workstation"), preferences.getProperty("webdav.ntlm.domain")));
        provider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.SPNEGO), new NTCredentials(host.getCredentials().getUsername(), host.getCredentials().getPassword(), preferences.getProperty("webdav.ntlm.workstation"), preferences.getProperty("webdav.ntlm.domain")));
    }
    provider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.BASIC), new UsernamePasswordCredentials(host.getCredentials().getUsername(), host.getCredentials().getPassword()));
    provider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.DIGEST), new UsernamePasswordCredentials(host.getCredentials().getUsername(), host.getCredentials().getPassword()));
    provider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.KERBEROS), new UsernamePasswordCredentials(host.getCredentials().getUsername(), host.getCredentials().getPassword()));
    client.setCredentials(provider);
    if (preferences.getBoolean("webdav.basic.preemptive")) {
        switch(proxy.getType()) {
            case DIRECT:
            case SOCKS:
                // Enable preemptive authentication. See HttpState#setAuthenticationPreemptive
                client.enablePreemptiveAuthentication(host.getHostname(), host.getPort(), host.getPort(), Charset.forName(preferences.getProperty("http.credentials.charset")));
                break;
            default:
                client.disablePreemptiveAuthentication();
        }
    } else {
        client.disablePreemptiveAuthentication();
    }
    if (host.getCredentials().isPassed()) {
        log.warn(String.format("Skip verifying credentials with previous successful authentication event for %s", this));
        return;
    }
    try {
        final Path home = new DelegatingHomeFeature(new WorkdirHomeFeature(host), new DefaultPathHomeFeature(host)).find();
        final HttpHead head = new HttpHead(new DAVPathEncoder().encode(home));
        try {
            client.execute(head, new MicrosoftIISFeaturesResponseHandler());
        } catch (SardineException e) {
            switch(e.getStatusCode()) {
                case HttpStatus.SC_NOT_FOUND:
                    log.warn(String.format("Ignore failure %s", e));
                    break;
                case HttpStatus.SC_NOT_IMPLEMENTED:
                case HttpStatus.SC_FORBIDDEN:
                case HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE:
                case HttpStatus.SC_METHOD_NOT_ALLOWED:
                    log.warn(String.format("Failed HEAD request to %s with %s. Retry with PROPFIND.", host, e.getResponsePhrase()));
                    cancel.verify();
                    // Possibly only HEAD requests are not allowed
                    list.list(home, new DisabledListProgressListener() {

                        @Override
                        public void chunk(final Path parent, final AttributedList<Path> list) throws ListCanceledException {
                            try {
                                cancel.verify();
                            } catch (ConnectionCanceledException e) {
                                throw new ListCanceledException(list, e);
                            }
                        }
                    });
                    break;
                case HttpStatus.SC_BAD_REQUEST:
                    if (preferences.getBoolean("webdav.basic.preemptive")) {
                        log.warn(String.format("Disable preemptive authentication for %s due to failure %s", host, e.getResponsePhrase()));
                        cancel.verify();
                        client.disablePreemptiveAuthentication();
                        client.execute(head, new MicrosoftIISFeaturesResponseHandler());
                    } else {
                        throw new DAVExceptionMappingService().map(e);
                    }
                    break;
                default:
                    throw new DAVExceptionMappingService().map(e);
            }
        }
    } catch (SardineException e) {
        throw new DAVExceptionMappingService().map(e);
    } catch (IOException e) {
        throw new HttpExceptionMappingService().map(e);
    }
}
Also used : Path(ch.cyberduck.core.Path) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) DelegatingHomeFeature(ch.cyberduck.core.shared.DelegatingHomeFeature) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) ConnectionCanceledException(ch.cyberduck.core.exception.ConnectionCanceledException) DefaultPathHomeFeature(ch.cyberduck.core.shared.DefaultPathHomeFeature) WindowsCredentialsProvider(org.apache.http.impl.auth.win.WindowsCredentialsProvider) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) SystemDefaultCredentialsProvider(org.apache.http.impl.client.SystemDefaultCredentialsProvider) IOException(java.io.IOException) WindowsCredentialsProvider(org.apache.http.impl.auth.win.WindowsCredentialsProvider) HttpHead(org.apache.http.client.methods.HttpHead) NTCredentials(org.apache.http.auth.NTCredentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) SardineException(com.github.sardine.impl.SardineException) HttpExceptionMappingService(ch.cyberduck.core.http.HttpExceptionMappingService) AttributedList(ch.cyberduck.core.AttributedList) AuthScope(org.apache.http.auth.AuthScope) SystemDefaultCredentialsProvider(org.apache.http.impl.client.SystemDefaultCredentialsProvider) WorkdirHomeFeature(ch.cyberduck.core.shared.WorkdirHomeFeature) ListCanceledException(ch.cyberduck.core.exception.ListCanceledException)

Example 5 with ListCanceledException

use of ch.cyberduck.core.exception.ListCanceledException in project cyberduck by iterate-ch.

the class SessionListWorkerTest method testCacheListCanceledWithController.

@Test
public void testCacheListCanceledWithController() throws Exception {
    final Host host = new Host(new TestProtocol(), "localhost");
    final Session<?> session = new NullSession(host) {

        @Override
        public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException {
            throw new ListCanceledException(AttributedList.<Path>emptyList());
        }
    };
    final PathCache cache = new PathCache(1);
    final Path directory = new Path("/home/notfound", EnumSet.of(Path.Type.directory));
    cache.put(directory, new AttributedList<>(Collections.singletonList(new Path(directory, "f", EnumSet.of(Path.Type.file)))));
    final SessionListWorker worker = new SessionListWorker(cache, directory, new DisabledListProgressListener());
    final Controller c = new AbstractController() {

        @Override
        public void invoke(final MainAction runnable, final boolean wait) {
            runnable.run();
        }
    };
    final Future<AttributedList<Path>> task = c.background(new WorkerBackgroundAction<AttributedList<Path>>(c, new StatelessSessionPool(new TestLoginConnectionService(), session, new DisabledTranscriptListener(), new DefaultVaultRegistry(new DisabledPasswordCallback())), worker));
    assertNotNull(task.get());
    assertTrue(cache.containsKey(directory));
    assertEquals(1, cache.get(directory).size());
}
Also used : StatelessSessionPool(ch.cyberduck.core.pool.StatelessSessionPool) MainAction(ch.cyberduck.core.threading.MainAction) DefaultVaultRegistry(ch.cyberduck.core.vault.DefaultVaultRegistry) ListCanceledException(ch.cyberduck.core.exception.ListCanceledException) Test(org.junit.Test)

Aggregations

ListCanceledException (ch.cyberduck.core.exception.ListCanceledException)5 Path (ch.cyberduck.core.Path)4 DisabledListProgressListener (ch.cyberduck.core.DisabledListProgressListener)3 Test (org.junit.Test)2 AttributedList (ch.cyberduck.core.AttributedList)1 CancellingListProgressListener (ch.cyberduck.core.CancellingListProgressListener)1 DefaultPathPredicate (ch.cyberduck.core.DefaultPathPredicate)1 ListService (ch.cyberduck.core.ListService)1 PathAttributes (ch.cyberduck.core.PathAttributes)1 AccessDeniedException (ch.cyberduck.core.exception.AccessDeniedException)1 BackgroundException (ch.cyberduck.core.exception.BackgroundException)1 ConnectionCanceledException (ch.cyberduck.core.exception.ConnectionCanceledException)1 InteroperabilityException (ch.cyberduck.core.exception.InteroperabilityException)1 NotfoundException (ch.cyberduck.core.exception.NotfoundException)1 Write (ch.cyberduck.core.features.Write)1 FTPParserSelector (ch.cyberduck.core.ftp.FTPParserSelector)1 CompositeFileEntryParser (ch.cyberduck.core.ftp.parser.CompositeFileEntryParser)1 HttpExceptionMappingService (ch.cyberduck.core.http.HttpExceptionMappingService)1 StatelessSessionPool (ch.cyberduck.core.pool.StatelessSessionPool)1 DefaultPathHomeFeature (ch.cyberduck.core.shared.DefaultPathHomeFeature)1