From eb2cbfd0a815e09c7200aee9af192468dcc39d7d Mon Sep 17 00:00:00 2001 From: abraunegg Date: Tue, 30 Oct 2018 06:20:52 +1100 Subject: [PATCH] Resolve 'Key not found: path' when syncing from some shared folders (#211) * Add a check to validate if the parentReference object has a path object * Fix spelling error - trough -> through * Only upload changes on remote folder if the item is in the database - dont assert if false --- src/sync.d | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/sync.d b/src/sync.d index 4a3a7fd1..3aff8940 100644 --- a/src/sync.d +++ b/src/sync.d @@ -45,6 +45,11 @@ private bool hasParentReferenceId(const ref JSONValue item) return ("id" in item["parentReference"]) != null; } +private bool hasParentReferencePath(const ref JSONValue item) +{ + return ("path" in item["parentReference"]) != null; +} + private bool isMalware(const ref JSONValue item) { return ("malware" in item) != null; @@ -459,9 +464,11 @@ final class SyncEngine if (item["parentReference"]["driveId"].str != defaultDriveId) { // The change parentReference driveId does not match the defaultDriveId - this could be a Shared Folder root item string sharedDriveRootPath = "/drives/" ~ item["parentReference"]["driveId"].str ~ "/root:"; - if (item["parentReference"]["path"].str == sharedDriveRootPath) { - // The drive path matches what a shared folder root item would equal - isRoot = true; + if (hasParentReferencePath(item)) { + if (item["parentReference"]["path"].str == sharedDriveRootPath) { + // The drive path matches what a shared folder root item would equal + isRoot = true; + } } } } @@ -473,7 +480,11 @@ final class SyncEngine applyDifference(item, driveId, isRoot); } else { // What is this item's path? - thisItemPath = item["parentReference"]["path"].str; + if (hasParentReferencePath(item)) { + thisItemPath = item["parentReference"]["path"].str; + } else { + thisItemPath = ""; + } // Check this item's path to see if this is a change on the path we want: // 1. 'item id' matches 'id' // 2. 'parentReference id' matches 'id' @@ -898,7 +909,7 @@ final class SyncEngine uploadNewFile(path); } else { log.vlog("The directory has not changed"); - // loop trough the children + // loop through the children foreach (Item child; itemdb.selectChildren(item.driveId, item.id)) { uploadDifferences(child); } @@ -924,12 +935,14 @@ final class SyncEngine uploadNewFile(path); } else { log.vlog("The directory has not changed"); - // continue trough the linked folder + // continue through the linked folder assert(item.remoteDriveId && item.remoteId); Item remoteItem; bool found = itemdb.selectById(item.remoteDriveId, item.remoteId, remoteItem); - assert(found); - uploadDifferences(remoteItem); + if(found){ + // item was found in the database + uploadDifferences(remoteItem); + } } } else { log.vlog("The directory has been deleted");