From ebc35c8288719ef7ae07cf5b538ab15716f25ac2 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Sun, 24 Nov 2024 18:58:29 -0800 Subject: [PATCH] Persist created and updated time in compose 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 2fb33d02da..b6f0db20d7 100644 --- a/fakestorage/object_test.go +++ b/fakestorage/object_test.go @@ -2065,6 +2065,7 @@ func TestServiceClientComposeObject(t *testing.T) { ) u32Checksum := uint32Checksum([]byte(source1Content)) hash := checksum.MD5Hash([]byte(source1Content)) + now := time.Now() objs := []Object{ { @@ -2198,6 +2199,12 @@ func TestServiceClientComposeObject(t *testing.T) { if attrs.ContentType != contentType { t.Errorf("wrong content type\nwant %q\ngot %q", contentType, attrs.ContentType) } + if now.After(attrs.Created) { + t.Errorf("wrong created time\nwant < %v\ngot: %v", now, attrs.Created) + } + if now.After(attrs.Updated) { + t.Errorf("wrong updated time\nwant < %v\ngot: %v", now, 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 {