Prior to this commit, specifying a file for "." in MapFS
created an invalid fs.FS and caused infinite recursion in fs.WalkDir.
Fixes #46776
Change-Id: Ia9e4ae1125355a74dba9ee6b36451b7fda75a862
Reviewed-on: https://go-review.googlesource.com/c/go/+/328409
Trust: Josh Bleecher Snyder <josharian@gmail.com>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
for fname, f := range fsys {
i := strings.Index(fname, "/")
if i < 0 {
- list = append(list, mapFileInfo{fname, f})
+ if fname != "." {
+ list = append(list, mapFileInfo{fname, f})
+ }
} else {
need[fname[:i]] = true
}
package fstest
import (
+ "fmt"
+ "io/fs"
+ "strings"
"testing"
)
t.Fatal(err)
}
}
+
+func TestMapFSChmodDot(t *testing.T) {
+ m := MapFS{
+ "a/b.txt": &MapFile{Mode: 0666},
+ ".": &MapFile{Mode: 0777 | fs.ModeDir},
+ }
+ buf := new(strings.Builder)
+ fs.WalkDir(m, ".", func(path string, d fs.DirEntry, err error) error {
+ fi, err := d.Info()
+ if err != nil {
+ return err
+ }
+ fmt.Fprintf(buf, "%s: %v\n", path, fi.Mode())
+ return nil
+ })
+ want := `
+.: drwxrwxrwx
+a: d---------
+a/b.txt: -rw-rw-rw-
+`[1:]
+ got := buf.String()
+ if want != got {
+ t.Errorf("MapFS modes want:\n%s\ngot:\n%s\n", want, got)
+ }
+}