Search in sources :

Example 21 with HostPreferences

use of ch.cyberduck.core.preferences.HostPreferences in project cyberduck by iterate-ch.

the class AzureContainerListService method list.

@Override
public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException {
    ResultSegment<CloudBlobContainer> result;
    ResultContinuation token = null;
    try {
        final AttributedList<Path> containers = new AttributedList<>();
        do {
            final BlobRequestOptions options = new BlobRequestOptions();
            result = session.getClient().listContainersSegmented(null, ContainerListingDetails.NONE, new HostPreferences(session.getHost()).getInteger("azure.listing.chunksize"), token, options, context);
            for (CloudBlobContainer container : result.getResults()) {
                final PathAttributes attributes = new PathAttributes();
                attributes.setETag(container.getProperties().getEtag());
                attributes.setModificationDate(container.getProperties().getLastModified().getTime());
                containers.add(new Path(PathNormalizer.normalize(container.getName()), EnumSet.of(Path.Type.volume, Path.Type.directory), attributes));
            }
            listener.chunk(directory, containers);
            token = result.getContinuationToken();
        } while (result.getHasMoreResults());
        return containers;
    } catch (StorageException e) {
        throw new AzureExceptionMappingService().map("Listing directory {0} failed", e, directory);
    }
}
Also used : Path(ch.cyberduck.core.Path) BlobRequestOptions(com.microsoft.azure.storage.blob.BlobRequestOptions) AttributedList(ch.cyberduck.core.AttributedList) ResultContinuation(com.microsoft.azure.storage.ResultContinuation) PathAttributes(ch.cyberduck.core.PathAttributes) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) StorageException(com.microsoft.azure.storage.StorageException) HostPreferences(ch.cyberduck.core.preferences.HostPreferences)

Example 22 with HostPreferences

use of ch.cyberduck.core.preferences.HostPreferences in project cyberduck by iterate-ch.

the class AzureCopyFeature method copy.

@Override
public Path copy(final Path source, final Path copy, final TransferStatus status, final ConnectionCallback callback, final StreamListener listener) throws BackgroundException {
    try {
        final CloudBlob target = session.getClient().getContainerReference(containerService.getContainer(copy).getName()).getAppendBlobReference(containerService.getKey(copy));
        final CloudBlob blob = session.getClient().getContainerReference(containerService.getContainer(source).getName()).getBlobReferenceFromServer(containerService.getKey(source));
        final BlobRequestOptions options = new BlobRequestOptions();
        options.setStoreBlobContentMD5(new HostPreferences(session.getHost()).getBoolean("azure.upload.md5"));
        final URI s = session.getHost().getCredentials().isTokenAuthentication() ? URI.create(blob.getUri().toString() + session.getHost().getCredentials().getToken()) : blob.getUri();
        final String id = target.startCopy(s, AccessCondition.generateEmptyCondition(), AccessCondition.generateEmptyCondition(), options, context);
        if (log.isDebugEnabled()) {
            log.debug(String.format("Started copy for %s with copy operation ID %s", copy, id));
        }
        listener.sent(status.getLength());
        // Copy original file attributes
        return copy.withAttributes(source.attributes());
    } catch (StorageException e) {
        throw new AzureExceptionMappingService().map("Cannot copy {0}", e, source);
    } catch (URISyntaxException e) {
        throw new NotfoundException(e.getMessage(), e);
    }
}
Also used : CloudBlob(com.microsoft.azure.storage.blob.CloudBlob) BlobRequestOptions(com.microsoft.azure.storage.blob.BlobRequestOptions) NotfoundException(ch.cyberduck.core.exception.NotfoundException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) StorageException(com.microsoft.azure.storage.StorageException) HostPreferences(ch.cyberduck.core.preferences.HostPreferences)

Example 23 with HostPreferences

use of ch.cyberduck.core.preferences.HostPreferences in project cyberduck by iterate-ch.

the class SDSCopyFeature method copy.

@Override
public Path copy(final Path source, final Path target, final TransferStatus status, final ConnectionCallback callback, final StreamListener listener) throws BackgroundException {
    try {
        new NodesApi(session.getClient()).copyNodes(new CopyNodesRequest().resolutionStrategy(CopyNodesRequest.ResolutionStrategyEnum.OVERWRITE).addItemsItem(new CopyNode().id(Long.parseLong(nodeid.getVersionId(source, new DisabledListProgressListener())))).keepShareLinks(new HostPreferences(session.getHost()).getBoolean("sds.upload.sharelinks.keep")), // Target Parent Node ID
        Long.parseLong(nodeid.getVersionId(target.getParent(), new DisabledListProgressListener())), StringUtils.EMPTY, null);
        listener.sent(status.getLength());
        nodeid.cache(target, null);
        final PathAttributes attributes = new SDSAttributesFinderFeature(session, nodeid).find(target);
        nodeid.cache(target, attributes.getVersionId());
        return target.withAttributes(attributes);
    } catch (ApiException e) {
        throw new SDSExceptionMappingService(nodeid).map("Cannot copy {0}", e, source);
    }
}
Also used : NodesApi(ch.cyberduck.core.sds.io.swagger.client.api.NodesApi) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) PathAttributes(ch.cyberduck.core.PathAttributes) CopyNode(ch.cyberduck.core.sds.io.swagger.client.model.CopyNode) CopyNodesRequest(ch.cyberduck.core.sds.io.swagger.client.model.CopyNodesRequest) HostPreferences(ch.cyberduck.core.preferences.HostPreferences) ApiException(ch.cyberduck.core.sds.io.swagger.client.ApiException)

