-
Notifications
You must be signed in to change notification settings - Fork 18k
fs: ValidPath() docs seem to contradict test case regarding "." #70155
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
Comments
It allows for |
Thanks but that doesn't really address my questions. Can the docs be reworded then? Because ./foo complies with what is allowed currently. Also what about a directory that is literally named .? How is one supposed to specify that? |
Directories literally named You are reading the docs wrong. You are not permitted to refer to a directory as |
Okay, thanks for clarifying. Maybe the doc could be reworded/clarified, that it's referring to the root of the file system, not a folder in the root named ".". This policy still leaves us with the problem of what to do about literal files named "." as appear in some tar archives (for example: request your user data from GitHub, and the downloaded tar has a "." folder in its root). Deciding that it's "not supported" or "not permitted" seems arbitrary when there are folders/files named ".". Is there a technical reason that this limitation exists, or is it just because we like clean paths? |
The technical reason is that the io/fs package is providing an abstraction of a simple unrooted file system. By not permitting names like The expectation is that translation from some other file system to io/fs will clean paths as necessary. If a tar archive contains a file |
The problem is an archive that looks like:
now becomes untenable because this restriction in io/fs forces us to treat |
In that tree are |
Yep. I agree, that's just how it is though. (Perhaps the Anyway, I will try to find a work around. (But I still recommend a clarification of the docs) |
Change https://go.dev/cl/624595 mentions this issue: |
Looks good. 👍 Thank you! |
For #70155 Change-Id: I648791c484e19bb12c6e4f84e2dc42eaaa4db546 Reviewed-on: https://go-review.googlesource.com/c/go/+/624595 Reviewed-by: Damien Neil <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> Reviewed-by: David Chase <[email protected]>
Go version
go version go1.23.2 linux/amd64
Output of
go env
in your module/workspace:What did you do?
Trying to implement
fs.FS
with the use offs.ValidName()
.What did you see happen?
A path of
./foo
is rejected, even though a file system literally has a root directory named ".", and the docs for fs.ValidPath() state (emphasis mine):Here, the root directory is named ".", and the docs say that should be an exception that is allowed. Yet the test case seems to show otherwise:
{"./x", false},
What did you expect to see?
I might be reading the docs wrong, but it seems like this should be allowed, especially since there are virtual file systems (like a tar archive) where there are literally root directories named "." (this can happen apparently when a tar archive is created in the same directory it is archiving).
The text was updated successfully, but these errors were encountered: