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: reset root directory on Rmdir and Purge

Nick Craig-Wood442578ca2522
diff --git a/drive/drive.go b/drive/drive.go
index d5166f96c..c724f301f 100644
--- a/drive/drive.go
+++ b/drive/drive.go
@@ -234,10 +234,8 @@ func NewFs(name, path string) (fs.Fs, error) {
return nil, fmt.Errorf("Couldn't read info about Drive: %s", err)
}
- // Find the Id of the root directory and the Id of its parent
- f.rootId = f.about.RootFolderId
- // Put the root directory in
- f.dirCache.Put("", f.rootId)
+ // Find the Id of the true root and clear everything
+ f.resetRoot()
// Find the current root
err = f.findRoot(false)
if err != nil {
@@ -499,7 +497,7 @@ func (f *FsDrive) _findDir(path string, create bool) (pathId string, err error)
}
info, err := f.svc.Files.Insert(info).Do()
if err != nil {
- return pathId, fmt.Errorf("Failed to make directory")
+ return pathId, fmt.Errorf("Failed to make directory: %v", err)
}
pathId = info.Id
} else {
@@ -537,6 +535,20 @@ func (f *FsDrive) findRoot(create bool) error {
return nil
}
+// Resets the root directory to the absolute root and clears the dirCache
+func (f *FsDrive) resetRoot() {
+ f.findRootLock.Lock()
+ defer f.findRootLock.Unlock()
+ f.foundRoot = false
+ f.dirCache.Flush()
+
+ // Put the true root in
+ f.rootId = f.about.RootFolderId
+
+ // Put the root directory in
+ f.dirCache.Put("", f.rootId)
+}
+
// Walk the path returning a channel of FsObjects
func (f *FsDrive) List() fs.ObjectsChan {
out := make(fs.ObjectsChan, fs.Config.Checkers)
@@ -686,6 +698,7 @@ func (f *FsDrive) Rmdir() error {
return err
}
}
+ f.resetRoot()
return nil
}
@@ -708,7 +721,7 @@ func (f *FsDrive) Purge() error {
return err
}
err = f.svc.Files.Delete(f.rootId).Do()
- f.dirCache.Flush()
+ f.resetRoot()
if err != nil {
return err
}