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

fix: add missing operation to fs path error #799

Merged
merged 2 commits into from
Jul 30, 2024
Merged
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
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
Loading