diff --git a/go/runfiles/fs.go b/go/runfiles/fs.go index 77be39e0c..a30564fb2 100644 --- a/go/runfiles/fs.go +++ b/go/runfiles/fs.go @@ -17,6 +17,7 @@ package runfiles import ( "io" "io/fs" + "runtime" "sort" "strings" "time" @@ -29,7 +30,8 @@ import ( // apparent repo names that are visible to the current source repo // (with --enable_bzlmod). func (r *Runfiles) Open(name string) (fs.File, error) { - if !fs.ValidPath(name) { + // Required by testfs.TestFS. + if !fs.ValidPath(name) || (runtime.GOOS == "windows" && strings.ContainsRune(name, '\\')) { return nil, &fs.PathError{Op: "open", Path: name, Err: fs.ErrInvalid} } if name == "." { diff --git a/go/runfiles/manifest.go b/go/runfiles/manifest.go index 8c014d946..25b10b8fb 100644 --- a/go/runfiles/manifest.go +++ b/go/runfiles/manifest.go @@ -121,9 +121,7 @@ func (m *manifest) open(name string) (fs.File, error) { if err == ErrEmpty { return emptyFile(name), nil } else if err == nil { - // Go through os.DirFs to throw the correct error on invalid paths. - volumePrefix := filepath.VolumeName(r) + "/" - return os.DirFS(volumePrefix).Open(filepath.ToSlash(r[len(volumePrefix):])) + return os.Open(r) } }