Skip to content

Commit

Permalink
blob/all: Don't require SetIOFSCallback to use io/fs.FS functions (#3479
Browse files Browse the repository at this point in the history
)
  • Loading branch information
vangent authored Aug 21, 2024
1 parent d2adbc5 commit bb796f8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
3 changes: 2 additions & 1 deletion blob/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,8 @@ var NewBucket = newBucket
// function; see the package documentation for details.
func newBucket(b driver.Bucket) *Bucket {
return &Bucket{
b: b,
b: b,
ioFSCallback: func() (context.Context, *ReaderOptions) { return context.Background(), nil },
tracer: &oc.Tracer{
Package: pkgName,
Provider: oc.ProviderName(b),
Expand Down
8 changes: 3 additions & 5 deletions blob/blob_fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,15 @@ func (d *iofsDir) openOnce() error {
//
// fn should return a context.Context and *ReaderOptions that can be used in
// calls to List and NewReader on b. It may be called more than once.
//
// If SetIOFSCallback is never called, io.FS functions will use context.Background
// and a default ReaderOptions.
func (b *Bucket) SetIOFSCallback(fn func() (context.Context, *ReaderOptions)) {
b.ioFSCallback = fn
}

// Open implements fs.FS.Open (https://pkg.go.dev/io/fs#FS).
//
// SetIOFSCallback must be called prior to calling this function.
func (b *Bucket) Open(path string) (fs.File, error) {
if b.ioFSCallback == nil {
return nil, gcerr.Newf(gcerr.InvalidArgument, nil, "blob: Open -- SetIOFSCallback must be called before Open")
}
if !fs.ValidPath(path) {
return nil, &fs.PathError{Op: "open", Path: path, Err: fs.ErrInvalid}
}
Expand Down
1 change: 0 additions & 1 deletion blob/blob_fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ func initBucket(t *testing.T, files []string) *blob.Bucket {
ctx := context.Background()

b := memblob.OpenBucket(nil)
b.SetIOFSCallback(func() (context.Context, *blob.ReaderOptions) { return ctx, nil })
for _, f := range files {
if err := b.WriteAll(ctx, f, []byte("data"), nil); err != nil {
t.Fatal(err)
Expand Down

0 comments on commit bb796f8

Please sign in to comment.