Skip to content

Commit

Permalink
fix: add missing operation to fs path error (#799)
Browse files Browse the repository at this point in the history
When opening a folder as OCI image layout and there is no `oci-layout`
file exists, the error would be

> failed to open OCI layout file:  oci-layout: file does not exist

There is a duplicated space in the error string, because the `Op` field
is missing in the returned `fs.PathError`. With fix in this PR, the
return error would be
> failed to open OCI layout file: open oci-layout: file does not exist

Fixes #640

Signed-off-by: Billy Zha <jinzha1@microsoft.com>
  • Loading branch information
qweeah authored Jul 30, 2024
1 parent c8c2048 commit bacf8f0
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions internal/fs/tarfs/tarfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func New(path string) (*TarFS, error) {
// ValidPath(name), returning a *PathError with Err set to
// ErrInvalid or ErrNotExist.
func (tfs *TarFS) Open(name string) (file fs.File, openErr error) {
entry, err := tfs.getEntry(name)
entry, err := tfs.getEntry("open", name)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -98,26 +98,26 @@ func (tfs *TarFS) Open(name string) (file fs.File, openErr error) {
// Stat returns a FileInfo describing the file.
// If there is an error, it should be of type *PathError.
func (tfs *TarFS) Stat(name string) (fs.FileInfo, error) {
entry, err := tfs.getEntry(name)
entry, err := tfs.getEntry("stat", name)
if err != nil {
return nil, err
}
return entry.header.FileInfo(), nil
}

// getEntry returns the named entry.
func (tfs *TarFS) getEntry(name string) (*entry, error) {
if !fs.ValidPath(name) {
return nil, &fs.PathError{Path: name, Err: fs.ErrInvalid}
func (tfs *TarFS) getEntry(operation string, path string) (*entry, error) {
if !fs.ValidPath(path) {
return nil, &fs.PathError{Op: operation, Path: path, Err: fs.ErrInvalid}
}
entry, ok := tfs.entries[name]
entry, ok := tfs.entries[path]
if !ok {
return nil, &fs.PathError{Path: name, Err: fs.ErrNotExist}
return nil, &fs.PathError{Op: operation, Path: path, Err: fs.ErrNotExist}
}
if entry.header.Typeflag != tar.TypeReg {
// support regular files only
return nil, fmt.Errorf("%s: type flag %c is not supported: %w",
name, entry.header.Typeflag, errdef.ErrUnsupported)
path, entry.header.Typeflag, errdef.ErrUnsupported)
}
return entry, nil
}
Expand Down

0 comments on commit bacf8f0

Please sign in to comment.