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

Support openTempFile and friends, fixes #2 #24

Merged
merged 10 commits into from
Aug 8, 2024
Merged

Support openTempFile and friends, fixes #2 #24

merged 10 commits into from
Aug 8, 2024

Conversation

hasufell
Copy link
Member

@hasufell hasufell commented Jul 21, 2024

Also see: haskell/directory#182

TODO:

  • windows

@Rufflewind

@hasufell hasufell marked this pull request as draft July 21, 2024 10:43
@hasufell hasufell requested a review from Bodigrim July 22, 2024 12:20
@hasufell hasufell marked this pull request as ready for review July 22, 2024 12:20
@hasufell hasufell requested a review from Bodigrim July 24, 2024 12:29
Copy link
Collaborator

@Bodigrim Bodigrim left a comment

Choose a reason for hiding this comment

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

LGTM, no idea what’s up with Windows CI job though.

@hasufell
Copy link
Member Author

LGTM, no idea what’s up with Windows CI job though.

It's suspicious. It also seems to be flaky.

@hasufell
Copy link
Member Author

hasufell commented Jul 25, 2024

@Rufflewind @Mistuke

Any idea why these concurrency tests would sometimes fail on windows?

https://github.com/hasufell/file-io/blob/a4a0464ccd38e8380c202949a90b21d9e592aeef/tests/Properties.hs#L109-L137

I can not reproduce in my windows VM.

@Rufflewind
Copy link
Member

_ <- OSP.openFile fp ReadMode

Is this intended to create a dangling handle? Genreally I would be a bit wary of writing a standalone statement in a garbage-collected language since there may or may not be a finalizer that releases the handle automatically if it goes unused.

Maybe someone familiar with the implementation details of hANDLEToHandle has a better idea of what's going on.

@Bodigrim
Copy link
Collaborator

Yeah, it might be worth to try something like

     !h <- OSP.openFile fp ReadMode 
     r <- try @IOException $ OSP.withFile fp WriteMode $ \h' -> do BS.hPut h' "test" 
     BS.hPut h "should have failed before"

@Mistuke
Copy link

Mistuke commented Aug 6, 2024

_ <- OSP.openFile fp ReadMode

Is this intended to create a dangling handle? Genreally I would be a bit wary of writing a standalone statement in a garbage-collected language since there may or may not be a finalizer that releases the handle automatically if it goes unused.

Maybe someone familiar with the implementation details of hANDLEToHandle has a better idea of what's going on.

We always add a finalizer to any handle you create. But the intention there is usually to make sure we don't leak resources. The RTS will invoke all finalizers before terminating. But when the finalizer run is non-deterministic. We only guarantee that it will run by the time you shutdown.

I think @Bodigrim 's solution is correct for the tests that check if the file is locked, and for the ones that check if you can read it you need >>= hClose.

@hasufell hasufell merged commit e07e089 into master Aug 8, 2024
16 of 17 checks passed
@hasufell
Copy link
Member Author

hasufell commented Aug 9, 2024

This is released as file-io-0.1.3.

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.

4 participants