forked from TrueCloudLab/rclone
fs: Document that Purger returns error on empty directory, test and fix
This commit is contained in:
parent
9711a5d647
commit
2f9f9afac2
4 changed files with 19 additions and 4 deletions
4
fs/fs.go
4
fs/fs.go
|
@ -85,7 +85,7 @@ type Fs interface {
|
||||||
|
|
||||||
// Remove the directory (container, bucket) if empty
|
// 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
|
Rmdir() error
|
||||||
|
|
||||||
// Precision of the ModTimes in this Fs
|
// 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
|
// Implement this if you have a way of deleting all the files
|
||||||
// quicker than just running Remove() on the result of List()
|
// quicker than just running Remove() on the result of List()
|
||||||
|
//
|
||||||
|
// Return an error if it doesn't exist
|
||||||
Purge() error
|
Purge() error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -161,9 +161,12 @@ func RandomRemote(remoteName string, subdir bool) (fs.Fs, func()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
finalise := func() {
|
finalise := func() {
|
||||||
TestPurge(remote)
|
_ = fs.Purge(remote) // ignore error
|
||||||
if parentRemote != nil {
|
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
|
// Delete directory if we made one above
|
||||||
if rmdir != "" {
|
if rmdir != "" {
|
||||||
|
|
|
@ -322,7 +322,10 @@ func TestObjectRemove(t *testing.T) {
|
||||||
func TestObjectPurge(t *testing.T) {
|
func TestObjectPurge(t *testing.T) {
|
||||||
skipIfNotOk(t)
|
skipIfNotOk(t)
|
||||||
fstest.TestPurge(remote)
|
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) {
|
func TestFinalise(t *testing.T) {
|
||||||
|
|
|
@ -261,6 +261,13 @@ func (f *FsLocal) readPrecision() (precision time.Duration) {
|
||||||
// deleting all the files quicker than just running Remove() on the
|
// deleting all the files quicker than just running Remove() on the
|
||||||
// result of List()
|
// result of List()
|
||||||
func (f *FsLocal) Purge() error {
|
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)
|
return os.RemoveAll(f.root)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue