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/ioutil: ReadDir: no error if dirname
is a file
#9789
Comments
I think it would be reasonable to check that os.File.Readdir and os.File.Readdirnames return an error if used on a non-directory. As far as I can see that should already happens on GNU/Linux. What OS are you using? |
@ianlancetaylor |
dirname
is a filedirname
is a file
On Linux:
On OS X:
|
syscall.Getdirentries is actually returning EINVAL on OS X, but @rsc added Yosemite work-around code to mask that error away. With my added logging the syscall func is:
But I thought that the Yosemite issue was fixed? |
The commit that added the Yosemite workaround was a83bbc9 |
I've sent https://go-review.googlesource.com/4164 |
Hi, I noticed that if you run
ioutil.ReadDir("/some/file.txt")
, it succeeds and returns an empty array ofos.FileInfo
and no error. I would expect an error, since the input is a file, not a dir.See
go/src/io/ioutil/ioutil.go
Line 100 in c007ce8
Equivalent operations in the stdlib of, for example, Python are
os.listdir
, and this raises an error if you pass in a file instead of a directory.Is this a bug, or is this the intended behavior? If the latter, why?
If it's a bug I'll be happy to submit a patch.
Thanks!
The text was updated successfully, but these errors were encountered: