Make it so optional interface Purge can fail so it can be wrapped

This commit is contained in:
Nick Craig-Wood 2015-11-08 14:16:00 +00:00
parent e9dda25c60
commit 2c2cb84ca7
2 changed files with 8 additions and 1 deletions

View file

@ -25,6 +25,7 @@ var (
fsRegistry []*Info fsRegistry []*Info
// ErrorNotFoundInConfigFile is returned by NewFs if not found in config file // ErrorNotFoundInConfigFile is returned by NewFs if not found in config file
ErrorNotFoundInConfigFile = fmt.Errorf("Didn't find section in config file") ErrorNotFoundInConfigFile = fmt.Errorf("Didn't find section in config file")
ErrorCantPurge = fmt.Errorf("Can't purge directory")
ErrorCantCopy = fmt.Errorf("Can't copy object - incompatible remotes") ErrorCantCopy = fmt.Errorf("Can't copy object - incompatible remotes")
ErrorCantMove = fmt.Errorf("Can't copy object - incompatible remotes") ErrorCantMove = fmt.Errorf("Can't copy object - incompatible remotes")
ErrorCantDirMove = fmt.Errorf("Can't copy directory - incompatible remotes") ErrorCantDirMove = fmt.Errorf("Can't copy directory - incompatible remotes")

View file

@ -734,14 +734,20 @@ func Rmdir(f Fs) error {
// //
// FIXME doesn't delete local directories // FIXME doesn't delete local directories
func Purge(f Fs) error { func Purge(f Fs) error {
doFallbackPurge := true
var err error var err error
if purger, ok := f.(Purger); ok { if purger, ok := f.(Purger); ok {
doFallbackPurge = false
if Config.DryRun { if Config.DryRun {
Debug(f, "Not purging as --dry-run set") Debug(f, "Not purging as --dry-run set")
} else { } else {
err = purger.Purge() err = purger.Purge()
if err == ErrorCantPurge {
doFallbackPurge = true
}
} }
} else { }
if doFallbackPurge {
// DeleteFiles and Rmdir observe --dry-run // DeleteFiles and Rmdir observe --dry-run
DeleteFiles(f.List()) DeleteFiles(f.List())
err = Rmdir(f) err = Rmdir(f)