use safewritefile
This commit is contained in:
parent
4f9336bb60
commit
04fe906ac6
4 changed files with 7 additions and 11 deletions
|
@ -20,6 +20,7 @@ import Version
|
||||||
import Messages
|
import Messages
|
||||||
import Locations
|
import Locations
|
||||||
import Types
|
import Types
|
||||||
|
import Utility
|
||||||
|
|
||||||
command :: [Command]
|
command :: [Command]
|
||||||
command = [Command "init" paramDesc seek
|
command = [Command "init" paramDesc seek
|
||||||
|
@ -61,7 +62,7 @@ gitAttributesWrite repo = do
|
||||||
exists <- doesFileExist attributes
|
exists <- doesFileExist attributes
|
||||||
if not exists
|
if not exists
|
||||||
then do
|
then do
|
||||||
writeFile attributes $ attrLine ++ "\n"
|
safeWriteFile attributes $ attrLine ++ "\n"
|
||||||
commit
|
commit
|
||||||
else do
|
else do
|
||||||
content <- readFile attributes
|
content <- readFile attributes
|
||||||
|
@ -85,7 +86,7 @@ gitPreCommitHookWrite repo = do
|
||||||
if exists
|
if exists
|
||||||
then warning $ "pre-commit hook (" ++ hook ++ ") already exists, not configuring"
|
then warning $ "pre-commit hook (" ++ hook ++ ") already exists, not configuring"
|
||||||
else liftIO $ do
|
else liftIO $ do
|
||||||
writeFile hook preCommitScript
|
safeWriteFile hook preCommitScript
|
||||||
p <- getPermissions hook
|
p <- getPermissions hook
|
||||||
setPermissions hook $ p {executable = True}
|
setPermissions hook $ p {executable = True}
|
||||||
where
|
where
|
||||||
|
|
|
@ -59,5 +59,5 @@ gitAttributesUnWrite repo = do
|
||||||
attrexists <- doesFileExist attributes
|
attrexists <- doesFileExist attributes
|
||||||
when attrexists $ do
|
when attrexists $ do
|
||||||
c <- readFileStrict attributes
|
c <- readFileStrict attributes
|
||||||
writeFile attributes $ unlines $
|
safeWriteFile attributes $ unlines $
|
||||||
filter (/= Command.Init.attrLine) $ lines c
|
filter (/= Command.Init.attrLine) $ lines c
|
||||||
|
|
|
@ -16,6 +16,7 @@ import Types
|
||||||
import Content
|
import Content
|
||||||
import Messages
|
import Messages
|
||||||
import Locations
|
import Locations
|
||||||
|
import Utility
|
||||||
import qualified Annex
|
import qualified Annex
|
||||||
import qualified GitRepo as Git
|
import qualified GitRepo as Git
|
||||||
import qualified Backend
|
import qualified Backend
|
||||||
|
@ -43,7 +44,7 @@ checkUnused = do
|
||||||
unused <- unusedKeys
|
unused <- unusedKeys
|
||||||
let list = number 1 unused
|
let list = number 1 unused
|
||||||
g <- Annex.gitRepo
|
g <- Annex.gitRepo
|
||||||
liftIO $ writeFile (gitAnnexUnusedLog g) $ unlines $
|
liftIO $ safeWriteFile (gitAnnexUnusedLog g) $ unlines $
|
||||||
map (\(n, k) -> show n ++ " " ++ show k) list
|
map (\(n, k) -> show n ++ " " ++ show k) list
|
||||||
if null unused
|
if null unused
|
||||||
then return True
|
then return True
|
||||||
|
|
|
@ -32,7 +32,6 @@ import Data.Time
|
||||||
import System.Locale
|
import System.Locale
|
||||||
import qualified Data.Map as Map
|
import qualified Data.Map as Map
|
||||||
import System.Directory
|
import System.Directory
|
||||||
import System.Posix.Process
|
|
||||||
import Control.Monad (when)
|
import Control.Monad (when)
|
||||||
|
|
||||||
import qualified GitRepo as Git
|
import qualified GitRepo as Git
|
||||||
|
@ -112,12 +111,7 @@ readLog file = do
|
||||||
|
|
||||||
{- Writes a set of lines to a log file -}
|
{- Writes a set of lines to a log file -}
|
||||||
writeLog :: FilePath -> [LogLine] -> IO ()
|
writeLog :: FilePath -> [LogLine] -> IO ()
|
||||||
writeLog file ls = do
|
writeLog file ls = safeWriteFile file (unlines $ map show ls)
|
||||||
pid <- getProcessID
|
|
||||||
let tmpfile = file ++ ".tmp" ++ show pid
|
|
||||||
createDirectoryIfMissing True (parentDir file)
|
|
||||||
writeFile tmpfile $ unlines $ map show ls
|
|
||||||
renameFile tmpfile file
|
|
||||||
|
|
||||||
{- Generates a new LogLine with the current date. -}
|
{- Generates a new LogLine with the current date. -}
|
||||||
logNow :: LogStatus -> UUID -> IO LogLine
|
logNow :: LogStatus -> UUID -> IO LogLine
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue