-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
os: Readdir returns error if file disappears during call #6680
Labels
Milestone
Comments
I agree that on the second pass, if the error is simply ENOENT, we don't have to add it to the list and don't need to return an error from Readdir. But if the error is something more serious (corrupt filesystem, or something), then Readdir should return an error. And if readdir does return an error, I think we're back to the same problem: filepath.Walk used to (and is documented to) let you see a file you can't stat. |
Readdir works better than I expected. It returns a []FileInfo for every name returned by Readdirnames, with a dummy entry for names for which Lstat failed. In the case of such a failed Lstat, Readdir also returns the first such error, but it still returns the full []FileInfo too. The change from Go 1.1 is that Go 1.1 returned nil even if there was a failed Lstat. I will reinstate that behavior. |
I don't think that's a "fix". Are you proposing changing it back to keep bug-for-bug compatibility with Go 1.1, or to fix filepath.Walk? If the former, at least be very explicit about that and update the documentation to say how it now works, now and forever. (sadly) I would prefer we just keep the new fixed behavior and adjust filepath.Walk accordingly. |
This issue was closed by revision ef805fe. Status changed to Fixed. |
Re-opening for Go1.3. Re-opening for Go1.3. See discussion at https://golang.org/cl/18870043 Proposal is to both fix os.File.Readdir to skip over Lstat ENOENT errors in the second pass on Unix and not ignore other Lstat errors, then change filepath.Walk to use Readdirnames + individual Lstat calls, as per the WalkFunc documentation. Labels changed: added go1.3, removed go1.2. Owner changed to @bradfitz. Status changed to Accepted. |
This issue was closed by revision 6a1a217. Status changed to Fixed. |
adg
added a commit
that referenced
this issue
May 11, 2015
««« CL 18870043 / eca0ca43a863 os: do not return Lstat errors from Readdir This CL restores the Go 1.1.2 semantics for os.File's Readdir method. The code in Go 1.1.2 was rewritten mainly because it looked buggy. This new version attempts to be clearer but still provide the 1.1.2 results. The important diff is not this CL's version against tip but this CL's version against Go 1.1.2. Go 1.1.2: names, err := f.Readdirnames(n) fi = make([]FileInfo, len(names)) for i, filename := range names { fip, err := Lstat(dirname + filename) if err == nil { fi[i] = fip } else { fi[i] = &fileStat{name: filename} } } return fi, err This CL: names, err := f.Readdirnames(n) fi = make([]FileInfo, len(names)) for i, filename := range names { fip, lerr := lstat(dirname + filename) if lerr != nil { fi[i] = &fileStat{name: filename} continue } fi[i] = fip } return fi, err The changes from Go 1.1.2 are stylistic, not semantic: 1. Use lstat instead of Lstat, for testing (done before this CL). 2. Make error handling in loop body look more like an error case. 3. Use separate error variable name in loop body, to be clear we are not trying to influence the final return result. Fixes #6656. Fixes #6680. R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/18870043 »»» R=golang-dev CC=golang-dev https://golang.org/cl/20110045
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The text was updated successfully, but these errors were encountered: