drive: Add --drive-use-trash flag so rclone trashes instead of deletes - fixes #82

This commit is contained in:
Nick Craig-Wood 2015-08-16 14:49:58 +01:00
parent 88ea8b305d
commit d8306938a1
2 changed files with 22 additions and 3 deletions

View File

@ -85,6 +85,12 @@ was
* They are deleted after 30 days or 100 revisions (whatever comes first). * They are deleted after 30 days or 100 revisions (whatever comes first).
* They do not count towards a user storage quota. * 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 ### ### Limitations ###
Drive has quite a lot of rate limiting. This causes rclone to be Drive has quite a lot of rate limiting. This causes rclone to be

View File

@ -39,6 +39,7 @@ const (
var ( var (
// Flags // Flags
driveFullList = pflag.BoolP("drive-full-list", "", true, "Use a full listing for directory list. More data but usually quicker.") 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. // 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. // 1<<18 is the minimum size supported by the Google uploader, and there is no maximum.
chunkSize = fs.SizeSuffix(256 * 1024) chunkSize = fs.SizeSuffix(256 * 1024)
@ -803,7 +804,11 @@ func (f *FsDrive) Rmdir() error {
// Delete the directory if it isn't the root // Delete the directory if it isn't the root
if f.root != "" { if f.root != "" {
f.call(&err, func() { 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 { if err != nil {
return err return err
@ -832,7 +837,11 @@ func (f *FsDrive) Purge() error {
return err return err
} }
f.call(&err, func() { 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() f.resetRoot()
if err != nil { 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 { func (o *FsObjectDrive) Remove() error {
var err error var err error
o.drive.call(&err, func() { 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 return err
} }