From d0ff07bdb0c899e8b1cf1f40e89f79cbaf1a19b2 Mon Sep 17 00:00:00 2001 From: Gary Kim Date: Fri, 26 Apr 2019 21:45:50 +0800 Subject: [PATCH] mega: add cleanup support Fixes #3138 --- backend/mega/mega.go | 21 +++++++++++++++++++++ docs/content/overview.md | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/backend/mega/mega.go b/backend/mega/mega.go index be3d7f8f1..28d6be1aa 100644 --- a/backend/mega/mega.go +++ b/backend/mega/mega.go @@ -402,6 +402,27 @@ func (f *Fs) clearRoot() { //log.Printf("cleared root directory") } +// CleanUp deletes all files currently in trash +func (f *Fs) CleanUp() (err error) { + trash := f.srv.FS.GetTrash() + items := []*mega.Node{} + _, err = f.list(trash, func(item *mega.Node) bool { + items = append(items, item) + return false + }) + if err != nil { + return errors.Wrap(err, "CleanUp failed to list items in trash") + } + // similar to f.deleteNode(trash) but with HardDelete as true + for _, item := range items { + err = f.pacer.Call(func() (bool, error) { + err = f.srv.Delete(item, true) + return shouldRetry(err) + }) + } + return err +} + // Return an Object from a path // // If it can't be found it returns the error fs.ErrorObjectNotFound. diff --git a/docs/content/overview.md b/docs/content/overview.md index d79fa6b23..b65bf4f45 100644 --- a/docs/content/overview.md +++ b/docs/content/overview.md @@ -142,7 +142,7 @@ operations more efficient. | HTTP | No | No | No | No | No | No | No | No [#2178](https://github.com/ncw/rclone/issues/2178) | No | | Hubic | Yes † | Yes | No | No | No | Yes | Yes | No [#2178](https://github.com/ncw/rclone/issues/2178) | Yes | | Jottacloud | Yes | Yes | Yes | Yes | No | Yes | No | Yes | Yes | -| Mega | Yes | No | Yes | Yes | No | No | No | No [#2178](https://github.com/ncw/rclone/issues/2178) | Yes | +| Mega | Yes | No | Yes | Yes | Yes | No | No | No [#2178](https://github.com/ncw/rclone/issues/2178) | Yes | | Microsoft Azure Blob Storage | Yes | Yes | No | No | No | Yes | No | No [#2178](https://github.com/ncw/rclone/issues/2178) | No | | Microsoft OneDrive | Yes | Yes | Yes | Yes | No [#575](https://github.com/ncw/rclone/issues/575) | No | No | Yes | Yes | | OpenDrive | Yes | Yes | Yes | Yes | No | No | No | No | No |