Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

drive: when initialized with a filepath, optional features used incorrect root path – see #2182

Stefan Breunig4d553ef701a1
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