Use both mktemp
and mktempfile
I added back the old `mktemp` behavior and split off the new behavior as the `mktempfile` function. This avoids a breaking API change and also lets users choose how much convenience/safety they want.
This commit is contained in:
parent
5862c005fb
commit
9bfb25fe86
1 changed files with 24 additions and 1 deletions
|
@ -148,6 +148,7 @@ module Turtle.Prelude (
|
|||
, writeonly
|
||||
, appendonly
|
||||
, mktemp
|
||||
, mktempfile
|
||||
, mktempdir
|
||||
, fork
|
||||
, wait
|
||||
|
@ -881,14 +882,36 @@ mktempdir parent prefix = do
|
|||
{-| Create a temporary file underneath the given directory
|
||||
|
||||
Deletes the temporary file when done
|
||||
|
||||
Note that this provides the `Handle` of the file in order to avoid a
|
||||
potential race condition from the file being moved or deleted before you
|
||||
have a chance to open the file. The `mktempfile` function provides a
|
||||
simpler API if you don't need to worry about that possibility.
|
||||
-}
|
||||
mktemp
|
||||
:: FilePath
|
||||
-- ^ Parent directory
|
||||
-> Text
|
||||
-- ^ File name template
|
||||
-> Managed FilePath
|
||||
-> Managed (FilePath, Handle)
|
||||
mktemp parent prefix = do
|
||||
let parent' = Filesystem.encodeString parent
|
||||
let prefix' = unpack prefix
|
||||
(file', handle) <- managed (\k ->
|
||||
withTempFile parent' prefix' (\file' handle -> k (file', handle)) )
|
||||
return (Filesystem.decodeString file', handle)
|
||||
|
||||
{-| Create a temporary file underneath the given directory
|
||||
|
||||
Deletes the temporary file when done
|
||||
-}
|
||||
mktempfile
|
||||
:: FilePath
|
||||
-- ^ Parent directory
|
||||
-> Text
|
||||
-- ^ File name template
|
||||
-> Managed FilePath
|
||||
mktempfile parent prefix = do
|
||||
let parent' = Filesystem.encodeString parent
|
||||
let prefix' = unpack prefix
|
||||
(file', handle) <- managed (\k ->
|
||||
|
|
Loading…
Reference in a new issue