mirror of
https://github.com/rclone/rclone.git
synced 2024-11-26 02:14:42 +01:00
fs: Add dir option to fs.Purge #1891
Purge optional interface needs fixing too.
This commit is contained in:
parent
a375992186
commit
5ad226ab54
@ -22,7 +22,7 @@ you want to selectively delete files.
|
|||||||
cmd.CheckArgs(1, 1, command, args)
|
cmd.CheckArgs(1, 1, command, args)
|
||||||
fdst := cmd.NewFsDst(args)
|
fdst := cmd.NewFsDst(args)
|
||||||
cmd.Run(true, false, command, func() error {
|
cmd.Run(true, false, command, func() error {
|
||||||
return operations.Purge(fdst)
|
return operations.Purge(fdst, "")
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -932,10 +932,12 @@ func Rmdir(f fs.Fs, dir string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Purge removes a container and all of its contents
|
// Purge removes a directory and all of its contents
|
||||||
func Purge(f fs.Fs) error {
|
func Purge(f fs.Fs, dir string) error {
|
||||||
doFallbackPurge := true
|
doFallbackPurge := true
|
||||||
var err error
|
var err error
|
||||||
|
if dir == "" {
|
||||||
|
// FIXME change the Purge interface so it takes a dir - see #1891
|
||||||
if doPurge := f.Features().Purge; doPurge != nil {
|
if doPurge := f.Features().Purge; doPurge != nil {
|
||||||
doFallbackPurge = false
|
doFallbackPurge = false
|
||||||
if fs.Config.DryRun {
|
if fs.Config.DryRun {
|
||||||
@ -947,9 +949,10 @@ func Purge(f fs.Fs) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if doFallbackPurge {
|
if doFallbackPurge {
|
||||||
// DeleteFiles and Rmdir observe --dry-run
|
// DeleteFiles and Rmdir observe --dry-run
|
||||||
err = DeleteFiles(listToChan(f))
|
err = DeleteFiles(listToChan(f, dir))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -1257,11 +1260,11 @@ func Deduplicate(f fs.Fs, mode DeduplicateMode) error {
|
|||||||
// channel.
|
// channel.
|
||||||
//
|
//
|
||||||
// If the error was ErrorDirNotFound then it will be ignored
|
// If the error was ErrorDirNotFound then it will be ignored
|
||||||
func listToChan(f fs.Fs) fs.ObjectsChan {
|
func listToChan(f fs.Fs, dir string) fs.ObjectsChan {
|
||||||
o := make(fs.ObjectsChan, fs.Config.Checkers)
|
o := make(fs.ObjectsChan, fs.Config.Checkers)
|
||||||
go func() {
|
go func() {
|
||||||
defer close(o)
|
defer close(o)
|
||||||
_ = walk.Walk(f, "", true, fs.Config.MaxDepth, func(dirPath string, entries fs.DirEntries, err error) error {
|
_ = walk.Walk(f, dir, true, fs.Config.MaxDepth, func(dirPath string, entries fs.DirEntries, err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == fs.ErrorDirNotFound {
|
if err == fs.ErrorDirNotFound {
|
||||||
return nil
|
return nil
|
||||||
@ -1411,7 +1414,7 @@ func Rcat(fdst fs.Fs, dstFileName string, in io.ReadCloser, modTime time.Time) (
|
|||||||
return nil, errors.Wrap(err, "Failed to create temporary local FS to spool file")
|
return nil, errors.Wrap(err, "Failed to create temporary local FS to spool file")
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
err := Purge(tmpLocalFs)
|
err := Purge(tmpLocalFs, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fs.Infof(tmpLocalFs, "Failed to cleanup temporary FS: %v", err)
|
fs.Infof(tmpLocalFs, "Failed to cleanup temporary FS: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -939,11 +939,11 @@ again:
|
|||||||
func TestObjectPurge(t *testing.T) {
|
func TestObjectPurge(t *testing.T) {
|
||||||
skipIfNotOk(t)
|
skipIfNotOk(t)
|
||||||
|
|
||||||
err := operations.Purge(remote)
|
err := operations.Purge(remote, "")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
fstest.CheckListing(t, remote, []fstest.Item{})
|
fstest.CheckListing(t, remote, []fstest.Item{})
|
||||||
|
|
||||||
err = operations.Purge(remote)
|
err = operations.Purge(remote, "")
|
||||||
assert.Error(t, err, "Expecting error after on second purge")
|
assert.Error(t, err, "Expecting error after on second purge")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,7 +276,7 @@ func (t *test) cleanFs() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return operations.Purge(dir)
|
return operations.Purge(dir, "")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user