Commit graph

4 commits

Author SHA1 Message Date
Joey Hess
3e9807bc03
work around file-io not setting locale encoding when opening a Handle
Works around this bug https://github.com/haskell/file-io/issues/45

The fix is in Utility.FileIO.CloseOnExec because all use of file-io is
already wrapped through that module. Although perhaps that ought to be
refactored at this point.

I'd hope that file-io will eventually fix this bug, and also provide
CloseOnExec variants of its functions. That would allow depending on the
fixed version, and removing this ugly code.

Note that, functions like readFile that don't care about the encoding
due to reading/writing a ByteString were kept optimally fast by not
setting the encoding. This avoids an IORef read and write per open.

Sponsored-by: Graham Spencer
2025-09-15 19:25:03 -04:00
Joey Hess
38786a4e5e
noCreateProcessWhile to fix close-on-exec races
Sponsored-by: the NIH-funded NICEMAN (ReproNim TR&D3) project
2025-09-10 14:29:15 -04:00
Joey Hess
867110e9ee
add readFileString, writeFileString, appendFileString
Exported by Common, so they will be available everywhere.
These are the same as readFile, writeFile, appendFile.
But have two benefits:

* They take OsPath, so using them avoids converting back and forth
  unncessarily.
* They use the close-on-exec flag so can't leak FDs to child processes.
  Unlike the standard Haskell versions which unfortunately have that
  wart currently. (I do hope the standard versions get fixed
  eventually.)

Sponsored-by: the NIH-funded NICEMAN (ReproNim TR&D3) project
2025-09-05 14:54:36 -04:00
Joey Hess
c18581c356
Utility.FileIO: set close-on-exec flag for all functions
Utility.FileIO.CloseOnExec is largely copied from
System.File.OsPath.Internal with the simple modification of
setting the flag.

Unfortunately, openTempFile does not set the flag when
opening the file, but afterwards, leaving it vulnerable to a race.
A lot of code, including posix and windows specific code,
would need to be copied from file-io in order to fix that.
Still, I consider this implementation a placeholder, it doesn't truely
fix all instances of the problem.

I hope that this will be addressed in file-io itself, see
https://github.com/haskell/file-io/issues/44

Utility.FileIO.CloseOnExec could form the basis of a
file-io-closeonexec library, depending on how things go with that
issue.

Sponsored-by: the NIH-funded NICEMAN (ReproNim TR&D3) project
2025-09-05 13:36:50 -04:00