fs: Add directory to optional Purge interface - fixes #1891

- add a directory to the optional Purge interface
- fix up all the backends
- add an additional integration test to test for the feature
- use the new feature in operations.Purge

Many of the backends had been prepared in advance for this so the
change was trivial for them.
This commit is contained in:
Nick Craig-Wood
2020-06-04 22:25:14 +01:00
parent c2f3949ded
commit a2afa9aadd
31 changed files with 244 additions and 222 deletions

View File

@@ -921,20 +921,16 @@ func Rmdir(ctx context.Context, f fs.Fs, dir string) error {
}
// Purge removes a directory and all of its contents
func Purge(ctx context.Context, f fs.Fs, dir string) error {
func Purge(ctx context.Context, f fs.Fs, dir string) (err error) {
doFallbackPurge := true
var err error
if dir == "" {
// FIXME change the Purge interface so it takes a dir - see #1891
if doPurge := f.Features().Purge; doPurge != nil {
doFallbackPurge = false
if SkipDestructive(ctx, fs.LogDirName(f, dir), "purge directory") {
return nil
}
err = doPurge(ctx)
if err == fs.ErrorCantPurge {
doFallbackPurge = true
}
if doPurge := f.Features().Purge; doPurge != nil {
doFallbackPurge = false
if SkipDestructive(ctx, fs.LogDirName(f, dir), "purge directory") {
return nil
}
err = doPurge(ctx, dir)
if err == fs.ErrorCantPurge {
doFallbackPurge = true
}
}
if doFallbackPurge {