diff --git a/fs/fs.go b/fs/fs.go index b53507f3d..6382a4b07 100644 --- a/fs/fs.go +++ b/fs/fs.go @@ -85,7 +85,7 @@ type Fs interface { // Remove the directory (container, bucket) if empty // - // Return an error if it doesn't exists or isn't empty + // Return an error if it doesn't exist or isn't empty Rmdir() error // Precision of the ModTimes in this Fs @@ -135,6 +135,8 @@ type Purger interface { // // Implement this if you have a way of deleting all the files // quicker than just running Remove() on the result of List() + // + // Return an error if it doesn't exist Purge() error } diff --git a/fstest/fstest.go b/fstest/fstest.go index e103b7648..2e35036e2 100644 --- a/fstest/fstest.go +++ b/fstest/fstest.go @@ -161,9 +161,12 @@ func RandomRemote(remoteName string, subdir bool) (fs.Fs, func()) { } finalise := func() { - TestPurge(remote) + _ = fs.Purge(remote) // ignore error if parentRemote != nil { - TestPurge(parentRemote) + err = fs.Purge(parentRemote) // ignore error + if err != nil { + log.Printf("Failed to purge %v: %v", parentRemote, err) + } } // Delete directory if we made one above if rmdir != "" { diff --git a/fstest/fstests/fstests.go b/fstest/fstests/fstests.go index 99be49c6f..b7d3ca337 100644 --- a/fstest/fstests/fstests.go +++ b/fstest/fstests/fstests.go @@ -322,7 +322,10 @@ func TestObjectRemove(t *testing.T) { func TestObjectPurge(t *testing.T) { skipIfNotOk(t) fstest.TestPurge(remote) - fstest.TestPurge(remote) + err := fs.Purge(remote) + if err == nil { + t.Fatal("Expecting error after on second purge") + } } func TestFinalise(t *testing.T) { diff --git a/local/local.go b/local/local.go index 0b48889c0..e957e332e 100644 --- a/local/local.go +++ b/local/local.go @@ -261,6 +261,13 @@ func (f *FsLocal) readPrecision() (precision time.Duration) { // deleting all the files quicker than just running Remove() on the // result of List() func (f *FsLocal) Purge() error { + fi, err := os.Lstat(f.root) + if err != nil { + return err + } + if !fi.Mode().IsDir() { + return fmt.Errorf("Can't Purge non directory: %q", f.root) + } return os.RemoveAll(f.root) }