local: support setting custom --metadata during server-side Copy

This commit is contained in:
nielash 2024-07-24 19:30:53 -04:00 committed by Nick Craig-Wood
parent 87ec26001f
commit f6d836eefd

View File

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