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?)
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"."
causesfs.WalkDir
to recurse infinitely.To reproduce, use https://play.golang.org/p/vVjpRABoLax. Change
m["c"] =
tom["."] =
and hit "run". (To see it working as correctly, replacem["c"]
withm["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:
cc @rsc @ianlancetaylor
The text was updated successfully, but these errors were encountered: