diff --git a/cloudstorage_fs.go b/cloudstorage_fs.go index 4319d67..8d8e92f 100644 --- a/cloudstorage_fs.go +++ b/cloudstorage_fs.go @@ -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 } @@ -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) diff --git a/cloudstorage_fs_test.go b/cloudstorage_fs_test.go index 008a85f..038cbdc 100644 --- a/cloudstorage_fs_test.go +++ b/cloudstorage_fs_test.go @@ -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() diff --git a/fs.go b/fs.go index ab88a89..ce5a5d3 100644 --- a/fs.go +++ b/fs.go @@ -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 }