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

io/fs: wrong comment about func Glob(fsys FS, pattern string) #44252

Closed
DrGo opened this issue Feb 13, 2021 · 2 comments
Closed

io/fs: wrong comment about func Glob(fsys FS, pattern string) #44252

DrGo opened this issue Feb 13, 2021 · 2 comments
Labels
Documentation FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@DrGo
Copy link
Contributor

DrGo commented Feb 13, 2021

currently it says

// Glob ignores file system errors such as I/O errors reading directories.
// The only possible returned error is path.ErrBadPattern, reporting that
// the pattern is malformed.

but Glob now calls Stat() on pattern if pattern does not contains any of the magic characters recognized by path.Match (ie if pattern is just a file path). So any file io errors can occur (and returned).

I suspect that this change was done to allow Glob to be used in places like html/template.ParseFS which takes as arguments fs.FS and any number of glob patterns; in a way overloading it to replace both ParseGlob and ParseFiles.

I wish that ParseFS behaved more like ParseFiles (since globing is trivial to add by users if needed) or that we have both ParseGlobFS and ParseFilesFS (which IMO is cleaner: the FS versions act on fs.FS whereas the other two act on the OS filesystem). In a package I am working on, I had to copy/paste the code for template.ParseFiles into a func that takes an fs.FS because since I was processing the template files before passing them to ParseFiles, I did not need an additional Stat() call on them which would happen if I passed them to ParseFS.

Thanks,

@seankhliao seankhliao added Documentation NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Feb 13, 2021
@ianlancetaylor
Copy link
Contributor

In the current code, if the call to Stat fails, Glob returns a nil error, which seems consistent with the documentation.

I am likely missing something. Can you show an example of how a problem might occur? Thanks.

@DrGo
Copy link
Contributor Author

DrGo commented Feb 13, 2021

Sorry Ian, looked at that code for an hour but did not realize it returns nil rather than error.

@DrGo DrGo closed this as completed Feb 13, 2021
@golang golang locked and limited conversation to collaborators Feb 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants