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
This commit is contained in:
Nick Craig-Wood 2023-05-02 16:23:19 +01:00
parent dea6bdf3df
commit 65b2e378e0
2 changed files with 5 additions and 2 deletions

View File

@ -3884,7 +3884,7 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
if err != nil { if err != nil {
return err return err
} }
newO, err := o.fs.newObjectWithInfo(ctx, src.Remote(), info) newO, err := o.fs.newObjectWithInfo(ctx, o.remote, info)
if err != nil { if err != nil {
return err return err
} }

View File

@ -1522,9 +1522,12 @@ func Run(t *testing.T, opt *Opt) {
file1.Size = int64(buf.Len()) file1.Size = int64(buf.Len())
obj := findObject(ctx, t, f, file1.Path) 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) err := obj.Update(ctx, in, obji)
require.NoError(t, err) require.NoError(t, err)
remoteAfter := obj.Remote()
assert.Equal(t, remoteBefore, remoteAfter, "Remote should not change")
file1.Hashes = hash.Sums() file1.Hashes = hash.Sums()
// check the object has been updated // check the object has been updated