From 315109182b17e3e2469ce231a4799a5962304542 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Sat, 4 Jan 2025 07:13:53 +0900 Subject: [PATCH] Persist created and updated time in compose (#1823) Also use the correct time format. --- fakestorage/object_test.go | 7 +++++++ internal/backend/fs.go | 4 +++- internal/backend/memory.go | 4 +++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/fakestorage/object_test.go b/fakestorage/object_test.go index 8cae0406d1..6987cfdf7d 100644 --- a/fakestorage/object_test.go +++ b/fakestorage/object_test.go @@ -2082,6 +2082,7 @@ func TestServiceClientComposeObject(t *testing.T) { ) u32Checksum := uint32Checksum([]byte(source1Content)) hash := checksum.MD5Hash([]byte(source1Content)) + then := time.Now().Add(time.Duration(-1) * time.Minute) objs := []Object{ { @@ -2215,6 +2216,12 @@ func TestServiceClientComposeObject(t *testing.T) { if attrs.ContentType != contentType { t.Errorf("wrong content type\nwant %q\ngot %q", contentType, attrs.ContentType) } + if then.After(attrs.Created) { + t.Errorf("wrong created time\nwant > %v\ngot: %v", then, attrs.Created) + } + if then.After(attrs.Updated) { + t.Errorf("wrong updated time\nwant > %v\ngot: %v", then, attrs.Updated) + } if !bytes.Equal(attrs.MD5, expectedHash) { t.Errorf("wrong hash returned\nwant %d\ngot %d", hash, attrs.MD5) } diff --git a/internal/backend/fs.go b/internal/backend/fs.go index c96867d802..b372ab8402 100644 --- a/internal/backend/fs.go +++ b/internal/backend/fs.go @@ -448,12 +448,14 @@ func (s *storageFS) ComposeObject(bucketName string, objectNames []string, desti sourceObjects = append(sourceObjects, obj) } + now := time.Now().Format(timestampFormat) dest := StreamingObject{ ObjectAttrs: ObjectAttrs{ BucketName: bucketName, Name: destinationName, ContentType: contentType, - Created: time.Now().String(), + Created: now, + Updated: now, }, } diff --git a/internal/backend/memory.go b/internal/backend/memory.go index c32f06abf2..2e95eb3ed5 100644 --- a/internal/backend/memory.go +++ b/internal/backend/memory.go @@ -361,12 +361,14 @@ func (s *storageMemory) ComposeObject(bucketName string, objectNames []string, d var dest Object streamingDest, err := s.GetObject(bucketName, destinationName) if err != nil { + now := time.Now().Format(timestampFormat) dest = Object{ ObjectAttrs: ObjectAttrs{ BucketName: bucketName, Name: destinationName, ContentType: contentType, - Created: time.Now().String(), + Created: now, + Updated: now, }, } } else {