From f88d171afd167be125186d58a49bdf9b57d6a6b4 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sat, 9 May 2015 10:37:43 +0100 Subject: [PATCH] s3: ignore etags from multipart uploads which aren't md5sums - fixes #56 --- s3/s3.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/s3/s3.go b/s3/s3.go index 207c8b707..0ad57cd7b 100644 --- a/s3/s3.go +++ b/s3/s3.go @@ -419,9 +419,17 @@ func (o *FsObjectS3) Remote() string { return o.remote } +var matchMd5 = regexp.MustCompile(`^[0-9a-f]{32}$`) + // Md5sum returns the Md5sum of an object returning a lowercase hex string func (o *FsObjectS3) Md5sum() (string, error) { - return strings.Trim(strings.ToLower(o.etag), `"`), nil + etag := strings.Trim(strings.ToLower(o.etag), `"`) + // Check the etag is a valid md5sum + if !matchMd5.MatchString(etag) { + fs.Debug(o, "Invalid md5sum (probably multipart uploaded) - ignoring: %q", etag) + return "", nil + } + return etag, nil } // Size returns the size of an object in bytes