mirror of
https://github.com/rclone/rclone
synced 2025-01-13 17:06:24 +01:00
drive: don't overwrite the description on sever side copy
See: https://forum.rclone.org/t/is-there-a-way-to-sync-while-keeping-file-description-on-the-destination/14609
This commit is contained in:
parent
fdb07f2f89
commit
6fdd7149c1
@ -642,17 +642,21 @@ func containsString(slice []string, s string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// getRootID returns the canonical ID for the "root" ID
|
// getFile returns drive.File for the ID passed and fields passed in
|
||||||
func (f *Fs) getRootID() (string, error) {
|
func (f *Fs) getFile(ID string, fields googleapi.Field) (info *drive.File, err error) {
|
||||||
var info *drive.File
|
|
||||||
var err error
|
|
||||||
err = f.pacer.CallNoRetry(func() (bool, error) {
|
err = f.pacer.CallNoRetry(func() (bool, error) {
|
||||||
info, err = f.svc.Files.Get("root").
|
info, err = f.svc.Files.Get(ID).
|
||||||
Fields("id").
|
Fields(fields).
|
||||||
SupportsAllDrives(true).
|
SupportsAllDrives(true).
|
||||||
Do()
|
Do()
|
||||||
return f.shouldRetry(err)
|
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 {
|
if err != nil {
|
||||||
return "", errors.Wrap(err, "couldn't find root directory ID")
|
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) {
|
func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object, error) {
|
||||||
var srcObj *baseObject
|
var srcObj *baseObject
|
||||||
ext := ""
|
ext := ""
|
||||||
|
readDescription := false
|
||||||
switch src := src.(type) {
|
switch src := src.(type) {
|
||||||
case *Object:
|
case *Object:
|
||||||
srcObj = &src.baseObject
|
srcObj = &src.baseObject
|
||||||
case *documentObject:
|
case *documentObject:
|
||||||
srcObj, ext = &src.baseObject, src.ext()
|
srcObj, ext = &src.baseObject, src.ext()
|
||||||
|
readDescription = true
|
||||||
case *linkObject:
|
case *linkObject:
|
||||||
srcObj, ext = &src.baseObject, src.ext()
|
srcObj, ext = &src.baseObject, src.ext()
|
||||||
default:
|
default:
|
||||||
@ -2070,6 +2076,19 @@ func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object,
|
|||||||
return nil, err
|
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
|
var info *drive.File
|
||||||
err = f.pacer.Call(func() (bool, error) {
|
err = f.pacer.Call(func() (bool, error) {
|
||||||
info, err = f.svc.Files.Copy(srcObj.id, createInfo).
|
info, err = f.svc.Files.Copy(srcObj.id, createInfo).
|
||||||
|
Loading…
Reference in New Issue
Block a user