Implement cleanup command for emptying trash / removing old versions of files

This commit is contained in:
Nick Craig-Wood 2016-07-01 16:35:36 +01:00
parent c8e2531c8b
commit 9aae143833
4 changed files with 36 additions and 0 deletions

View File

@ -197,6 +197,11 @@ don't match. It doesn't alter the source or destination.
`--size-only` may be used to only compare the sizes, not the MD5SUMs.
### rclone cleanup remote:path ###
Clean up the remote if possible. Empty the trash or delete old file
versions. Not supported by all remotes.
### rclone dedupe remote:path ###
By default `dedup` interactively finds duplicate files and offers to

View File

@ -273,6 +273,15 @@ type PutUncheckeder interface {
PutUnchecked(in io.Reader, src ObjectInfo) (Object, error)
}
// CleanUpper is an optional interfaces for Fs
type CleanUpper interface {
// CleanUp the trash in the Fs
//
// Implement this if you have a way of emptying the trash or
// otherwise cleaning up old versions of files.
CleanUp() error
}
// ObjectsChan is a channel of Objects
type ObjectsChan chan Object

View File

@ -1379,3 +1379,12 @@ func listToChan(list *Lister) ObjectsChan {
}()
return o
}
// CleanUp removes the trash for the Fs
func CleanUp(f Fs) error {
fc, ok := f.(CleanUpper)
if !ok {
return errors.Errorf("%v doesn't support cleanup", f)
}
return fc.CleanUp()
}

View File

@ -278,6 +278,19 @@ var Commands = []Command{
MinArgs: 1,
MaxArgs: 3,
},
{
Name: "cleanup",
ArgsHelp: "remote:path",
Help: `
Clean up the remote if possible. Empty the trash or delete
old file versions. Not supported by all remotes.`,
Run: func(fdst, fsrc fs.Fs) error {
return fs.CleanUp(fdst)
},
MinArgs: 1,
MaxArgs: 1,
Retry: true,
},
{
Name: "help",
Help: `