Catch a 412 response when moving files (Issue #706) (#707)

* Catch a 412 response when moving files right after upload.
This commit is contained in:
abraunegg 2019-10-31 12:58:09 +11:00 committed by GitHub
parent 12947d160f
commit df3fba1be0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3200,10 +3200,25 @@ final class SyncEngine
"lastModifiedDateTime": mtime.toISOExtString()
])
];
auto res = onedrive.updateById(fromItem.driveId, fromItem.id, diff, fromItem.eTag);
// update itemdb
// Perform the move operation on OneDrive
JSONValue response;
try {
response = onedrive.updateById(fromItem.driveId, fromItem.id, diff, fromItem.eTag);
} catch (OneDriveException e) {
if (e.httpStatusCode == 412) {
// OneDrive threw a 412 error, most likely: ETag does not match current item's value
// Retry without eTag
log.vdebug("File Move Failed - OneDrive eTag / cTag match issue");
log.vlog("OneDrive returned a 'HTTP 412 - Precondition Failed' when attempting to move the file - gracefully handling error");
string nullTag = null;
// move the file but without the eTag
response = onedrive.updateById(fromItem.driveId, fromItem.id, diff, nullTag);
}
}
// save the move response from OneDrive in the database
// Is the response a valid JSON object - validation checking done in saveItem
saveItem(res);
saveItem(response);
}
}