From bde0334bd8e2c16d9fbc49758cd9374f1d741bd2 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Mon, 24 Feb 2020 10:22:09 +0000 Subject: [PATCH] operations: fix setting the timestamp on Windows for multithread copy Before this fix we attempted to set the modification time on the file when it was open. This works fine on Linux but not on Windows. The test was also incorrect testing the source file rather than the destination file. This closes the file before setting the modification time and fixes the tests. Fixes #3994 --- fs/operations/multithread.go | 5 ++++- fs/operations/multithread_test.go | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/operations/multithread.go b/fs/operations/multithread.go index 1e8f5ec82..1f615d4b2 100644 --- a/fs/operations/multithread.go +++ b/fs/operations/multithread.go @@ -165,7 +165,6 @@ func multiThreadCopy(ctx context.Context, f fs.Fs, remote string, src fs.Object, if err != nil { return nil, errors.Wrap(err, "multpart copy: failed to open destination") } - defer fs.CheckClose(mc.wc, &err) fs.Debugf(src, "Starting multi-thread copy with %d parts of size %v", mc.streams, fs.SizeSuffix(mc.partSize)) for stream := 0; stream < mc.streams; stream++ { @@ -175,9 +174,13 @@ func multiThreadCopy(ctx context.Context, f fs.Fs, remote string, src fs.Object, }) } err = g.Wait() + closeErr := mc.wc.Close() if err != nil { return nil, err } + if closeErr != nil { + return nil, errors.Wrap(closeErr, "multi-thread copy: failed to close object after copy") + } obj, err := f.NewObject(ctx, remote) if err != nil { diff --git a/fs/operations/multithread_test.go b/fs/operations/multithread_test.go index 9e125a702..86ca3c1b6 100644 --- a/fs/operations/multithread_test.go +++ b/fs/operations/multithread_test.go @@ -138,7 +138,7 @@ func TestMultithreadCopy(t *testing.T) { assert.Equal(t, src.Size(), dst.Size()) assert.Equal(t, "file1", dst.Remote()) - fstest.CheckListingWithPrecision(t, r.Fremote, []fstest.Item{file1}, nil, fs.ModTimeNotSupported) + fstest.CheckItems(t, r.Flocal, file1) require.NoError(t, dst.Remove(context.Background())) }) }