Commit graph

8 commits

Author SHA1 Message Date
Joey Hess
d3567cdc47
fix conversions to withFile
33bb14339a accidentially used withFile',
which is for lazy IO and does not close the handle. That broke the test
suite.

Sponsored-by: Kevin Mueller
2026-02-02 11:12:42 -04:00
Joey Hess
33bb14339a
remove file-io locale encoding bug workaround
https://github.com/haskell/file-io/issues/45
Fixed in file-io 0.2.0. Went ahead and made that version be required for
the OsPath build flag to avoid ifdefs. Since it's behind that build flag,
builds with older versions of file-io will keep working, by auto-disabling
the build flag.

Note that this loses the withFileNoEncoding optimisation when opening a
file only to perform ByteString IO on it. That is probably too minor an
optimisation to worry about, since it only involves avoiding an IORef
read/write or such.

Sponsored-by: Nicholas Golder-Manning
2026-01-30 12:15:17 -04:00
Joey Hess
d02a217c48
file-io 0.2.0 openTempFile' supports setting close-on-exec
This makes for a cleaner implementation, which is also better because it
does not stall process creation while creating temp files.

Left an ifdef, since on unix, older versions of file-io are still
supported, for now.

Sponsored-by: Nicholas Golder-Manning
2026-01-30 11:52:16 -04:00
Joey Hess
026bab0c49
don't set locale encoding when opening binary file
importfeed: Fix encoding issues parsing feeds when built with OsPath.
2025-09-29 11:06:18 -04:00
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