fs: Update object modtime when metadata is updated (#12818)

Follow S3 behavior of updating object modtime when object metadata is
updated.
This commit is contained in:
Anis Elleuch 2021-07-28 15:36:38 +01:00 committed by GitHub
parent a78bc7bfdb
commit 20cacc3b04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 2 deletions

View File

@ -24,6 +24,7 @@ import (
pathutil "path" pathutil "path"
"runtime" "runtime"
"strings" "strings"
"time"
"github.com/minio/minio/internal/lock" "github.com/minio/minio/internal/lock"
"github.com/minio/minio/internal/logger" "github.com/minio/minio/internal/logger"
@ -168,6 +169,25 @@ func fsStat(ctx context.Context, statLoc string) (os.FileInfo, error) {
return fi, nil return fi, nil
} }
// fsTouch updates a file access & modtime with current time
func fsTouch(ctx context.Context, statLoc string) error {
if statLoc == "" {
logger.LogIf(ctx, errInvalidArgument)
return errInvalidArgument
}
if err := checkPathLength(statLoc); err != nil {
logger.LogIf(ctx, err)
return err
}
now := time.Now()
if err := os.Chtimes(statLoc, now, now); err != nil {
logger.LogIf(ctx, err)
return err
}
return nil
}
// Lookup if volume exists, returns volume attributes upon success. // Lookup if volume exists, returns volume attributes upon success.
func fsStatVolume(ctx context.Context, volume string) (os.FileInfo, error) { func fsStatVolume(ctx context.Context, volume string) (os.FileInfo, error) {
fi, err := fsStat(ctx, volume) fi, err := fsStat(ctx, volume)

View File

@ -682,8 +682,15 @@ func (fs *FSObjects) CopyObject(ctx context.Context, srcBucket, srcObject, dstBu
return oi, toObjectErr(err, srcBucket, srcObject) return oi, toObjectErr(err, srcBucket, srcObject)
} }
// Stat the file to get file size. fsObjectPath := pathJoin(fs.fsPath, srcBucket, srcObject)
fi, err := fsStatFile(ctx, pathJoin(fs.fsPath, srcBucket, srcObject))
// Update object modtime
err = fsTouch(ctx, fsObjectPath)
if err != nil {
return oi, toObjectErr(err, srcBucket, srcObject)
}
// Stat the file to get object info
fi, err := fsStatFile(ctx, fsObjectPath)
if err != nil { if err != nil {
return oi, toObjectErr(err, srcBucket, srcObject) return oi, toObjectErr(err, srcBucket, srcObject)
} }