hugo
hugo copied to clipboard
readDir/readFile should return nil when not found
Or to be more specific: nil
for readFile and a []os.FileInfo
for readDir (so it can be ranged over even if empty).
This is in line with resources.Get
etc. and what all would expect.
is the code located in @bep here?
https://github.com/gohugoio/hugo/blob/673cde1eb122888509cca32e322662af08187ff1/tpl/os/os.go#L71
and
https://github.com/gohugoio/hugo/blob/673cde1eb122888509cca32e322662af08187ff1/tpl/os/os.go#L102
can I jump in to help?
Yes, that's the code, and please create a PR. Looking at the code, readFile
returns a string, so an empty string when not found would be the medicine.
It would also be great if you could update the relevant snippets in /docs (in this repo) with a note about this new behaviour.
Thinking about this, could you wait with this until we have merged #9613
sure no problem!
have you been able to address this @rubiagatra ? can I help?
still waiting mentioned PR to merge @dibrinsofor
Has this been fixed? Can I jump in to help?
so an empty string when not found should be the medicine
It looks like it is like that, or maybe I am missing something. Can we possibly have some test that fails with current implementation?
func readFile(fs afero.Fs, filename string) (string, error) {
filename = filepath.Clean(filename)
if filename == "" || filename == "." || filename == string(_os.PathSeparator) {
return "", errors.New("invalid filename")
}
b, err := afero.ReadFile(fs, filename)
if err != nil {
return "", err
}
return string(b), nil
}
The other method is already fixed in #9613 so I think you can close that one as fixed once #9613 gets merged.
@bep Can I pick this one if not already done?
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.