From de98fe849259c4b80562f0731cfb492117120ec2 Mon Sep 17 00:00:00 2001 From: abraunegg Date: Fri, 22 Mar 2019 10:23:21 +1100 Subject: [PATCH] Fix JSONValue is not an object crash when a 5xx error is returned when uploading files (#426) * Fix JSONValue is not an object crash when a 5xx error is returned when uploading files --- src/sync.d | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/sync.d b/src/sync.d index 8514097a..4ebbb041 100644 --- a/src/sync.d +++ b/src/sync.d @@ -1684,6 +1684,8 @@ final class SyncEngine auto maxUploadFileSize = 16106127360; // 15GB //auto maxUploadFileSize = 21474836480; // 20GB auto thisFileSize = getSize(path); + // To avoid a 409 Conflict error - does the file actually exist on OneDrive already? + JSONValue fileDetailsFromOneDrive; // Can we read the file - as a permissions issue or file corruption will cause a failure // https://github.com/abraunegg/onedrive/issues/113 @@ -1691,10 +1693,6 @@ final class SyncEngine // able to read the file if (thisFileSize <= maxUploadFileSize){ // Resolves: https://github.com/skilion/onedrive/issues/121, https://github.com/skilion/onedrive/issues/294, https://github.com/skilion/onedrive/issues/329 - - // To avoid a 409 Conflict error - does the file actually exist on OneDrive already? - JSONValue fileDetailsFromOneDrive; - // Does this 'file' already exist on OneDrive? try { // test if the local path exists on OneDrive @@ -1841,7 +1839,8 @@ final class SyncEngine // even though some file systems (such as a POSIX-compliant file system) may consider them as different. // Note that NTFS supports POSIX semantics for case sensitivity but this is not the default behavior. - if (fileDetailsFromOneDrive["name"].str == baseName(path)){ + // Check that 'name' is in the JSON response (validates data) and that 'name' == the path we are looking for + if (("name" in fileDetailsFromOneDrive) && (fileDetailsFromOneDrive["name"].str == baseName(path))) { // OneDrive 'name' matches local path name log.vlog("Requested file to upload exists on OneDrive - local database is out of sync for this file: ", path);