Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions internal/storage/fake/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ func (b *bucket) mintObject(
func (b *bucket) mintFolder(folderName string) (f gcs.Folder) {
f = gcs.Folder{
Name: folderName,
UpdateTime: b.clock.Now(),
UpdateTime: b.clock.Now().UnixNano(),
}

return
Expand Down Expand Up @@ -1224,7 +1224,7 @@ func (b *bucket) RenameFolder(ctx context.Context, folderName string, destinatio
for i := range b.folders {
Comment thread
vedantdas-source marked this conversation as resolved.
if strings.HasPrefix(b.folders[i].Name, folderName) {
b.folders[i].Name = strings.Replace(b.folders[i].Name, folderName, destinationFolderId, 1)
b.folders[i].UpdateTime = time.Now()
b.folders[i].UpdateTime = time.Now().UnixNano()
Comment thread
vedantdas-source marked this conversation as resolved.
Outdated
}
}

Expand All @@ -1245,7 +1245,7 @@ func (b *bucket) RenameFolder(ctx context.Context, folderName string, destinatio
// Return the updated folder.
folder := &gcs.Folder{
Name: destinationFolderId,
UpdateTime: time.Now(),
UpdateTime: time.Now().UnixNano(),
Comment thread
vedantdas-source marked this conversation as resolved.
Outdated
}

return folder, nil
Expand Down
10 changes: 7 additions & 3 deletions internal/storage/gcs/folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,25 @@ package gcs

import (
"strings"
"time"

"cloud.google.com/go/storage/control/apiv2/controlpb"
)

type Folder struct {
Name string
UpdateTime time.Time
UpdateTime int64
}

func GCSFolder(bucketName string, attrs *controlpb.Folder) *Folder {
// Setting the parameters in Folder and doing conversions as necessary.
var updateTime int64
Comment thread
vedantdas-source marked this conversation as resolved.
t := attrs.GetUpdateTime().AsTime()
if !t.IsZero() {
updateTime = t.UnixNano()
}
return &Folder{
Name: getFolderName(bucketName, attrs.Name),
UpdateTime: attrs.GetUpdateTime().AsTime(),
UpdateTime: updateTime,
}
}

Expand Down
20 changes: 19 additions & 1 deletion internal/storage/gcs/folder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,23 @@ func TestGCSFolder(t *testing.T) {
gcsFolder := GCSFolder(TestBucketName, &attrs)

assert.Equal(t, attrs.Name, gcsFolder.Name)
assert.Equal(t, attrs.UpdateTime.AsTime(), gcsFolder.UpdateTime)
assert.Equal(t, attrs.UpdateTime.AsTime().UnixNano(), gcsFolder.UpdateTime)
}
func BenchmarkGCSFolder(b *testing.B) {
timestamp := &timestamppb.Timestamp{
Seconds: 1234567890,
}
attrs := controlpb.Folder{
Name: "projects/_/buckets/testBucket/folders/testFolder",
UpdateTime: timestamp,
}

b.ReportAllocs()
b.ResetTimer()
for b.Loop() {
// this triggers 2 allocations
// the string creation inside getFolderName()
// and the &Folder{} heap allocation
_ = GCSFolder("testBucket", &attrs)
}
}
Loading