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);
}
}
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);
}
}
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);
}
}
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();
}
}
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();
}
Aggregations