diff options
author | Joey Hess <joey@kitenet.net> | 2010-12-28 17:17:02 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2010-12-28 17:17:02 -0400 |
commit | aa4f91b2d67b9f7827b02acebfbf4e67ba33bb80 (patch) | |
tree | b81d1dea5915cc6aad1b9d0efc911fc1b9bbbe9a /Utility.hs | |
parent | 6c58a58393a1d6d2257cb9e72e534387561943d7 (diff) |
Add trust and untrust subcommands, to allow configuring remotes that are trusted to retain files without explicit checking.
Diffstat (limited to 'Utility.hs')
-rw-r--r-- | Utility.hs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/Utility.hs b/Utility.hs index 2447c95a0..3a6c75751 100644 --- a/Utility.hs +++ b/Utility.hs @@ -15,7 +15,8 @@ module Utility ( boolSystem, shellEscape, unsetFileMode, - readMaybe + readMaybe, + safeWriteFile ) where import System.IO @@ -139,3 +140,12 @@ readMaybe :: (Read a) => String -> Maybe a 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 + pid <- getProcessID + let tmpfile = file ++ ".tmp" ++ show pid + createDirectoryIfMissing True (parentDir file) + writeFile tmpfile content + renameFile tmpfile file |