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

testing/fstest: cannot chmod "." in MapFS #46776

josharian opened this issue Jun 15, 2021 · 1 comment

testing/fstest: cannot chmod "." in MapFS #46776

josharian opened this issue Jun 15, 2021 · 1 comment


Copy link

@josharian josharian commented Jun 15, 2021

fstest.MapFS synthesizes directories as needed. These directories have mode fs.ModeDir ("d---------"). This is an unhelpful default, in that copying that mode anywhere results in an unreadable directory.

You can work around this by explicitly providing directory entries. This works for all directories except ".". Providing a directory entry for "." causes fs.WalkDir to recurse infinitely.

To reproduce, use Change m["c"] = to m["."] = and hit "run". (To see it working as correctly, replace m["c"] with m["a"].)

The primary issue here is that providing a "." entry for fstest.MapFS should generate a well-formed filesystem. Secondarily, we might also want to change the default mode of synthesized fstest.MapFS directories and/or prevent infinite recursion in fs.WalkDir using a cheap cycle detection algorithm like Floyd-Warshall. (Opinions about these secondary fixes?)

The playground code mentioned above:

package main

import (

func main() {

	m := make(fstest.MapFS)
	m["a/b.txt"] = &fstest.MapFile{
		Mode: 0666,
	m["c"] = &fstest.MapFile{
		Mode: 0777 | fs.ModeDir,
	fs.WalkDir(m, ".", func(path string, d fs.DirEntry, err error) error {
		fi, err := d.Info()
		if err != nil {
			return err
		fmt.Printf("%s: %v\n", path, fi.Mode())
		return nil

cc @rsc @ianlancetaylor

@josharian josharian added this to the Go1.18 milestone Jun 15, 2021
@josharian josharian changed the title testing/fstest: cannot chmod "." testing/fstest: cannot chmod "." in MapFS Jun 15, 2021
Copy link

@gopherbot gopherbot commented Jun 15, 2021

Change mentions this issue: testing/fstest: allow specifying file for "." in MapFS

josharian added a commit to josharian/mapfs that referenced this issue Jun 15, 2021
This corresponds to,
which fixes upstream golang/go#46776.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants