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

Closed
josharian opened this issue Jun 15, 2021 · 1 comment
Closed

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

josharian opened this issue Jun 15, 2021 · 1 comment
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@josharian
Copy link
Contributor

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 https://play.golang.org/p/vVjpRABoLax. 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 (
	"fmt"
	"io/fs"
	"testing/fstest"
)

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 the NeedsFix The path to resolution is known, but the work has not been done. label Jun 15, 2021
@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
@gopherbot
Copy link

Change https://golang.org/cl/328409 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 golang.org/cl/328409,
which fixes upstream golang/go#46776.
@golang golang locked and limited conversation to collaborators Aug 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

2 participants