From d134d78979e6d57c2d84a0ff93edca97f786d2a2 Mon Sep 17 00:00:00 2001 From: John Papandriopoulos Date: Sun, 23 Jul 2017 05:02:42 -0700 Subject: [PATCH] b2: add --b2-hard-delete to permanently delete instead of hide files - Fixes #1547 --- b2/b2.go | 49 +++++++++++++++++++++++++++------------------- docs/content/b2.md | 9 ++++++--- 2 files changed, 35 insertions(+), 23 deletions(-) diff --git a/b2/b2.go b/b2/b2.go index 6a37712ee..f0ef9a414 100644 --- a/b2/b2.go +++ b/b2/b2.go @@ -51,6 +51,7 @@ var ( uploadCutoff = fs.SizeSuffix(200E6) b2TestMode = fs.StringP("b2-test-mode", "", "", "A flag string for X-Bz-Test-Mode header.") b2Versions = fs.BoolP("b2-versions", "", false, "Include old versions in directory listings.") + b2HardDelete = fs.BoolP("b2-hard-delete", "", false, "Permanently delete files on remote removal, otherwise hide files.") errNotWithVersions = errors.New("can't modify or delete files in --b2-versions mode") ) @@ -786,6 +787,31 @@ func (f *Fs) Precision() time.Duration { return time.Millisecond } +// hide hides a file on the remote +func (f *Fs) hide(Name string) error { + bucketID, err := f.getBucketID() + if err != nil { + return err + } + opts := rest.Opts{ + Method: "POST", + Path: "/b2_hide_file", + } + var request = api.HideFileRequest{ + BucketID: bucketID, + Name: Name, + } + var response api.File + err = f.pacer.Call(func() (bool, error) { + resp, err := f.srv.CallJSON(&opts, &request, &response) + return f.shouldRetry(resp, err) + }) + if err != nil { + return errors.Wrapf(err, "failed to hide %q", Name) + } + return nil +} + // deleteByID deletes a file version given Name and ID func (f *Fs) deleteByID(ID, Name string) error { opts := rest.Opts{ @@ -1361,27 +1387,10 @@ func (o *Object) Remove() error { if *b2Versions { return errNotWithVersions } - bucketID, err := o.fs.getBucketID() - if err != nil { - return err + if *b2HardDelete { + return o.fs.deleteByID(o.id, o.remote) } - opts := rest.Opts{ - Method: "POST", - Path: "/b2_hide_file", - } - var request = api.HideFileRequest{ - BucketID: bucketID, - Name: o.fs.root + o.remote, - } - var response api.File - err = o.fs.pacer.Call(func() (bool, error) { - resp, err := o.fs.srv.CallJSON(&opts, &request, &response) - return o.fs.shouldRetry(resp, err) - }) - if err != nil { - return errors.Wrap(err, "failed to delete file") - } - return nil + return o.fs.hide(o.fs.root + o.remote) } // MimeType of an Object if known, "" otherwise diff --git a/docs/content/b2.md b/docs/content/b2.md index ea1383b29..d7437f484 100644 --- a/docs/content/b2.md +++ b/docs/content/b2.md @@ -138,10 +138,13 @@ used. When rclone uploads a new version of a file it creates a [new version of it](https://www.backblaze.com/b2/docs/file_versions.html). -Likewise when you delete a file, the old version will still be -available. +Likewise when you delete a file, the old version will be marked hidden +and still be available. Conversely, you may opt in to a "hard delete" +of files with the `--b2-hard-delete` flag which would permanently remove +the file instead of hiding it. -Old versions of files are visible using the `--b2-versions` flag. +Old versions of files, where available, are visible using the +`--b2-versions` flag. If you wish to remove all the old versions then you can use the `rclone cleanup remote:bucket` command which will delete all the old