From b7199fe3d71f88ae72718980643eef9a3d3f2ed5 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Wed, 29 May 2019 10:24:49 +0100 Subject: [PATCH] s3: when copying from s3 to s3, preserve metadata #111 See: https://forum.rclone.org/t/s3-bucket-migration-with-metadata-issues/10262 --- backend/s3/s3.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/backend/s3/s3.go b/backend/s3/s3.go index fc570413b..8a7242a22 100644 --- a/backend/s3/s3.go +++ b/backend/s3/s3.go @@ -3171,11 +3171,26 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op multipart := size < 0 || size >= int64(o.fs.opt.UploadCutoff) - // Set the mtime in the meta data - metadata := map[string]*string{ - metaMtime: aws.String(swift.TimeToFloatString(modTime)), + // Metadata for upload + metadata := map[string]*string{} + fs.Debugf(o, "src = %#v", src) + + // Read metadata from source s3 object if available + srcObj, ok := fs.UnWrapObjectInfo(src).(*Object) + if ok { + fs.Debugf(o, "Reading metadata from %v", srcObj) + err := srcObj.readMetaData(ctx) // reads info and meta, returning an error + if err != nil { + return err + } + for k, v := range srcObj.meta { + metadata[k] = v + } } + // Set the mtime in the meta data + metadata[metaMtime] = aws.String(swift.TimeToFloatString(modTime)) + // read the md5sum if available // - for non multipart // - so we can add a ContentMD5