return dirFS(dir)
}
+// containsAny reports whether any bytes in chars are within s.
func containsAny(s, chars string) bool {
for i := 0; i < len(s); i++ {
for j := 0; j < len(chars); j++ {
}
f, err := Open(dir.join(name))
if err != nil {
- if runtime.GOOS == "windows" {
- // Undo the backslash conversion done by dir.join.
- perr := err.(*PathError)
- if containsAny(perr.Path, `\`) {
- perr.Path = string(dir) + "/" + name
- }
- }
- return nil, err // nil fs.File
+ // DirFS takes a string appropriate for GOOS,
+ // while the name argument here is always slash separated.
+ // dir.join will have mixed the two; undo that for
+ // error reporting.
+ err.(*PathError).Path = name
+ return nil, err
}
return f, nil
}
}
f, err := Stat(dir.join(name))
if err != nil {
+ // See comment in dirFS.Open.
+ err.(*PathError).Path = name
return nil, err
}
return f, nil
t.Fatal(err)
}
- // Test that the error message does not contain a backslash.
+ // Test that the error message does not contain a backslash,
+ // and does not contain the DirFS argument.
const nonesuch = "dir/nonesuch"
_, err := fs.Open(nonesuch)
if err == nil {
if !strings.Contains(err.Error(), nonesuch) {
t.Errorf("error %q does not contain %q", err, nonesuch)
}
+ if strings.Contains(err.Error(), "testdata") {
+ t.Errorf("error %q contains %q", err, "testdata")
+ }
}
// Test that Open does not accept backslash as separator.