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
Sys.readdir
on MingW Windows disagrees with Linux behavior
#11829
Comments
Thanks for the report! Just to add that this appears to be native-Windows-specific, rather than OCaml 5 only. It's the same for both the 4.11 mingw-w64 and msvc64 compilers I had lying around on my machine. |
Many thanks for having reported this issue, @Lucccyo. In my understanding, the behaviour you obseve comes from
Basically, if the preceeding call to However, this has always been so since |
I'm sure this can be fixed in no more than 50 lines of Win32 incantations, but I'll let others give it a try. |
Xavier Leroy (2022/12/21 03:21 -0800):
> I don't understand what's the reason why we return 0 rather than -1 when errno == ENOENT?
`_wfindfirst` fails with ENOENT if the directory is empty. (Indeed,
there is no first entry in this case.) That's why 0 is returned.
Now, it could be that it also fails with ENOENT if the directory
doesn't exist...
Ah. For those interested, the documentation is at
`https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/findfirst-functions?view=msvc-170`.
I'm sure this can be fixed in no more than 50 lines of Win32
incantations, but I'll let others give it a try.
|
Can we, in the case of |
Given that you have tested, do you feel brave enough to submit a PR?
I am wondering whether adding `*.*` even in the first call is (still)
necessary?
|
The replies to all your questions are in MSDN. You'll see that bad APIs never die. |
I can give it a try :) |
Charlène_Gros (2022/12/22 01:31 -0800):
> Given that you have tested, do you feel brave enough to submit a PR?
I can give it a try :)
Cool! Go ahead and I'll make sure to be participating in the review!
|
We did a couple of tests with @tertium, and we're unsure what is the correct way of handling this, any comments are welcome. The idea was to replace the line
That is, if the first call to It turns out, however, that this test is useless. Indeed, there is no such thing as "empty directory", because At this stage, I'm inclined to suggest a much simpler fix: whenever |
Oh! Excellent point! If that's indeed the case, your simpler fix is perfect, let's implement this ASAP. |
I'm afraid there are empty directories - root directories are capable of being empty. It's irritatingly inconsitent: despite the fact that |
While I wrote multicore tests of Sys module that run on Linux, macOS, and Windows CI,
I discovered that Sys.readdir doesn't behave the same on Linux or macOS as on MingW Windows.
Running the command on a Windows OCaml top-level using OCaml 5.0.0:
We get back a string array empty instead of raising a Sys.error complaining of an unfound directory.
The text was updated successfully, but these errors were encountered: