fs: add --metadata/-M flag to control whether metadata is copied
This commit is contained in:
parent
c4451bc43a
commit
78d52882ca
4 changed files with 17 additions and 0 deletions
|
@ -134,6 +134,7 @@ type ConfigInfo struct {
|
|||
HumanReadable bool
|
||||
KvLockTime time.Duration // maximum time to keep key-value database locked by process
|
||||
DisableHTTPKeepAlives bool
|
||||
Metadata bool
|
||||
}
|
||||
|
||||
// NewConfig creates a new config with everything set to the default
|
||||
|
|
|
@ -140,6 +140,7 @@ func AddFlags(ci *fs.ConfigInfo, flagSet *pflag.FlagSet) {
|
|||
flags.BoolVarP(flagSet, &ci.HumanReadable, "human-readable", "", ci.HumanReadable, "Print numbers in a human-readable format, sizes with suffix Ki|Mi|Gi|Ti|Pi")
|
||||
flags.DurationVarP(flagSet, &ci.KvLockTime, "kv-lock-time", "", ci.KvLockTime, "Maximum time to keep key-value database locked by process")
|
||||
flags.BoolVarP(flagSet, &ci.DisableHTTPKeepAlives, "disable-http-keep-alives", "", ci.DisableHTTPKeepAlives, "Disable HTTP keep-alives and use each connection once.")
|
||||
flags.BoolVarP(flagSet, &ci.Metadata, "metadata", "M", ci.Metadata, "If set, preserve metadata when copying objects")
|
||||
}
|
||||
|
||||
// ParseHeaders converts the strings passed in via the header flags into HTTPOptions
|
||||
|
|
|
@ -68,8 +68,14 @@ func GetMetadata(ctx context.Context, o ObjectInfo) (metadata Metadata, err erro
|
|||
|
||||
// GetMetadataOptions from an ObjectInfo and merge it with any in options
|
||||
//
|
||||
// If --metadata isn't in use it will return nil
|
||||
//
|
||||
// If the object has no metadata then metadata will be nil
|
||||
func GetMetadataOptions(ctx context.Context, o ObjectInfo, options []OpenOption) (metadata Metadata, err error) {
|
||||
ci := GetConfig(ctx)
|
||||
if !ci.Metadata {
|
||||
return nil, nil
|
||||
}
|
||||
metadata, err = GetMetadata(ctx, o)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -206,6 +206,15 @@ func PutTestContentsMetadata(ctx context.Context, t *testing.T, f fs.Fs, file *f
|
|||
file.Size = int64(buf.Len())
|
||||
obji := object.NewStaticObjectInfo(file.Path, file.ModTime, file.Size, true, nil, nil)
|
||||
if mimeType != "" || metadata != nil {
|
||||
// force the --metadata flag on temporarily
|
||||
if metadata != nil {
|
||||
ci := fs.GetConfig(ctx)
|
||||
previousMetadata := ci.Metadata
|
||||
ci.Metadata = true
|
||||
defer func() {
|
||||
ci.Metadata = previousMetadata
|
||||
}()
|
||||
}
|
||||
obji = overrideMimeType(obji, mimeType, metadata)
|
||||
}
|
||||
obj, err = f.Put(ctx, in, obji)
|
||||
|
|
Loading…
Reference in a new issue