From 6b20478635cdbfe3bb24b79c35ce52325c77e837 Mon Sep 17 00:00:00 2001 From: abraunegg Date: Fri, 19 Mar 2021 17:29:55 +1100 Subject: [PATCH] Fix 'Item cannot be deleted from OneDrive because it was not found in the local database' (#1354) * When in --monitor mode, and there are multiple driveId being used (shared folders), when a deletion event occurs, search the DB using all the known driveids rather than just the default one. When using just the default driveid, if the file to be deleted resides on another drive, the following error message is printed: 'Item cannot be deleted from OneDrive because it was not found in the local database' - which is not entirely accurate as the item is in the database, it is just not being searched for correctly. --- src/main.d | 2 +- src/sync.d | 24 ++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/main.d b/src/main.d index 02f72313..3584a022 100644 --- a/src/main.d +++ b/src/main.d @@ -1043,7 +1043,7 @@ int main(string[] args) log.vlog("Offline, cannot delete item!"); } catch(SyncException e) { if (e.msg == "The item to delete is not in the local database") { - log.vlog("Item cannot be deleted from OneDrive because not found in the local database"); + log.vlog("Item cannot be deleted from OneDrive because it was not found in the local database"); } else { log.logAndNotify("Cannot delete remote item: ", e.msg); } diff --git a/src/sync.d b/src/sync.d index c8d781cb..0569edf7 100644 --- a/src/sync.d +++ b/src/sync.d @@ -933,7 +933,17 @@ final class SyncEngine } Item item; - if (!itemdb.selectByPath(path, defaultDriveId, item)) { + // Need to check all driveid's we know about, not just the defaultDriveId + bool itemInDB = false; + foreach (searchDriveId; driveIDsArray) { + if (itemdb.selectByPath(path, searchDriveId, item)) { + // item was found in the DB + itemInDB = true; + break; + } + } + // Was the item found in the DB + if (!itemInDB) { // this is odd .. this directory is not in the local database - just go delete it log.vlog("The requested directory to delete was not found in the local database - pushing delete request direct to OneDrive"); uploadDeleteItem(item, path); @@ -5331,9 +5341,19 @@ final class SyncEngine void deleteByPath(const(string) path) { Item item; - if (!itemdb.selectByPath(path, defaultDriveId, item)) { + // Need to check all driveid's we know about, not just the defaultDriveId + bool itemInDB = false; + foreach (searchDriveId; driveIDsArray) { + if (itemdb.selectByPath(path, searchDriveId, item)) { + // item was found in the DB + itemInDB = true; + break; + } + } + if (!itemInDB) { throw new SyncException("The item to delete is not in the local database"); } + if (item.parentId == null) { // the item is a remote folder, need to do the operation on the parent enforce(itemdb.selectByPathWithoutRemote(path, defaultDriveId, item));