"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
fs: add --metadata/-M flag to control whether metadata is copied
Nick Craig-Wood78d52882ca9f
diff --git a/fs/config.go b/fs/config.goindex dceb063bb..a39779bae 100644--- a/fs/config.go+++ b/fs/config.go@@ -134,6 +134,7 @@ type ConfigInfo struct {HumanReadable boolKvLockTime time.Duration // maximum time to keep key-value database locked by processDisableHTTPKeepAlives bool+ Metadata bool}// NewConfig creates a new config with everything set to the defaultdiff --git a/fs/config/configflags/configflags.go b/fs/config/configflags/configflags.goindex de9d08073..61aa65f91 100644--- a/fs/config/configflags/configflags.go+++ b/fs/config/configflags/configflags.go@@ -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 HTTPOptionsdiff --git a/fs/metadata.go b/fs/metadata.goindex 50d0340ed..1fa48dc77 100644--- a/fs/metadata.go+++ b/fs/metadata.go@@ -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 nilfunc 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, errdiff --git a/fstest/fstests/fstests.go b/fstest/fstests/fstests.goindex 5d24296a0..9cc95896e 100644--- a/fstest/fstests/fstests.go+++ b/fstest/fstests/fstests.go@@ -206,6 +206,15 @@ func PutTestContentsMetadata(ctx context.Context, t *testing.T, f fs.Fs, file *ffile.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)