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); } }