From f6d836eefd8dbd4e55d0594b90176d907de52a0a Mon Sep 17 00:00:00 2001 From: nielash Date: Wed, 24 Jul 2024 19:30:53 -0400 Subject: [PATCH] local: support setting custom --metadata during server-side Copy --- backend/local/clone_darwin.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/backend/local/clone_darwin.go b/backend/local/clone_darwin.go index 2dbff2c05..abce58134 100644 --- a/backend/local/clone_darwin.go +++ b/backend/local/clone_darwin.go @@ -5,6 +5,7 @@ package local import ( "context" + "fmt" "runtime" "github.com/go-darwin/apfs" @@ -30,9 +31,15 @@ func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object, return nil, fs.ErrorCantCopy } + // Fetch metadata if --metadata is in use + meta, err := fs.GetMetadataOptions(ctx, f, src, fs.MetadataAsOpenOptions(ctx)) + if err != nil { + return nil, fmt.Errorf("copy: failed to read metadata: %w", err) + } + // Create destination dstObj := f.newObject(remote) - err := dstObj.mkdirAll() + err = dstObj.mkdirAll() if err != nil { return nil, err } @@ -42,6 +49,15 @@ func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object, return nil, err } fs.Debugf(remote, "server-side cloned!") + + // Set metadata if --metadata is in use + if meta != nil { + err = dstObj.writeMetadata(meta) + if err != nil { + return nil, fmt.Errorf("copy: failed to set metadata: %w", err) + } + } + return f.NewObject(ctx, remote) }