diff --git a/cmd/disk-cache-backend.go b/cmd/disk-cache-backend.go index ba396bec4..6886c791c 100644 --- a/cmd/disk-cache-backend.go +++ b/cmd/disk-cache-backend.go @@ -103,7 +103,6 @@ func (m *cacheMeta) ToObjectInfo(bucket, object string) (o ObjectInfo) { } // We set file info only if its valid. - o.ModTime = m.Stat.ModTime o.Size = m.Stat.Size o.ETag = extractETag(m.Meta) o.ContentType = m.Meta["content-type"] @@ -122,6 +121,12 @@ func (m *cacheMeta) ToObjectInfo(bucket, object string) (o ObjectInfo) { o.Expires = t.UTC() } } + if mtime, ok := m.Meta["last-modified"]; ok { + if t, e = time.Parse(http.TimeFormat, mtime); e == nil { + o.ModTime = t.UTC() + } + } + // etag/md5Sum has already been extracted. We need to // remove to avoid it from appearing as part of user-defined metadata o.UserDefined = cleanMetadata(m.Meta) @@ -506,9 +511,7 @@ func (c *diskCache) statCache(ctx context.Context, cacheObjPath string) (meta *c } // get metadata of part.1 if full file has been cached. partial = true - fi, err := os.Stat(pathJoin(cacheObjPath, cacheDataFile)) - if err == nil { - meta.Stat.ModTime = atime.Get(fi) + if _, err := os.Stat(pathJoin(cacheObjPath, cacheDataFile)); err == nil { partial = false } return meta, partial, meta.Hits, nil @@ -570,7 +573,6 @@ func (c *diskCache) saveMetadata(ctx context.Context, bucket, object string, met } } m.Stat.Size = actualSize - m.Stat.ModTime = UTCNow() if !incHitsOnly { // reset meta m.Meta = meta diff --git a/cmd/disk-cache.go b/cmd/disk-cache.go index 385583c3e..049de51b1 100644 --- a/cmd/disk-cache.go +++ b/cmd/disk-cache.go @@ -200,6 +200,7 @@ func getMetadata(objInfo ObjectInfo) map[string]string { if !objInfo.Expires.Equal(timeSentinel) { metadata["expires"] = objInfo.Expires.Format(http.TimeFormat) } + metadata["last-modified"] = objInfo.ModTime.Format(http.TimeFormat) for k, v := range objInfo.UserDefined { metadata[k] = v } diff --git a/cmd/disk-cache_test.go b/cmd/disk-cache_test.go index a6a1ccbdd..161b4e395 100644 --- a/cmd/disk-cache_test.go +++ b/cmd/disk-cache_test.go @@ -18,6 +18,7 @@ package cmd import ( "testing" + "time" ) // Tests ToObjectInfo function. @@ -27,7 +28,7 @@ func TestCacheMetadataObjInfo(t *testing.T) { if objInfo.Size != 0 { t.Fatal("Unexpected object info value for Size", objInfo.Size) } - if !objInfo.ModTime.Equal(timeSentinel) { + if !objInfo.ModTime.Equal(time.Time{}) { t.Fatal("Unexpected object info value for ModTime ", objInfo.ModTime) } if objInfo.IsDir { diff --git a/cmd/object-api-utils.go b/cmd/object-api-utils.go index 7e2760bab..f3b789471 100644 --- a/cmd/object-api-utils.go +++ b/cmd/object-api-utils.go @@ -258,7 +258,7 @@ func cleanMetadata(metadata map[string]string) map[string]string { // Remove STANDARD StorageClass metadata = removeStandardStorageClass(metadata) // Clean meta etag keys 'md5Sum', 'etag', "expires", "x-amz-tagging". - return cleanMetadataKeys(metadata, "md5Sum", "etag", "expires", xhttp.AmzObjectTagging) + return cleanMetadataKeys(metadata, "md5Sum", "etag", "expires", xhttp.AmzObjectTagging, "last-modified") } // Filter X-Amz-Storage-Class field only if it is set to STANDARD.