Skip to content

Commit

Permalink
wkfs/gcs: on Open, return os.ErrNotExist when storage.ErrObjectNotExi…
Browse files Browse the repository at this point in the history
…st occurs

And document wkfs.Open accordingly.
  • Loading branch information
mpl committed Aug 9, 2018
1 parent 9599cf2 commit df50f1d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions wkfs/gcs/gcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ func (fs *gcsFS) Open(name string) (wkfs.File, error) {
obj := fs.sc.Bucket(bucket).Object(fileName)
attrs, err := obj.Attrs(fs.ctx)
if err != nil {
if err == storage.ErrObjectNotExist {
return nil, os.ErrNotExist
}
return nil, err
}
size := attrs.Size
Expand Down
4 changes: 4 additions & 0 deletions wkfs/wkfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ type FileWriter interface {
io.Closer
}

// Open opens the object designated by name, for reading and/or writing as a
// file. The returned error can be checked with
// https://golang.org/pkg/os/#IsNotExist to ascertain whether the object actually
// exists.
func Open(name string) (File, error) { return fs(name).Open(name) }
func Stat(name string) (os.FileInfo, error) { return fs(name).Stat(name) }
func Lstat(name string) (os.FileInfo, error) { return fs(name).Lstat(name) }
Expand Down

0 comments on commit df50f1d

Please sign in to comment.