From 606ee52ad25672fce4ad8d510901f2a2bd20b13b Mon Sep 17 00:00:00 2001 From: abraunegg Date: Thu, 22 Jul 2021 08:17:02 +1000 Subject: [PATCH] Fix edge case with OneDrive Personal Shared Folders (#1586) * In a `--resync --upload-only --single-directory 'dir'` scenario, and where the root 'dir' for --single-directory is a 'shared folder' we will not have the 'tie' DB entry created because of using --upload-only because we do not download the folder structure from OneDrive. As a result, query of the folder will fail and file uploads will fail. Simulate the 'tie' DB record only when --resync --upload-only --single-directory 'dir' is being used, and if that folder is 'remote' and if we are using a 'personal' account. The 'impact' of this however is, because of `--resync --upload-only` being used, local files are not in the local DB cache anymore, thus are treated as *new* files, thus, will be attempted to be re-uploaded. --- src/sync.d | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/sync.d b/src/sync.d index 7683c56d..d90eaa28 100644 --- a/src/sync.d +++ b/src/sync.d @@ -4409,6 +4409,35 @@ final class SyncEngine // Is the response a valid JSON object - validation checking done in saveItem saveItem(pathDetails); + + // OneDrive Personal Shared Folder edgecase handling + // In a --resync --upload-only --single-directory 'dir' scenario, and where the root 'dir' for --single-directory is a 'shared folder' + // we will not have the 'tie' DB entry created because of --upload-only because we do not download the folder structure from OneDrive + if (accountType == "personal"){ + // are we in a --resync --upload-only --single-directory scenario ? + if ((cfg.getValueBool("resync")) && (cfg.getValueBool("upload_only")) && (singleDirectoryScope)) { + // Create a temp item + // Takes a JSON input and formats to an item which can be used by the database + Item tempItem = makeItem(pathDetails); + // New DB Tie item due to edge case + Item tieDBItem; + // Set the name + tieDBItem.name = tempItem.name; + // Set the correct item type + tieDBItem.type = ItemType.dir; + //parent.type = ItemType.remote; + if ((tempItem.type == ItemType.remote) && (!tempItem.remoteDriveId.empty)) { + // set the right elements + tieDBItem.driveId = tempItem.remoteDriveId; + tieDBItem.id = tempItem.remoteId; + } + // Set the correct mtime + tieDBItem.mtime = tempItem.mtime; + // Add tie DB record to the local database + log.vdebug("Adding tie DB record to database: ", tieDBItem); + itemdb.upsert(tieDBItem); + } + } } else { // need to fake this data auto fakeResponse = createFakeResponse(path); @@ -5500,6 +5529,15 @@ final class SyncEngine // Add to the local database log.vdebug("Adding to database: ", item); itemdb.upsert(item); + + // If we have a remote drive ID, add this to our list of known drive id's + if (!item.remoteDriveId.empty) { + // Keep the driveIDsArray with unique entries only + if (!canFind(driveIDsArray, item.remoteDriveId)) { + // Add this drive id to the array to search with + driveIDsArray ~= item.remoteDriveId; + } + } } } else { // log error