mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 12:05:05 +08:00
fs: Document that Purger returns error on empty directory, test and fix
This commit is contained in:
parent
9711a5d647
commit
2f9f9afac2
4
fs/fs.go
4
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
|
||||
}
|
||||
|
||||
|
|
|
@ -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 != "" {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user