From 442578ca2522b2625c586d0a902cf8fc0128b086 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Mon, 28 Jul 2014 23:34:05 +0100 Subject: [PATCH] drive: reset root directory on Rmdir and Purge --- drive/drive.go | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) 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 }