better shutdown

This commit is contained in:
Joey Hess 2010-10-14 17:57:04 -04:00
parent 508a3b65ed
commit 467c4b2751
3 changed files with 43 additions and 37 deletions

57
Core.hs
View file

@ -11,34 +11,43 @@ import UUID
import qualified GitRepo as Git
import qualified Annex
{- Sets up a git repo for git-annex. May be called repeatedly. -}
gitSetup :: Annex ()
gitSetup = do
{- Sets up a git repo for git-annex. -}
setup :: Annex ()
setup = do
g <- Annex.gitRepo
liftIO $ setupattributes g
liftIO $ gitAttributes g
prepUUID
where
-- configure git to use union merge driver on state files
setupattributes repo = do
exists <- doesFileExist attributes
if (not exists)
{- When git-annex is done, it runs this. -}
shutdown :: Annex ()
shutdown = do
g <- Annex.gitRepo
liftIO $ Git.run g ["commit", "-m",
"git-annex log update", ".git-annex"]
{- configure git to use union merge driver on state files, if it is not
- already -}
gitAttributes :: Git.Repo -> IO ()
gitAttributes repo = do
exists <- doesFileExist attributes
if (not exists)
then do
writeFile attributes $ attrLine ++ "\n"
commit
else do
content <- readFile attributes
if (all (/= attrLine) (lines content))
then do
writeFile attributes $ attrLine ++ "\n"
appendFile attributes $ attrLine ++ "\n"
commit
else do
content <- readFile attributes
if (all (/= attrLine) (lines content))
then do
appendFile attributes $ attrLine ++ "\n"
commit
else return ()
where
attrLine = stateLoc ++ "/*.log merge=union"
attributes = Git.attributes repo
commit = do
Git.run repo ["add", attributes]
Git.run repo ["commit", "-m", "git-annex setup",
attributes]
else return ()
where
attrLine = stateLoc ++ "/*.log merge=union"
attributes = Git.attributes repo
commit = do
Git.run repo ["add", attributes]
Git.run repo ["commit", "-m", "git-annex setup",
attributes]
{- Checks if a given key is currently present in the annexLocation -}
inAnnex :: Backend -> Key -> Annex Bool