Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

Commit

Permalink
Introduce Attributes.CustomTime
Browse files Browse the repository at this point in the history
  • Loading branch information
pior committed Jul 29, 2024
1 parent afaeb6f commit 3ecff12
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cloudstorage_fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func (c *cloudStorageFS) Attributes(ctx context.Context, path string, _ *ReaderO
Metadata: a.Metadata,
ModTime: a.Updated,
CreationTime: a.Created,
CustomTime: a.CustomTime,
Size: a.Size,
}, nil
}
Expand All @@ -122,6 +123,7 @@ func (c *cloudStorageFS) Create(ctx context.Context, path string, options *Write
w.ContentType = options.Attributes.ContentType
w.ContentEncoding = options.Attributes.ContentEncoding
w.ChunkSize = options.BufferSize
w.CustomTime = options.Attributes.CustomTime
}
w.ChunkSize = c.chunkSize(w.ChunkSize)

Expand Down
35 changes: 35 additions & 0 deletions cloudstorage_fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,41 @@ func Test_cloudStorageFS_Content_Encoding(t *testing.T) {
})
}

func Test_cloudStorageFS_CustomTime(t *testing.T) {
ctx := context.Background()

withCloudStorageFS(t, func(fs storage.FS) {
path := "foo"

customTime := time.Date(2030, 1, 1, 0, 0, 0, 0, time.UTC)

wc, err := fs.Create(ctx, path, &storage.WriterOptions{
Attributes: storage.Attributes{
CustomTime: customTime,
},
})
require.NoError(t, err)

_, err = wc.Write([]byte(""))
require.NoError(t, err)

err = wc.Close()
require.NoError(t, err)

// Open()

f, err := fs.Open(ctx, path, nil)
require.NoError(t, err)
require.Zero(t, f.Attributes.CustomTime) // CustomTime is not available when reading an object.

// Attributes()

attrs, err := fs.Attributes(ctx, path, nil)
require.NoError(t, err)
require.Equal(t, customTime, attrs.CustomTime)
})
}

func withCloudStorageFS(tb testing.TB, cb func(fs storage.FS)) {
tb.Helper()

Expand Down
2 changes: 2 additions & 0 deletions fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ type Attributes struct {
ModTime time.Time
// CreationTime is the time the blob object was created.
CreationTime time.Time
// CustomTime is a special time attribute that can have multiple purposes.
CustomTime time.Time
// Size is the size of the object in bytes.
Size int64
}
Expand Down

0 comments on commit 3ecff12

Please sign in to comment.