From aa2d7f00c2376f2dc44f50afb3276402ddfdb44d Mon Sep 17 00:00:00 2001 From: Abhiraj Date: Fri, 4 Feb 2022 17:07:58 +0530 Subject: [PATCH] drive: added --drive-copy-shortcut-content - fixes #4604 --- backend/drive/drive.go | 21 ++++++++++++++++++++- docs/content/drive.md | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/backend/drive/drive.go b/backend/drive/drive.go index 01e3fd6a4..798db047f 100644 --- a/backend/drive/drive.go +++ b/backend/drive/drive.go @@ -299,6 +299,17 @@ a non root folder as its starting point. Default: true, Help: "Send files to the trash instead of deleting permanently.\n\nDefaults to true, namely sending files to the trash.\nUse `--drive-use-trash=false` to delete files permanently instead.", Advanced: true, + }, { + Name: "copy_shortcut_content", + Default: false, + Help: `Server side copy contents of shortcuts instead of the shortcut. + +When doing server side copies, normally rclone will copy shortcuts as +shortcuts. + +If this flag is used then rclone will copy the contents of shortcuts +rather than shortcuts themselves when doing server side copies.`, + Advanced: true, }, { Name: "skip_gdocs", Default: false, @@ -578,6 +589,7 @@ type Options struct { TeamDriveID string `config:"team_drive"` AuthOwnerOnly bool `config:"auth_owner_only"` UseTrash bool `config:"use_trash"` + CopyShortcutContent bool `config:"copy_shortcut_content"` SkipGdocs bool `config:"skip_gdocs"` SkipChecksumGphotos bool `config:"skip_checksum_gphotos"` SharedWithMe bool `config:"shared_with_me"` @@ -2374,9 +2386,16 @@ func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object, createInfo.Description = "" } - // get the ID of the thing to copy - this is the shortcut if available + // get the ID of the thing to copy + // copy the contents if CopyShortcutContent + // else copy the shortcut only + id := shortcutID(srcObj.id) + if f.opt.CopyShortcutContent { + id = actualID(srcObj.id) + } + var info *drive.File err = f.pacer.Call(func() (bool, error) { info, err = f.svc.Files.Copy(id, createInfo). diff --git a/docs/content/drive.md b/docs/content/drive.md index 23b062dc5..beb17bf9d 100644 --- a/docs/content/drive.md +++ b/docs/content/drive.md @@ -410,7 +410,7 @@ For shortcuts pointing to files: - When downloading the contents of the destination file is downloaded. - When updating shortcut file with a non shortcut file, the shortcut is removed then a new file is uploaded in place of the shortcut. - When server-side moving (renaming) the shortcut is renamed, not the destination file. -- When server-side copying the shortcut is copied, not the contents of the shortcut. +- When server-side copying the shortcut is copied, not the contents of the shortcut. (unless `--drive-copy-shortcut-content` is in use in which case the contents of the shortcut gets copied). - When deleting the shortcut is deleted not the linked file. - When setting the modification time, the modification time of the linked file will be set.