// chroot-style security mechanism, and Sub does not change that fact.
func Sub(fsys FS, dir string) (FS, error) {
if !ValidPath(dir) {
- return nil, &PathError{Op: "sub", Path: dir, Err: errors.New("invalid name")}
+ return nil, &PathError{Op: "sub", Path: dir, Err: ErrInvalid}
}
if dir == "." {
return fsys, nil
// fullName maps name to the fully-qualified name dir/name.
func (f *subFS) fullName(op string, name string) (string, error) {
if !ValidPath(name) {
- return "", &PathError{Op: op, Path: name, Err: errors.New("invalid name")}
+ return "", &PathError{Op: op, Path: name, Err: ErrInvalid}
}
return path.Join(f.dir, name), nil
}
package fs_test
import (
+ "errors"
. "io/fs"
"testing"
)
if pe.Path != "nonexist" {
t.Fatalf("Open(nonexist): err.Path = %q, want %q", pe.Path, "nonexist")
}
+
+ _, err = sub.Open("./")
+ if !errors.Is(err, ErrInvalid) {
+ t.Fatalf("Open(./): error is %v, want %v", err, ErrInvalid)
+ }
}