From df3fba1be032441f9b6f09f3b8c0cb5768de14da Mon Sep 17 00:00:00 2001 From: abraunegg Date: Thu, 31 Oct 2019 12:58:09 +1100 Subject: [PATCH] Catch a 412 response when moving files (Issue #706) (#707) * Catch a 412 response when moving files right after upload. --- src/sync.d | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/sync.d b/src/sync.d index 44f018f2..e9b904a0 100644 --- a/src/sync.d +++ b/src/sync.d @@ -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); } }