Skip to content

Commit

Permalink
Extract failure to interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
dkocher committed Jun 7, 2023
1 parent 59a11aa commit b6a2021
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
9 changes: 9 additions & 0 deletions core/src/main/java/ch/cyberduck/core/io/StreamProgress.java
Expand Up @@ -17,13 +17,22 @@
* Bug fixes, suggestions and comments should be sent to feedback@cyberduck.ch
*/

import ch.cyberduck.core.exception.BackgroundException;

public interface StreamProgress {
void setComplete();

void setFailure(final BackgroundException failure);

StreamProgress noop = new StreamProgress() {
@Override
public void setComplete() {
//
}

@Override
public void setFailure(final BackgroundException failure) {
//
}
};
}
Expand Up @@ -16,6 +16,7 @@
*/

import ch.cyberduck.core.PathAttributes;
import ch.cyberduck.core.exception.BackgroundException;
import ch.cyberduck.core.exception.ConnectionCanceledException;
import ch.cyberduck.core.io.StreamCancelation;
import ch.cyberduck.core.io.StreamProgress;
Expand Down Expand Up @@ -43,6 +44,11 @@ public void setComplete() {
progress.setComplete();
}

@Override
public void setFailure(final BackgroundException failure) {
progress.setFailure(failure);
}

@Override
public PathAttributes getResponse() {
return response.getResponse();
Expand Down
Expand Up @@ -24,6 +24,7 @@
import ch.cyberduck.core.PathAttributes;
import ch.cyberduck.core.Permission;
import ch.cyberduck.core.concurrency.Interruptibles;
import ch.cyberduck.core.exception.BackgroundException;
import ch.cyberduck.core.exception.ConnectionCanceledException;
import ch.cyberduck.core.exception.TransferStatusCanceledException;
import ch.cyberduck.core.features.Encryption;
Expand Down Expand Up @@ -260,7 +261,8 @@ public TransferStatus complete() {
return this;
}

public void setFailure() {
@Override
public void setFailure(final BackgroundException failure) {
complete.set(false);
done.countDown();
}
Expand Down
Expand Up @@ -33,6 +33,7 @@
import ch.cyberduck.core.SleepPreventerFactory;
import ch.cyberduck.core.TransferItemCache;
import ch.cyberduck.core.exception.BackgroundException;
import ch.cyberduck.core.exception.ConnectionCanceledException;
import ch.cyberduck.core.exception.TransferCanceledException;
import ch.cyberduck.core.io.StreamListener;
import ch.cyberduck.core.notification.NotificationService;
Expand Down Expand Up @@ -451,7 +452,7 @@ private void transferSegment(final TransferStatus segment) throws BackgroundExce
if(log.isDebugEnabled()) {
log.debug(String.format("Cancel retry for %s", item));
}
segment.setFailure();
segment.setFailure(e);
// Prompt to continue or abort for application errors
if(error.prompt(item, segment, e, table.size())) {
// Continue
Expand Down Expand Up @@ -509,7 +510,7 @@ public TransferStatus call() throws BackgroundException {
}
else {
log.warn(String.format("Skip concatenating segments for failed transfer %s", status));
status.setFailure();
status.setFailure(new ConnectionCanceledException());
}
}
return status;
Expand Down

0 comments on commit b6a2021

Please sign in to comment.