Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blob/all: Don't require SetIOFSCallback be called to use io/fs.FS functions #3479

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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
Loading