From 65b2e378e0992d6504e7398a16fa128f053f23ed Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Tue, 2 May 2023 16:23:19 +0100 Subject: [PATCH] drive: fix incorrect remote after Update on object Before this change, when Object.Update was called in the drive backend, it overwrote the remote with that of the object info. This is incorrect - the remote doesn't change on Update and this patch fixes that and introduces a new test to make sure it is correct for all backends. This was noticed when doing Update of objects in a nested combine backend. See: https://forum.rclone.org/t/rclone-runtime-goroutine-stack-exceeds-1000000000-byte-limit/37912 --- backend/drive/drive.go | 2 +- fstest/fstests/fstests.go | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/backend/drive/drive.go b/backend/drive/drive.go index 625f4a303..b07602bb4 100644 --- a/backend/drive/drive.go +++ b/backend/drive/drive.go @@ -3884,7 +3884,7 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op if err != nil { return err } - newO, err := o.fs.newObjectWithInfo(ctx, src.Remote(), info) + newO, err := o.fs.newObjectWithInfo(ctx, o.remote, info) if err != nil { return err } diff --git a/fstest/fstests/fstests.go b/fstest/fstests/fstests.go index b3bbc5724..46a6ff4b5 100644 --- a/fstest/fstests/fstests.go +++ b/fstest/fstests/fstests.go @@ -1522,9 +1522,12 @@ func Run(t *testing.T, opt *Opt) { file1.Size = int64(buf.Len()) obj := findObject(ctx, t, f, file1.Path) - obji := object.NewStaticObjectInfo(file1.Path, file1.ModTime, int64(len(contents)), true, nil, obj.Fs()) + remoteBefore := obj.Remote() + obji := object.NewStaticObjectInfo(file1.Path+"-should-be-ignored.bin", file1.ModTime, int64(len(contents)), true, nil, obj.Fs()) err := obj.Update(ctx, in, obji) require.NoError(t, err) + remoteAfter := obj.Remote() + assert.Equal(t, remoteBefore, remoteAfter, "Remote should not change") file1.Hashes = hash.Sums() // check the object has been updated