module System.AtomicWrite.Writer.String.Binary (atomicWriteFile, atomicWithFile, atomicWriteFileWithMode, atomicWithFileAndMode) where
import System.AtomicWrite.Internal (closeAndRename, maybeSetFileMode,
tempFileFor)
import System.IO (Handle, hPutStr, hSetBinaryMode)
import System.Posix.Types (FileMode)
atomicWriteFile ::
FilePath
-> String
-> IO ()
atomicWriteFile :: FilePath -> FilePath -> IO ()
atomicWriteFile = (forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b c. (a -> b -> c) -> b -> a -> c
flip Handle -> FilePath -> IO ()
hPutStr) forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> (Handle -> IO ()) -> IO ()
atomicWithFile
atomicWriteFileWithMode ::
FileMode
-> FilePath
-> String
-> IO ()
atomicWriteFileWithMode :: FileMode -> FilePath -> FilePath -> IO ()
atomicWriteFileWithMode FileMode
mode = ( forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b c. (a -> b -> c) -> b -> a -> c
flip Handle -> FilePath -> IO ()
hPutStr)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FileMode -> FilePath -> (Handle -> IO ()) -> IO ()
atomicWithFileAndMode FileMode
mode
atomicWithFile :: FilePath -> (Handle -> IO ()) -> IO ()
atomicWithFile :: FilePath -> (Handle -> IO ()) -> IO ()
atomicWithFile = Maybe FileMode -> FilePath -> (Handle -> IO ()) -> IO ()
atomicWithFileAndMaybeMode forall a. Maybe a
Nothing
atomicWithFileAndMode :: FileMode
-> FilePath
-> (Handle -> IO ())
-> IO ()
atomicWithFileAndMode :: FileMode -> FilePath -> (Handle -> IO ()) -> IO ()
atomicWithFileAndMode = Maybe FileMode -> FilePath -> (Handle -> IO ()) -> IO ()
atomicWithFileAndMaybeMode forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> Maybe a
Just
atomicWithFileAndMaybeMode :: Maybe FileMode
-> FilePath
-> (Handle -> IO ())
-> IO ()
atomicWithFileAndMaybeMode :: Maybe FileMode -> FilePath -> (Handle -> IO ()) -> IO ()
atomicWithFileAndMaybeMode Maybe FileMode
mmode FilePath
path Handle -> IO ()
action =
FilePath -> IO (FilePath, Handle)
tempFileFor FilePath
path forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(FilePath
tmpPath, Handle
h) -> Handle -> Bool -> IO ()
hSetBinaryMode Handle
h Bool
True
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Handle -> IO ()
action Handle
h
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Handle -> FilePath -> FilePath -> IO ()
closeAndRename Handle
h FilePath
tmpPath FilePath
path
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FilePath -> Maybe FileMode -> IO ()
maybeSetFileMode FilePath
path Maybe FileMode
mmode