From b5ba077a2f78161248f175bb18ef4dd007134e4a Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Tue, 18 Aug 2020 19:36:50 +0100 Subject: [PATCH] drive: work around drive bug which didn't set modtime of copied docs Google drive appears to no longer be copying the modification time of google docs. Setting the mod time immediately after the copy doesn't work either, so this patch copies the object, waits for 1 second and then sets the modtime. Fixes #4517 --- backend/drive/drive.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/backend/drive/drive.go b/backend/drive/drive.go index 02efb3f50..e12953c6e 100755 --- a/backend/drive/drive.go +++ b/backend/drive/drive.go @@ -2258,13 +2258,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 + isDoc := false switch src := src.(type) { case *Object: srcObj = &src.baseObject case *documentObject: srcObj, ext = &src.baseObject, src.ext() - readDescription = true + isDoc = true case *linkObject: srcObj, ext = &src.baseObject, src.ext() default: @@ -2288,7 +2288,7 @@ func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object, return nil, err } - if readDescription { + if isDoc { // preserve the description on copy for docs info, err := f.getFile(actualID(srcObj.id), "description") if err != nil { @@ -2320,6 +2320,22 @@ func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object, if err != nil { return nil, err } + // Google docs aren't preserving their mod time after copy, so set them explicitly + // See: https://github.com/rclone/rclone/issues/4517 + // + // FIXME remove this when google fixes the problem! + if isDoc { + // A short sleep is needed here in order to make the + // change effective, without it is is ignored. This is + // probably some eventual consistency nastiness. + sleepTime := 2 * time.Second + fs.Debugf(f, "Sleeping for %v before setting the modtime to work around drive bug - see #4517") + time.Sleep(sleepTime) + err = newObject.SetModTime(ctx, src.ModTime(ctx)) + if err != nil { + return nil, err + } + } if existingObject != nil { err = existingObject.Remove(ctx) if err != nil {