1
mirror of https://github.com/rclone/rclone synced 2024-10-20 06:58:02 +02:00

fs: Document that Purger returns error on empty directory, test and fix

This commit is contained in:
Nick Craig-Wood 2014-07-28 21:02:00 +01:00
parent 9711a5d647
commit 2f9f9afac2
4 changed files with 19 additions and 4 deletions

View File

@ -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
}

View File

@ -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 != "" {

View File

@ -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) {

View File

@ -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)
}