diff --git a/cmd/disk-cache-backend.go b/cmd/disk-cache-backend.go index 4b2c3e389..856891227 100644 --- a/cmd/disk-cache-backend.go +++ b/cmd/disk-cache-backend.go @@ -538,12 +538,15 @@ func (c *diskCache) saveMetadata(ctx context.Context, bucket, object string, met } m.Ranges[rs.String(actualSize)] = rsFileName } - } else { + } + if rs == nil && !incHitsOnly { // this is necessary cleanup of range files if entire object is cached. - for _, f := range m.Ranges { - removeAll(pathJoin(cachedPath, f)) + if _, err := os.Stat(pathJoin(cachedPath, cacheDataFile)); err == nil { + for _, f := range m.Ranges { + removeAll(pathJoin(cachedPath, f)) + } + m.Ranges = nil } - m.Ranges = nil } m.Stat.Size = actualSize m.Stat.ModTime = UTCNow()