diff options
author | Joey Hess <joey@kitenet.net> | 2011-06-30 00:42:09 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2011-06-30 00:46:39 -0400 |
commit | 2cda9d0a0fcdd1cc2aebc066ef19282fbe36e898 (patch) | |
tree | de4244439c340a664afd2993b7203ca8ac31e0cd /Utility.hs | |
parent | d72fb5acc28af3ea6380dd09518f7d1382dea8d2 (diff) |
generalized safeWriteFile to viaTmp
Diffstat (limited to 'Utility.hs')
-rw-r--r-- | Utility.hs | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/Utility.hs b/Utility.hs index 47d10ed75..7831a4ab4 100644 --- a/Utility.hs +++ b/Utility.hs @@ -22,7 +22,7 @@ module Utility ( shellUnEscape, unsetFileMode, readMaybe, - safeWriteFile, + viaTmp, dirContains, dirContents, myHomeDir, @@ -243,13 +243,14 @@ readMaybe s = case reads s of ((x,_):_) -> Just x _ -> Nothing -{- Writes a file using a temp file that is renamed atomically into place. -} -safeWriteFile :: FilePath -> String -> IO () -safeWriteFile file content = do +{- Runs an action like writeFile, writing to a tmp file first and + - then moving it into place. -} +viaTmp :: (FilePath -> String -> IO ()) -> FilePath -> String -> IO () +viaTmp a file content = do pid <- getProcessID let tmpfile = file ++ ".tmp" ++ show pid createDirectoryIfMissing True (parentDir file) - writeFile tmpfile content + a tmpfile content renameFile tmpfile file {- Lists the contents of a directory. |