Revision 710f5ae2 src/Ganeti/Utils.hs
b/src/Ganeti/Utils.hs | ||
---|---|---|
60 | 60 |
, resolveAddr |
61 | 61 |
, setOwnerAndGroupFromNames |
62 | 62 |
, formatOrdinal |
63 |
, atomicWriteFile |
|
63 | 64 |
) where |
64 | 65 |
|
65 | 66 |
import Data.Char (toUpper, isAlphaNum, isDigit, isSpace) |
... | ... | |
67 | 68 |
import Data.List |
68 | 69 |
import qualified Data.Map as M |
69 | 70 |
import Control.Monad (foldM) |
71 |
import System.Directory (renameFile) |
|
72 |
import System.FilePath.Posix (takeDirectory, takeBaseName) |
|
70 | 73 |
|
71 | 74 |
import Debug.Trace |
72 | 75 |
import Network.Socket |
... | ... | |
485 | 488 |
| otherwise = suffix "th" |
486 | 489 |
where tens = num `mod` 10 |
487 | 490 |
suffix s = show num ++ s |
491 |
|
|
492 |
-- | Atomically write a file, by first writing the contents into a temporary |
|
493 |
-- file and then renaming it to the old position. |
|
494 |
atomicWriteFile :: FilePath -> String -> IO () |
|
495 |
atomicWriteFile path contents = do |
|
496 |
(tmppath, tmphandle) <- openTempFile (takeDirectory path) (takeBaseName path) |
|
497 |
hPutStr tmphandle contents |
|
498 |
hClose tmphandle |
|
499 |
renameFile tmppath path |
Also available in: Unified diff