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
This commit is contained in:
Nick Craig-Wood 2020-02-24 10:22:09 +00:00
parent 5470d34740
commit bde0334bd8
2 changed files with 5 additions and 2 deletions

View File

@ -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 {

View File

@ -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()))
})
}