Example 24 with HostPreferences

use of ch.cyberduck.core.preferences.HostPreferences in project cyberduck by iterate-ch.

the class DropboxBatchDeleteFeature method delete.

@Override
public void delete(final Map<Path, TransferStatus> files, final PasswordCallback prompt, final Callback callback) throws BackgroundException {
    final ScheduledThreadPool scheduler = new ScheduledThreadPool();
    try {
        for (Path f : files.keySet()) {
            callback.delete(f);
        }
        final DbxUserFilesRequests requests = new DbxUserFilesRequests(session.getClient());
        final DeleteBatchLaunch job = requests.deleteBatch(files.keySet().stream().map(f -> new DeleteArg(f.getAbsolute())).collect(Collectors.toList()));
        final CountDownLatch signal = new CountDownLatch(1);
        final AtomicReference<BackgroundException> failure = new AtomicReference<>();
        scheduler.repeat(() -> {
            try {
                // Poll status
                final DeleteBatchJobStatus status = requests.deleteBatchCheck(job.getAsyncJobIdValue());
                if (status.isComplete()) {
                    final List<DeleteBatchResultEntry> entries = status.getCompleteValue().getEntries();
                    for (DeleteBatchResultEntry entry : entries) {
                        if (entry.isFailure()) {
                            switch(entry.getFailureValue().tag()) {
                                case PATH_LOOKUP:
                                    failure.set(new NotfoundException(entry.getFailureValue().toString()));
                                    break;
                                default:
                                    failure.set(new InteroperabilityException());
                            }
                        }
                    }
                    signal.countDown();
                }
                if (status.isFailed()) {
                    signal.countDown();
                }
            } catch (DbxException e) {
                failure.set(new DropboxExceptionMappingService().map(e));
                signal.countDown();
            }
        }, new HostPreferences(session.getHost()).getLong("dropbox.delete.poll.interval.ms"), TimeUnit.MILLISECONDS);
        Uninterruptibles.awaitUninterruptibly(signal);
        if (null != failure.get()) {
            throw failure.get();
        }
    } catch (DbxException e) {
        throw new DropboxExceptionMappingService().map(e);
    } finally {
        scheduler.shutdown();
    }
}
Also used : Path(ch.cyberduck.core.Path) DeleteBatchResultEntry(com.dropbox.core.v2.files.DeleteBatchResultEntry) NotfoundException(ch.cyberduck.core.exception.NotfoundException) InteroperabilityException(ch.cyberduck.core.exception.InteroperabilityException) DeleteBatchJobStatus(com.dropbox.core.v2.files.DeleteBatchJobStatus) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) HostPreferences(ch.cyberduck.core.preferences.HostPreferences) DbxUserFilesRequests(com.dropbox.core.v2.files.DbxUserFilesRequests) ScheduledThreadPool(ch.cyberduck.core.threading.ScheduledThreadPool) DeleteBatchLaunch(com.dropbox.core.v2.files.DeleteBatchLaunch) DeleteArg(com.dropbox.core.v2.files.DeleteArg) BackgroundException(ch.cyberduck.core.exception.BackgroundException) DbxException(com.dropbox.core.DbxException)

Example 25 with HostPreferences

use of ch.cyberduck.core.preferences.HostPreferences in project cyberduck by iterate-ch.

the class DropboxPathContainerService method getKey.

@Override
public String getKey(final Path file) {
    if (new HostPreferences(session.getHost()).getBoolean("dropbox.business.enable")) {
        final Path container = this.getContainer(file);
        final String namespace = container.attributes().getFileId();
        if (StringUtils.isNotBlank(namespace)) {
            if (file.isRoot()) {
                // Root
                if (useNamespace) {
                    return String.format("ns:%s", namespace);
                }
                return StringUtils.EMPTY;
            }
            // Return path relative to the namespace root
            final String key = this.isContainer(file) ? StringUtils.EMPTY : Path.DELIMITER + super.getKey(file);
            if (useNamespace) {
                return String.format("ns:%s%s", namespace, key);
            }
            return key;
        }
    }
    return file.isRoot() ? StringUtils.EMPTY : file.getAbsolute();
}
Also used : Path(ch.cyberduck.core.Path) HostPreferences(ch.cyberduck.core.preferences.HostPreferences)

Aggregations

HostPreferences (ch.cyberduck.core.preferences.HostPreferences)81 IOException (java.io.IOException)33 Path (ch.cyberduck.core.Path)29 DisabledListProgressListener (ch.cyberduck.core.DisabledListProgressListener)18 BackgroundException (ch.cyberduck.core.exception.BackgroundException)12 DefaultIOExceptionMappingService (ch.cyberduck.core.DefaultIOExceptionMappingService)11 PathAttributes (ch.cyberduck.core.PathAttributes)11 NotfoundException (ch.cyberduck.core.exception.NotfoundException)11 File (com.google.api.services.drive.model.File)10 AttributedList (ch.cyberduck.core.AttributedList)8 URI (java.net.URI)8 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)7 AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)6 SimplePathPredicate (ch.cyberduck.core.SimplePathPredicate)6 InteroperabilityException (ch.cyberduck.core.exception.InteroperabilityException)6 MemorySegementingOutputStream (ch.cyberduck.core.io.MemorySegementingOutputStream)6 NodesApi (ch.cyberduck.core.sds.io.swagger.client.api.NodesApi)5 Credentials (ch.cyberduck.core.Credentials)4 Partition (ch.cyberduck.core.collections.Partition)4 S3Protocol (ch.cyberduck.core.s3.S3Protocol)4