diff --git a/docs/content/drive.md b/docs/content/drive.md index 61a64c8c9..7e16414d2 100644 --- a/docs/content/drive.md +++ b/docs/content/drive.md @@ -85,6 +85,12 @@ was * They are deleted after 30 days or 100 revisions (whatever comes first). * They do not count towards a user storage quota. +### Deleting files ### + +By default rclone will delete files permanently when requested. If +sending them to the trash is required instead then use the +`--drive-use-trash` flag. + ### Limitations ### Drive has quite a lot of rate limiting. This causes rclone to be diff --git a/drive/drive.go b/drive/drive.go index 7420fca37..ebce8fbc6 100644 --- a/drive/drive.go +++ b/drive/drive.go @@ -39,6 +39,7 @@ const ( var ( // Flags driveFullList = pflag.BoolP("drive-full-list", "", true, "Use a full listing for directory list. More data but usually quicker.") + driveUseTrash = pflag.BoolP("drive-use-trash", "", false, "Send files to the trash instead of deleting permanently.") // chunkSize is the size of the chunks created during a resumable upload and should be a power of two. // 1<<18 is the minimum size supported by the Google uploader, and there is no maximum. chunkSize = fs.SizeSuffix(256 * 1024) @@ -803,7 +804,11 @@ func (f *FsDrive) Rmdir() error { // Delete the directory if it isn't the root if f.root != "" { f.call(&err, func() { - err = f.svc.Files.Delete(f.rootId).Do() + if *driveUseTrash { + _, err = f.svc.Files.Trash(f.rootId).Do() + } else { + err = f.svc.Files.Delete(f.rootId).Do() + } }) if err != nil { return err @@ -832,7 +837,11 @@ func (f *FsDrive) Purge() error { return err } f.call(&err, func() { - err = f.svc.Files.Delete(f.rootId).Do() + if *driveUseTrash { + _, err = f.svc.Files.Trash(f.rootId).Do() + } else { + err = f.svc.Files.Delete(f.rootId).Do() + } }) f.resetRoot() if err != nil { @@ -1023,7 +1032,11 @@ func (o *FsObjectDrive) Update(in io.Reader, modTime time.Time, size int64) erro func (o *FsObjectDrive) Remove() error { var err error o.drive.call(&err, func() { - err = o.drive.svc.Files.Delete(o.id).Do() + if *driveUseTrash { + _, err = o.drive.svc.Files.Trash(o.id).Do() + } else { + err = o.drive.svc.Files.Delete(o.id).Do() + } }) return err }