From ccd4dfbaf722d732ef273c5e39cd4aed90ea2dae Mon Sep 17 00:00:00 2001 From: abraunegg Date: Sun, 29 Apr 2018 12:39:27 +1000 Subject: [PATCH] Resolve #341 '--single-directory' edge case * Resolve where '--single-directory' is used to sync a single directory, but a file / folder is 'moved' on OneDrive to outside the scope of the focus of the '--single-directory' path. Before this change, the file would remain in the local path (original location) whilst it would reside in the new OneDrive path. This patch looks for this mis match and deletes the local file / folder to reflect it is no longer in the same OneDrive path. --- src/sync.d | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/sync.d b/src/sync.d index fd4069aa..2b44e0a8 100644 --- a/src/sync.d +++ b/src/sync.d @@ -358,6 +358,30 @@ final class SyncEngine if ( (item["id"].str == id) || (item["parentReference"]["id"].str == id) || (canFind(thisItemPath, syncFolderName)) ){ // This is a change we want to apply applyDifference(item, driveId, isRoot); + } else { + // No item ID match or folder sync match + // Before discarding change - does this ID still exist on OneDrive - as in IS this + // potentially a --single-directory sync and the user 'moved' the file out of the 'sync-dir' to another OneDrive folder + // This is a corner edge case - https://github.com/skilion/onedrive/issues/341 + JSONValue oneDriveMovedNotDeleted; + try { + oneDriveMovedNotDeleted = onedrive.getPathDetailsById(item["id"].str); + } catch (OneDriveException e) { + if (e.httpStatusCode == 404) { + // No .. that ID is GONE + return; + } + } + // Yes .. ID is still on OneDrive but elsewhere .... #341 edge case handling + // What is the original local path for this ID in the database? Does it match 'syncFolderName' + string originalLocalPath = itemdb.computePath(driveId, item["id"].str); + + if (canFind(originalLocalPath, syncFolderName)){ + // This 'change' relates to an item that WAS in 'syncFolderName' but is now + // stored elsewhere on OneDrive - outside the path we are syncing from + // Remove this item locally as it's local path is now obsolete + idsToDelete ~= [driveId, item["id"].str]; + } } } }