s3: Fix corrupting Content-Type on mod time update

This fixes an issue where updating the modification time resets the
content-type to the S3 default of binary/octet-stream which breaks
static websites that expect an html file to have a content-type of
text/html.
This commit is contained in:
Joseph Spurrier 2016-01-02 03:58:48 -05:00 committed by Nick Craig-Wood
parent 6a64567dd7
commit fe0289f2f5

View File

@ -644,6 +644,9 @@ func (o *Object) SetModTime(modTime time.Time) {
} }
o.meta[metaMtime] = aws.String(swift.TimeToFloatString(modTime)) o.meta[metaMtime] = aws.String(swift.TimeToFloatString(modTime))
// Guess the content type
contentType := fs.MimeType(o)
// Copy the object to itself to update the metadata // Copy the object to itself to update the metadata
key := o.fs.root + o.remote key := o.fs.root + o.remote
sourceKey := o.fs.bucket + "/" + key sourceKey := o.fs.bucket + "/" + key
@ -652,6 +655,7 @@ func (o *Object) SetModTime(modTime time.Time) {
Bucket: &o.fs.bucket, Bucket: &o.fs.bucket,
ACL: &o.fs.perm, ACL: &o.fs.perm,
Key: &key, Key: &key,
ContentType: &contentType,
CopySource: &sourceKey, CopySource: &sourceKey,
Metadata: o.meta, Metadata: o.meta,
MetadataDirective: &directive, MetadataDirective: &directive,