From 6e005b025a0fdcf7823ea0d4eb6a5c8cb585d4e9 Mon Sep 17 00:00:00 2001 From: Cnly Date: Tue, 21 May 2019 15:45:03 +0800 Subject: [PATCH] onedrive: More accurately check if root is found - fixes #3164 --- backend/onedrive/onedrive.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/backend/onedrive/onedrive.go b/backend/onedrive/onedrive.go index 48786794d..6b8c9e053 100644 --- a/backend/onedrive/onedrive.go +++ b/backend/onedrive/onedrive.go @@ -385,9 +385,19 @@ func (f *Fs) readMetaDataForPath(path string) (info *api.Item, resp *http.Respon var dirCacheFoundRoot bool var rootNormalizedID string if f.dirCache != nil { - var ok bool - if rootNormalizedID, ok = f.dirCache.Get(""); ok { - dirCacheFoundRoot = true + var dirCacheRootIDExists bool + rootNormalizedID, dirCacheRootIDExists = f.dirCache.Get("") + if f.root == "" { + // if f.root == "", it means f.root is the absolute root of the drive + // and its ID should have been found in NewFs + dirCacheFoundRoot = dirCacheRootIDExists + } else if _, err := f.dirCache.RootParentID(); err == nil { + // if root is in a folder, it must have a parent folder, and + // if dirCache has found root in NewFs, the parent folder's ID + // should be present. + // This RootParentID() check is a fix for #3164 which describes + // a possible case where the root is not found. + dirCacheFoundRoot = dirCacheRootIDExists } }