Skip to content

Commit 0051e1d

Browse files
handle 416
1 parent a71d518 commit 0051e1d

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

DriveBackup/src/main/java/ratismal/drivebackup/uploaders/onedrive/OneDriveUploader.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ private FQID getFolder(@NotNull FQID root, @NotNull String folder) throws IOExce
368368
@NotNull
369369
private List<JSONObject> getChildren(@NotNull FQID folder, @NotNull String queryParams) throws IOException, GraphApiErrorException {
370370
ArrayList<JSONObject> allChildren = new ArrayList<>();
371-
String targetUrl = "https://graph.microsoft.com/v1.0/me/drives/" + folder.driveId
371+
String targetUrl = "https://graph.microsoft.com/v1.0/drives/" + folder.driveId
372372
+ "/items/" + folder.itemId + "/children" + queryParams;
373373
while (true) {
374374
Request request = new Request.Builder()
@@ -499,16 +499,21 @@ private void uploadToSession(@NotNull String uploadURL, @NotNull RandomAccessFil
499499
retryCount = 0;
500500
} else if (uploadResponse.code() == 201 || uploadResponse.code() == 200) {
501501
break;
502-
} else { // TODO 416
502+
} else {
503503
if (retryCount > MAX_RETRY_ATTEMPTS || uploadResponse.code() == 409) {
504504
Request cancelRequest = new Request.Builder().url(uploadURL).delete().build();
505505
DriveBackup.httpClient.newCall(cancelRequest).execute().close();
506506
throw new GraphApiErrorException(uploadResponse);
507-
}
508-
if (uploadResponse.code() == 404) {
507+
} else if (uploadResponse.code() == 404) {
509508
throw new GraphApiErrorException(uploadResponse);
510-
}
511-
if (uploadResponse.code() >= 500 && uploadResponse.code() < 600) {
509+
} else if (uploadResponse.code() == 416) {
510+
Request statusRequest = new Request.Builder().url(uploadURL).build();
511+
try (Response statusResponse = DriveBackup.httpClient.newCall(statusRequest).execute()) {
512+
JSONObject responseObject = new JSONObject(statusResponse.body().string());
513+
JSONArray expectedRanges = responseObject.getJSONArray("nextExpectedRanges");
514+
range = new Range(expectedRanges.getString(0), UPLOAD_CHUNK_SIZE);
515+
}
516+
} else if (uploadResponse.code() >= 500 && uploadResponse.code() < 600) {
512517
TimeUnit.MILLISECONDS.sleep(exponentialBackoffMillis);
513518
exponentialBackoffMillis *= EXPONENTIAL_BACKOFF_FACTOR;
514519
}

0 commit comments

Comments
 (0)