-
Notifications
You must be signed in to change notification settings - Fork 17.5k
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: Seek suceeds for directories where it should error #45046
Comments
As far as I know this is working as intended. Seeking in a directory can be meaningful. In particular you can call Is there a particular reason that |
Here’s a corrected test program, I missed the https://play.golang.org/p/INPumuqPZ-V Seek-ing in directories on Unix used to fail:
I’ve got no objections to keeping the current behaviour, but I can see nothing in the changes that cleared |
Also while Seek can be meaningful at a system call level, I don’t see how it can be meaningful at a Go level. The dir_unix.go code buffers a full 8KiB of directory information on each read. If you tried to use Seek to remember a position, you’d always end up at the end of one of those 8KiB blocks, if I’m not mistaken, not immediately after the directory entry you’d just read as you’d expect. |
Fair enough. I hadn't realized that this failed in earlier releases. Looks like this changed in https://golang.org/cl/219143. See #35767 and #37161. The tests cases for those issues involve seeking to position 0, which has always been permitted. But, as you said, that CL changed the code so that the check to return Interestingly, returning I'm not quite sure what behavior we should enforce going forward. CC @randall77 |
I think we want Practically speaking, we can change the order of the tests in Quoting myself from CL 209961:
|
Historically we've only permitted the case where the result of the |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes with tip.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I was looking through the os directory reading source code and I noticed that
Seek
s EISDIR error condition is broken.Seek
checks if the os-specificseek
method succeeded for a file that has adirinfo
:go/src/os/file.go
Lines 239 to 241 in f02a26b
Unfortunately the
seek
method always clearsdirinfo
(#35767 and #37161):go/src/os/file_unix.go
Lines 269 to 274 in 78f9015
This script should reproduce the error when run locally:
https://play.golang.org/p/brgpk5je9tP
As an aside: I'm not sure this is the best way handle
Seek
-ing a directory, it will only trigger ifreaddir
was previously called and, on Linux at least, only after the seek has actually succeeded.What did you expect to see?
Seek
returned asyscall.EISDIR
error.What did you see instead?
Seek
returned without error.The text was updated successfully, but these errors were encountered: