Skip to content

Commit

Permalink
Persist created and updated time in compose (#1823)
Browse files Browse the repository at this point in the history
Also use the correct time format.
  • Loading branch information
gaul authored Jan 3, 2025
1 parent 6fcb3c9 commit 3151091
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
7 changes: 7 additions & 0 deletions fakestorage/object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
{
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 3 additions & 1 deletion internal/backend/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}

Expand Down
4 changes: 3 additions & 1 deletion internal/backend/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 3151091

Please sign in to comment.