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

readFile creates new files on Windows #14

Closed
Bodigrim opened this issue Jan 11, 2024 · 4 comments
Closed

readFile creates new files on Windows #14

Bodigrim opened this issue Jan 11, 2024 · 4 comments

Comments

@Bodigrim
Copy link
Collaborator

Win 10, GHC 9.6.3:

$ cabal repl -b file-io 
ghci> :set -XQuasiQuotes
ghci> System.File.OsPath.readFile [System.OsPath.osp|does-not-exist|]
""

What's worse is that readFile also creates an empty does-not-exist file.

@hasufell
Copy link
Member

Ouch.

We're using the Win32 API proper, which is a bit peculiar.

I'll look at it this weekend.

@hasufell
Copy link
Member

From a quick glance it seems I was tricked by the posix functions behaving in a certain way:

  • openFile by design creates a missing file for every IOMode except ReadOnly
  • openExistingFile never creates the file
  • we use openFile through withFile

The solution seems to be to use openExistingFile for all read operations. On posix it doesn't matter, on windows it does.

@hasufell
Copy link
Member

hasufell added a commit that referenced this issue Jan 12, 2024
@hasufell
Copy link
Member

This is fixed here: 9436ee8

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

No branches or pull requests

2 participants