From 942613498f04941aabbf750e271eff8ac6e6146b Mon Sep 17 00:00:00 2001 From: Jcomp Date: Mon, 23 Oct 2023 14:30:25 +0000 Subject: [PATCH 1/2] Fix ignored file upload --- src/sync.d | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/sync.d b/src/sync.d index d52a18ca0..77de291db 100644 --- a/src/sync.d +++ b/src/sync.d @@ -4591,10 +4591,17 @@ class SyncEngine { // No 404 or otherwise was triggered, meaning that the file already exists online and passes the POSIX test ... log.vdebug("fileDetailsFromOneDrive after exist online check: ", fileDetailsFromOneDrive); + + // Save item to the database + saveItem(fileDetailsFromOneDrive); + // Does the data from online match our local file? - if (performUploadIntegrityValidationChecks(fileDetailsFromOneDrive, fileToUpload, thisFileSize)) { - // Save item to the database - saveItem(fileDetailsFromOneDrive); + if (disableUploadValidation || !performUploadIntegrityValidationChecks(fileDetailsFromOneDrive, fileToUpload, thisFileSize)) { + // The item already exists online, replace it instead + string changedItemParentId = fileDetailsFromOneDrive["parentReference"]["driveId"].str; + string changedItemId = fileDetailsFromOneDrive["id"].str; + databaseItemsWhereContentHasChanged ~= [changedItemParentId, changedItemId, fileToUpload]; + processChangedLocalItemsToUpload(); } } catch (OneDriveException exception) { // If we get a 404 .. the file is not online .. this is what we want .. file does not exist online From 38bc4a3ce8a5bb6b718e2fcaeaed25bc9ab83a6b Mon Sep 17 00:00:00 2001 From: Jcomp Date: Mon, 23 Oct 2023 16:52:00 +0000 Subject: [PATCH 2/2] Fix moving file 409 conflict --- src/sync.d | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/src/sync.d b/src/sync.d index 77de291db..2323c1bf5 100644 --- a/src/sync.d +++ b/src/sync.d @@ -6434,6 +6434,7 @@ class SyncEngine { ]; // Perform the move operation on OneDrive + bool isMoveSuccess = false; JSONValue response; // Create a new API Instance for this thread and initialise it @@ -6441,27 +6442,41 @@ class SyncEngine { movePathOnlineApiInstance = new OneDriveApi(appConfig); movePathOnlineApiInstance.initialise(); - try { - response = movePathOnlineApiInstance.updateById(oldItem.driveId, oldItem.id, data, oldItem.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 = movePathOnlineApiInstance.updateById(oldItem.driveId, oldItem.id, data, nullTag); - } - } + const(char)[] eTag = oldItem.eTag; + for (int i = 0; i < 3; i++) { + try { + response = movePathOnlineApiInstance.updateById(oldItem.driveId, oldItem.id, data, eTag); + isMoveSuccess = true; + break; + } 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"); + // move the file but without the eTag + eTag = null; + } else if (e.httpStatusCode == 409) { + // Destination item already exists, delete it first + log.log("Moved local item overwrote an existing item - deleting old online item"); + uploadDeletedItem(newItem, newPath); + } else + break; + } + } // Shutdown API instance movePathOnlineApiInstance.shutdown(); // Free object and memory object.destroy(movePathOnlineApiInstance); - // save the move response from OneDrive in the database - // Is the response a valid JSON object - validation checking done in saveItem - saveItem(response); + if (isMoveSuccess) { + // save the move response from OneDrive in the database + // Is the response a valid JSON object - validation checking done in saveItem + saveItem(response); + log.log("Moving ", oldPath, " to ", newPath, " ... done."); + } else { + log.error("ERROR: Unable to move from ", oldPath, " to ", newPath); + } } } else { // Moved item is unwanted