"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
b2: add --b2-hard-delete to permanently delete instead of hide files - Fixes #1547
John Papandriopoulosd134d78979e6
diff --git a/b2/b2.go b/b2/b2.goindex 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 IDfunc (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- }- opts := rest.Opts{- Method: "POST",- Path: "/b2_hide_file",- }- var request = api.HideFileRequest{- BucketID: bucketID,- Name: o.fs.root + o.remote,+ if *b2HardDelete {+ return o.fs.deleteByID(o.id, 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, "" otherwisediff --git a/docs/content/b2.md b/docs/content/b2.mdindex 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 versionof 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