From 9aae1438339d15a3ece2a0ce44d62d509ad99277 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 1 Jul 2016 16:35:36 +0100 Subject: [PATCH] Implement cleanup command for emptying trash / removing old versions of files --- docs/content/docs.md | 5 +++++ fs/fs.go | 9 +++++++++ fs/operations.go | 9 +++++++++ rclone.go | 13 +++++++++++++ 4 files changed, 36 insertions(+) diff --git a/docs/content/docs.md b/docs/content/docs.md index 355053470..b9e63d80b 100644 --- a/docs/content/docs.md +++ b/docs/content/docs.md @@ -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 diff --git a/fs/fs.go b/fs/fs.go index 87cbbe14d..dcbc80134 100644 --- a/fs/fs.go +++ b/fs/fs.go @@ -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 diff --git a/fs/operations.go b/fs/operations.go index c37505c30..1ef78d5f6 100644 --- a/fs/operations.go +++ b/fs/operations.go @@ -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() +} diff --git a/rclone.go b/rclone.go index bd261f48a..f976be9ce 100644 --- a/rclone.go +++ b/rclone.go @@ -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: `