Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 14 additions & 19 deletions library/src/main/java/com/qiniu/android/storage/ResumeUploader.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ private boolean isCancelled() {
}

private void nextTask(final int offset, final int retried, final URI address) {
if (isCancelled()) {
ResponseInfo i = ResponseInfo.cancelled();
completionHandler.complete(key, i, null);
return;
}

if (offset == size) {
CompletionHandler complete = new CompletionHandler() {
@Override
Expand All @@ -203,13 +209,7 @@ public void complete(ResponseInfo info, JSONObject response) {
return;
}

if (isCancelled()) {
ResponseInfo i = ResponseInfo.cancelled();
completionHandler.complete(key, i, null);
return;
}

if (isNotQiniu(info) || (info.needRetry() && retried < config.retryMax)) {
if ((isNotQiniu(info) || info.needRetry()) && retried < config.retryMax) {
nextTask(offset, retried + 1, config.upBackup.address);
return;
}
Expand All @@ -236,27 +236,22 @@ public void onProgress(int bytesWritten, int totalSize) {
@Override
public void complete(ResponseInfo info, JSONObject response) {
if (!info.isOK()) {
if (isCancelled()) {
ResponseInfo i = ResponseInfo.cancelled();
completionHandler.complete(key, i, null);
return;
}
if (info.statusCode == 701) {
nextTask((offset / Configuration.BLOCK_SIZE) * Configuration.BLOCK_SIZE, retried, address);
if (info.statusCode == 701 && retried < config.retryMax) {
nextTask((offset / Configuration.BLOCK_SIZE) * Configuration.BLOCK_SIZE, retried + 1, address);
return;
}

if (!isNotQiniu(info) && (retried >= config.retryMax || !info.needRetry())) {
completionHandler.complete(key, info, null);
if ((isNotQiniu(info) || info.needRetry()) && retried < config.retryMax) {
nextTask(offset, retried + 1, config.upBackup.address);
return;
}

nextTask(offset, retried + 1, config.upBackup.address);
completionHandler.complete(key, info, response);
return;
}
String context = null;

if (response == null) {
if (response == null && retried < config.retryMax) {
nextTask(offset, retried + 1, config.upBackup.address);
return;
}
Expand All @@ -267,7 +262,7 @@ public void complete(ResponseInfo info, JSONObject response) {
} catch (JSONException e) {
e.printStackTrace();
}
if (context == null || crc != ResumeUploader.this.crc32) {
if ((context == null || crc != ResumeUploader.this.crc32) && retried < config.retryMax) {
nextTask(offset, retried + 1, config.upBackup.address);
return;
}
Expand Down