From 4d553ef701a13946031e52415e8738f838301fed Mon Sep 17 00:00:00 2001 From: Stefan Breunig Date: Wed, 28 Mar 2018 20:33:39 +0200 Subject: [PATCH] =?UTF-8?q?drive:=20when=20initialized=20with=20a=20filepa?= =?UTF-8?q?th,=20optional=20features=20used=20incorrect=20root=20path=20?= =?UTF-8?q?=E2=80=93=20see=20#2182?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/drive/drive.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/backend/drive/drive.go b/backend/drive/drive.go index 1e33eb3b3..abcdb46c3 100644 --- a/backend/drive/drive.go +++ b/backend/drive/drive.go @@ -34,7 +34,7 @@ import ( "github.com/pkg/errors" "golang.org/x/oauth2" "golang.org/x/oauth2/google" - "google.golang.org/api/drive/v3" + drive "google.golang.org/api/drive/v3" "google.golang.org/api/googleapi" ) @@ -551,24 +551,28 @@ func NewFs(name, path string) (fs.Fs, error) { if err != nil { // Assume it is a file newRoot, remote := dircache.SplitPath(root) - newF := *f - newF.dirCache = dircache.New(newRoot, f.rootFolderID, &newF) - newF.root = newRoot + tempF := *f + tempF.dirCache = dircache.New(newRoot, f.rootFolderID, &tempF) + tempF.root = newRoot // Make new Fs which is the parent - err = newF.dirCache.FindRoot(false) + err = tempF.dirCache.FindRoot(false) if err != nil { // No root so return old f return f, nil } - entries, err := newF.List("") + entries, err := tempF.List("") if err != nil { // unable to list folder so return old f return f, nil } for _, e := range entries { if _, isObject := e.(fs.Object); isObject && e.Remote() == remote { - // return an error with an fs which points to the parent - return &newF, fs.ErrorIsFile + // XXX: update the old f here instead of returning tempF, since + // `features` were already filled with functions having *f as a receiver. + // See https://github.com/ncw/rclone/issues/2182 + f.dirCache = tempF.dirCache + f.root = tempF.root + return f, fs.ErrorIsFile } } // File doesn't exist so return old f