use of ch.cyberduck.core.exception.ConnectionCanceledException in project cyberduck by iterate-ch.
the class WritePermissionWorker method run.
@Override
public Boolean run(final Session<?> session) throws BackgroundException {
final UnixPermission feature = session.getFeature(UnixPermission.class);
if (log.isDebugEnabled()) {
log.debug(String.format("Run with feature %s", feature));
}
for (Path file : files) {
if (this.isCanceled()) {
throw new ConnectionCanceledException();
}
final Permission merged = permissions.get(file);
this.write(session, feature, file, merged);
}
return true;
}
use of ch.cyberduck.core.exception.ConnectionCanceledException in project cyberduck by iterate-ch.
the class WriteRedundancyWorker method write.
protected void write(final Session<?> session, final Redundancy feature, final Path file) throws BackgroundException {
if (this.isCanceled()) {
throw new ConnectionCanceledException();
}
if (!level.equals(file.attributes().getStorageClass())) {
listener.message(MessageFormat.format(LocaleFactory.localizedString("Writing metadata of {0}", "Status"), file.getName()));
feature.setClass(file, level);
file.attributes().setStorageClass(level);
}
if (file.isDirectory()) {
if (callback.recurse(file, level)) {
for (Path child : session.getFeature(ListService.class).list(file, new WorkerListProgressListener(this, listener))) {
this.write(session, feature, child);
}
}
}
}
use of ch.cyberduck.core.exception.ConnectionCanceledException in project cyberduck by iterate-ch.
the class WriteTransferAccelerationWorker method run.
@Override
public Boolean run(final Session<?> session) throws BackgroundException {
final TransferAcceleration feature = session.getFeature(TransferAcceleration.class);
if (log.isDebugEnabled()) {
log.debug(String.format("Run with feature %s", feature));
}
final PathContainerService container = session.getFeature(PathContainerService.class);
for (Path file : this.getContainers(container, files)) {
if (this.isCanceled()) {
throw new ConnectionCanceledException();
}
this.write(feature, file);
}
return true;
}
use of ch.cyberduck.core.exception.ConnectionCanceledException in project cyberduck by iterate-ch.
the class StreamCopierTest method testTransferInterrupt.
@Test
public void testTransferInterrupt() throws Exception {
final TransferStatus status = new TransferStatus();
final CyclicBarrier lock = new CyclicBarrier(2);
final CyclicBarrier exit = new CyclicBarrier(2);
status.setLength(432768L);
final BytecountStreamListener count = new BytecountStreamListener() {
@Override
public void sent(final long bytes) {
super.sent(bytes);
try {
lock.await();
exit.await();
} catch (InterruptedException | BrokenBarrierException e) {
fail(e.getMessage());
}
}
};
new Thread(new Runnable() {
@Override
public void run() {
try {
new StreamCopier(status, status).withListener(count).transfer(new NullInputStream(status.getLength()), NullOutputStream.NULL_OUTPUT_STREAM);
} catch (BackgroundException e) {
assertTrue(e instanceof ConnectionCanceledException);
}
}
}).start();
lock.await();
status.setCanceled();
exit.await();
assertFalse(status.isComplete());
try {
status.validate();
fail();
} catch (ConnectionCanceledException e) {
}
assertEquals(32768L, count.getRecv());
assertEquals(32768L, count.getSent());
assertEquals(0L, status.getOffset());
}
use of ch.cyberduck.core.exception.ConnectionCanceledException in project cyberduck by iterate-ch.
the class EueLargeUploadService method upload.
@Override
public EueWriteFeature.Chunk upload(final Path file, final Local local, final BandwidthThrottle throttle, final StreamListener listener, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException {
final ThreadPool pool = ThreadPoolFactory.get("multipart", concurrency);
try {
final List<Future<EueWriteFeature.Chunk>> parts = new ArrayList<>();
long offset = 0;
long remaining = status.getLength();
final String resourceId;
final String uploadUri;
if (status.isExists()) {
resourceId = fileid.getFileId(file, new DisabledListProgressListener());
uploadUri = EueUploadHelper.updateResource(session, resourceId, UploadType.CHUNKED).getUploadURI();
} else {
final ResourceCreationResponseEntry uploadResourceCreationResponseEntry = EueUploadHelper.createResource(session, fileid.getFileId(file.getParent(), new DisabledListProgressListener()), file.getName(), status, UploadType.CHUNKED);
resourceId = EueResourceIdProvider.getResourceIdFromResourceUri(uploadResourceCreationResponseEntry.getHeaders().getLocation());
uploadUri = uploadResourceCreationResponseEntry.getEntity().getUploadURI();
}
for (int partNumber = 1; remaining > 0; partNumber++) {
final long length = Math.min(chunksize, remaining);
parts.add(this.submit(pool, file, local, throttle, listener, status, uploadUri, resourceId, partNumber, offset, length, callback));
remaining -= length;
offset += length;
}
// Checksums for uploaded segments
final List<EueWriteFeature.Chunk> chunks = new ArrayList<>();
for (Future<EueWriteFeature.Chunk> uploadResponseFuture : parts) {
try {
chunks.add(uploadResponseFuture.get());
} catch (InterruptedException e) {
log.error("Part upload failed with interrupt failure");
status.setCanceled();
throw new ConnectionCanceledException(e);
} catch (ExecutionException e) {
log.warn(String.format("Part upload failed with execution failure %s", e.getMessage()));
if (e.getCause() instanceof BackgroundException) {
throw (BackgroundException) e.getCause();
}
throw new BackgroundException(e.getCause());
}
}
final MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
final AtomicLong totalSize = new AtomicLong();
chunks.stream().sorted(Comparator.comparing(EueWriteFeature.Chunk::getPartnumber)).forEach(chunk -> {
try {
messageDigest.update(Hex.decodeHex(chunk.getChecksum().hash));
} catch (DecoderException e) {
log.error(String.format("Failure %s decoding hash %s", e, chunk.getChecksum()));
}
messageDigest.update(ChunkListSHA256ChecksumCompute.intToBytes(chunk.getLength().intValue()));
totalSize.set(totalSize.get() + chunk.getLength());
});
final String cdash64 = Base64.encodeBase64URLSafeString(messageDigest.digest());
final EueUploadHelper.UploadResponse completedUploadResponse = new EueMultipartUploadCompleter(session).getCompletedUploadResponse(uploadUri, totalSize.get(), cdash64);
final EueWriteFeature.Chunk object = new EueWriteFeature.Chunk(totalSize.get(), cdash64);
// Mark parent status as complete
status.withResponse(new EueAttributesAdapter().toAttributes(object)).setComplete();
return object;
} catch (NoSuchAlgorithmException e) {
throw new ChecksumException(LocaleFactory.localizedString("Checksum failure", "Error"), e);
} finally {
// Cancel future tasks
pool.shutdown(false);
}
}
Aggregations