From 48a8bfa6b3147d263d59e3ca1d6ce8b2c6ae94d0 Mon Sep 17 00:00:00 2001 From: Vitor Gomes Date: Tue, 10 Oct 2023 16:31:21 +0200 Subject: [PATCH] operations: fix OpenOptions ignored in copy if operation was a multiThreadCopy --- fs/operations/multithread.go | 4 ++-- fs/operations/operations.go | 22 ++++++++++++---------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/fs/operations/multithread.go b/fs/operations/multithread.go index 9b79e6fa1..e5357dc0b 100644 --- a/fs/operations/multithread.go +++ b/fs/operations/multithread.go @@ -127,7 +127,7 @@ func calculateNumChunks(size int64, chunkSize int64) int { // Copy src to (f, remote) using streams download threads. It tries to use the OpenChunkWriter feature // and if that's not available it creates an adapter using OpenWriterAt -func multiThreadCopy(ctx context.Context, f fs.Fs, remote string, src fs.Object, concurrency int, tr *accounting.Transfer) (newDst fs.Object, err error) { +func multiThreadCopy(ctx context.Context, f fs.Fs, remote string, src fs.Object, concurrency int, tr *accounting.Transfer, options ...fs.OpenOption) (newDst fs.Object, err error) { openChunkWriter := f.Features().OpenChunkWriter ci := fs.GetConfig(ctx) noseek := false @@ -148,7 +148,7 @@ func multiThreadCopy(ctx context.Context, f fs.Fs, remote string, src fs.Object, return nil, fmt.Errorf("multi-thread copy: can't copy zero sized file") } - info, chunkWriter, err := openChunkWriter(ctx, remote, src) + info, chunkWriter, err := openChunkWriter(ctx, remote, src, options...) if err != nil { return nil, fmt.Errorf("multi-thread copy: failed to open chunk writer: %w", err) } diff --git a/fs/operations/operations.go b/fs/operations/operations.go index 3c1ced8db..262f9fedd 100644 --- a/fs/operations/operations.go +++ b/fs/operations/operations.go @@ -422,8 +422,17 @@ func Copy(ctx context.Context, f fs.Fs, dst fs.Object, remote string, src fs.Obj removeFailedPartialCopy(ctx, f, remotePartial) }) } + + uploadOptions := []fs.OpenOption{hashOption} + for _, option := range ci.UploadHeaders { + uploadOptions = append(uploadOptions, option) + } + if ci.MetadataSet != nil { + uploadOptions = append(uploadOptions, fs.MetadataOption(ci.MetadataSet)) + } + if doMultiThreadCopy(ctx, f, src) { - dst, err = multiThreadCopy(ctx, f, remotePartial, src, ci.MultiThreadStreams, tr) + dst, err = multiThreadCopy(ctx, f, remotePartial, src, ci.MultiThreadStreams, tr, uploadOptions...) if err == nil { newDst = dst } @@ -467,17 +476,10 @@ func Copy(ctx context.Context, f fs.Fs, dst fs.Object, remote string, src fs.Obj if src.Remote() != remotePartial { wrappedSrc = fs.NewOverrideRemote(src, remotePartial) } - options := []fs.OpenOption{hashOption} - for _, option := range ci.UploadHeaders { - options = append(options, option) - } - if ci.MetadataSet != nil { - options = append(options, fs.MetadataOption(ci.MetadataSet)) - } if doUpdate && inplace { - err = dst.Update(ctx, in, wrappedSrc, options...) + err = dst.Update(ctx, in, wrappedSrc, uploadOptions...) } else { - dst, err = f.Put(ctx, in, wrappedSrc, options...) + dst, err = f.Put(ctx, in, wrappedSrc, uploadOptions...) } if doUpdate { actionTaken = "Copied (replaced existing)"