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

Handle non-ASCII filenames correctly on Windows #91

Merged
merged 5 commits into from
Aug 31, 2016

Conversation

Blaisorblade
Copy link
Contributor

@Blaisorblade Blaisorblade commented Aug 14, 2016

Not yet finished, but I've confirmed this code fixes the bug on Windows. EDIT: at least with GHC 7.10.3. I'll add a test and rebase.

Fix snoyberg#90. Idea: reuse low-level API from GHC internals, since it has
already tested low-level code to deal with non-ASCII filenames on
different platforms.
A null file pointer doesn't need closing; `fclose_helper` will indeed do
nothing on a null pointer.
I've ensured both parts of the test fail without the changes.

To ensure the whole test fails without the fixes, accented characters
must be in the path argument, not just in the current working directory.
@Blaisorblade
Copy link
Contributor Author

This PR is now ready for review, though on Windows I only tested on GHC 7.10.3 (with LTS-3 with relaxed version checks and LTS-6).

-- indicated via both 'rawOpenFlags' and 'openMode'.
openFile :: FilePath -> CInt -> String -> IO File
openFile file rawOpenFlags openMode = do
fd <- liftIO $ Posix.withFilePath file $ \file' ->
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised that such a large change is needed. Is it insufficient to simply replace withCString with Posix.withFilePath and leave the rest of the code the same as it was before?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC from two weeks ago, the first problem is that fopen doesn't do the right thing on Windows, because it takes normal characters instead of wide ones. This might be wrong, but I remember solving this by hand looked non trivial.
Instead, this code simply reuses the existing tested solution in GHC's libraries, which happens to provide a variant of open instead of fopen. To wit, as soon as this worked on Mac, it worked on Windows.
I look into it again if you want for more accurate details, but not tonight.
Also, sorry for the delay in replying, forgot y this email.

@snoyberg
Copy link
Owner

Sorry for the delay here, vacation definitely intervened.

I'm going to start by setting up appveyor so we can get some Windows testing going on this.

@snoyberg
Copy link
Owner

OK, I can confirm that due to wide characters the simple approach I mentioned does not work.

@snoyberg snoyberg merged commit 5c2b6b2 into snoyberg:master Aug 31, 2016
@snoyberg
Copy link
Owner

I'll release to Hackage once the AppVeyor and Travis builds succeed.

@Blaisorblade Blaisorblade deleted the 90-safe-intl-filename branch September 5, 2016 19:44
@Blaisorblade
Copy link
Contributor Author

Thanks for the merge... and apologies for kicking this hornet's nest (#92, #94, #95...).

@snoyberg
Copy link
Owner

snoyberg commented Sep 6, 2016

I'm honestly blown away that you seem to have been the first person to
trigger this bug in Hackage, cabal-install, and Stack. Well done :)

On Mon, Sep 5, 2016 at 10:46 PM Paolo G. Giarrusso notifications@github.com
wrote:

Thanks for the merge... and apologies for kicking this hornet's nest (#92
#92, #94
#94, #95
#95...).


You are receiving this because you modified the open/close state.

Reply to this email directly, view it on GitHub
#91 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AADBBxHHX3KkzJrpYEwyU6XjTW4PcaOAks5qnHGFgaJpZM4Jj9Yg
.

snoyberg added a commit to commercialhaskell/stack that referenced this pull request Nov 20, 2016
This has been fixed upstream, see:
snoyberg/yaml#91
snoyberg added a commit to commercialhaskell/stack that referenced this pull request Nov 20, 2016
This has been fixed upstream, see:
snoyberg/yaml#91
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants