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

os: fix Windows (*os.File).Seek on directory handle #36019

Open
bradfitz opened this issue Dec 6, 2019 · 13 comments
Open

os: fix Windows (*os.File).Seek on directory handle #36019

bradfitz opened this issue Dec 6, 2019 · 13 comments

Comments

@bradfitz
Copy link
Member

@bradfitz bradfitz commented Dec 6, 2019

Half of our Windows builders (windows-386-2008, windows-amd64-2016, windows-amd64-longtest) fail to seek an *os.File opened on a directory.

But windows-amd64-2008 and windows-amd64-2012 work.

Figure this out and re-enable the test on Windows. (The test was added late in the Go 1.14 cycle, just before beta)

@bradfitz bradfitz added this to the Go1.15 milestone Dec 6, 2019
@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Dec 6, 2019

Change https://golang.org/cl/210283 mentions this issue: os: skip a new failing test on Windows

gopherbot pushed a commit that referenced this issue Dec 6, 2019
This test was recently added in CL 209961.

Apparently Windows can't seek a directory filehandle?

And move the test from test/fixedbugs (which is mostly for compiler bugs) to
an os package test.

Updates #36019

Change-Id: I626b69b0294471014901d0ccfeefe5e2c7651788
Reviewed-on: https://go-review.googlesource.com/c/go/+/210283
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
@networkimprov

This comment has been minimized.

Copy link

@networkimprov networkimprov commented Dec 11, 2019

@alexbrainman

This comment has been minimized.

Copy link
Member

@alexbrainman alexbrainman commented Dec 21, 2019

Go use FindFirstFile, FindNextFile and FindClose Windows API to implement directory reading. The API does not provide functionality to seek to random position of the directory. I don't know what the alternatives are, if any.

Alex

@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Jan 6, 2020

Change https://golang.org/cl/213439 mentions this issue: os: document that File.Seek works on directories, but not portably

gopherbot pushed a commit that referenced this issue Jan 6, 2020
Updates #36019

Change-Id: I9fea2c3c5138e2233290979e4724f6e7b91da652
Reviewed-on: https://go-review.googlesource.com/c/go/+/213439
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@networkimprov

This comment has been minimized.

Copy link

@networkimprov networkimprov commented Jan 6, 2020

Could File.Seek(0, os.SeekStart) be mapped to FindFirstFile() ?

@mattn

This comment has been minimized.

Copy link
Member

@mattn mattn commented Jan 7, 2020

man 3 fdopendir say:

fd is used internally by the implementation, and should not otherwise be used by the application.

https://linux.die.net/man/3/opendir

As far as I can see the doc, Go should not support Seek for directory.

@zx2c4

This comment has been minimized.

Copy link
Contributor

@zx2c4 zx2c4 commented Jan 7, 2020

NtQueryDirectoryFile may be of use.

@alexbrainman

This comment has been minimized.

Copy link
Member

@alexbrainman alexbrainman commented Jan 10, 2020

Could File.Seek(0, os.SeekStart) be mapped to FindFirstFile() ?

Yes. But people will still complain that File.Seel(1, os.SeekStart) fails. So, lets not pretend.

NtQueryDirectoryFile

Yes, it might work. But is all extra new code worth ability to File.Seek?

Alex

@networkimprov

This comment has been minimized.

Copy link

@networkimprov networkimprov commented Jan 10, 2020

Could File.Seek(0, os.SeekStart) be mapped to FindFirstFile() ?

Yes. But people will still complain that File.Seel(1, os.SeekStart) fails. So, lets not pretend.

Well you could FindNextFile() in a loop for i < seek_pos?

@alexbrainman

This comment has been minimized.

Copy link
Member

@alexbrainman alexbrainman commented Jan 10, 2020

Well you could FindNextFile() in a loop for i < seek_pos?

I don't understand what you are proposing. Please, send a CL with the change, if you know what to do.

Thank you.

Alex

@networkimprov

This comment was marked as off-topic.

Copy link

@networkimprov networkimprov commented Jan 10, 2020

I can't sign a copyright-transfer agreement, sorry. That's the only reason I don't make CLs.

func (f *File) Seek(pos int, from int) error {
   if is_directory(f) {
      if from != SeekStart { return &PathError{...} }
      FindFirstFile(...)
      for i := 0; i < pos; i++ {
         FindNextFile(...)
      }
   }
}
@alexbrainman

This comment was marked as off-topic.

Copy link
Member

@alexbrainman alexbrainman commented Jan 11, 2020

can't sign a copyright-transfer agreement, sorry. That's the only reason I don't make CLs.

Fair enough. Then I won't look at any of your code postings.

Alex

@networkimprov

This comment was marked as off-topic.

Copy link

@networkimprov networkimprov commented Jan 11, 2020

By that logic, you must check for the poster's CLA before reading any post about Go, whether or not it contains code. The relevant clause:

"Contribution" shall mean any original work of authorship, including any modifications or additions to an existing work, that is intentionally submitted by You to Google for inclusion in, or documentation of, any of the products owned or managed by Google (the "Work"). For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to Google or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, Google for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by You as "Not a Contribution."

From https://cla.developers.google.com/about/google-individual

cc @rsc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.