Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

drive: don't overwrite the description on sever side copy

Nick Craig-Wood6fdd7149c1b6
diff --git a/backend/drive/drive.go b/backend/drive/drive.go
index feee84a69..928e089aa 100644
--- a/backend/drive/drive.go
+++ b/backend/drive/drive.go
@@ -642,17 +642,21 @@ func containsString(slice []string, s string) bool {
return false
}
-// getRootID returns the canonical ID for the "root" ID
-func (f *Fs) getRootID() (string, error) {
- var info *drive.File
- var err error
+// getFile returns drive.File for the ID passed and fields passed in
+func (f *Fs) getFile(ID string, fields googleapi.Field) (info *drive.File, err error) {
err = f.pacer.CallNoRetry(func() (bool, error) {
- info, err = f.svc.Files.Get("root").
- Fields("id").
+ info, err = f.svc.Files.Get(ID).
+ Fields(fields).
SupportsAllDrives(true).
Do()
return f.shouldRetry(err)
})
+ return info, err
+}
+
+// getRootID returns the canonical ID for the "root" ID
+func (f *Fs) getRootID() (string, error) {
+ info, err := f.getFile("root", "id")
if err != nil {
return "", errors.Wrap(err, "couldn't find root directory ID")
}
@@ -2042,11 +2046,13 @@ func (f *Fs) Precision() time.Duration {
func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object, error) {
var srcObj *baseObject
ext := ""
+ readDescription := false
switch src := src.(type) {
case *Object:
srcObj = &src.baseObject
case *documentObject:
srcObj, ext = &src.baseObject, src.ext()
+ readDescription = true
case *linkObject:
srcObj, ext = &src.baseObject, src.ext()
default:
@@ -2070,6 +2076,19 @@ func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object,
return nil, err
}
+ if readDescription {
+ // preserve the description on copy for docs
+ info, err := f.getFile(srcObj.id, "description")
+ if err != nil {
+ return nil, errors.Wrap(err, "failed to read description for Google Doc")
+ }
+ createInfo.Description = info.Description
+ } else {
+ // don't overwrite the description on copy for files
+ // this should work for docs but it doesn't - it is probably a bug in Google Drive
+ createInfo.Description = ""
+ }
+
var info *drive.File
err = f.pacer.Call(func() (bool, error) {
info, err = f.svc.Files.Copy(srcObj.id, createInfo).