fix failure propigation

This commit is contained in:
Joey Hess 2010-10-25 19:17:11 -04:00
parent 47892ced88
commit e87287c11b
4 changed files with 27 additions and 13 deletions

View file

@ -42,21 +42,27 @@ type SubCmdPerform = Annex (Maybe SubCmdCleanup)
type SubCmdCleanup = Annex Bool type SubCmdCleanup = Annex Bool
{- Runs a subcommand through its three stages. -} {- Runs a subcommand through its three stages. -}
doSubCmd :: String -> SubCmdStart -> String -> Annex () doSubCmd :: String -> SubCmdStart -> String -> Annex Bool
doSubCmd cmdname start param = do doSubCmd cmdname start param = do
res <- start param :: Annex (Maybe SubCmdPerform) res <- start param :: Annex (Maybe SubCmdPerform)
case (res) of case (res) of
Nothing -> return () Nothing -> return True
Just perform -> do Just perform -> do
showStart cmdname param showStart cmdname param
res <- perform :: Annex (Maybe SubCmdCleanup) res <- perform :: Annex (Maybe SubCmdCleanup)
case (res) of case (res) of
Nothing -> showEndFail Nothing -> do
showEndFail
return False
Just cleanup -> do Just cleanup -> do
res <- cleanup res <- cleanup
if (res) if (res)
then showEndOk then do
else showEndFail showEndOk
return True
else do
showEndFail
return False
{- A subcommand can broadly want one of several kinds of input parameters. {- A subcommand can broadly want one of several kinds of input parameters.
@ -159,7 +165,7 @@ findWanted Keys params _ = return params
- run in the Annex monad. The first actions configure it - run in the Annex monad. The first actions configure it
- according to command line options, while the second actions - according to command line options, while the second actions
- handle subcommands. -} - handle subcommands. -}
parseCmd :: [String] -> AnnexState -> IO ([Annex ()], [Annex ()]) parseCmd :: [String] -> AnnexState -> IO ([Annex Bool], [Annex Bool])
parseCmd argv state = do parseCmd argv state = do
(flags, params) <- getopt (flags, params) <- getopt
if (null params) if (null params)
@ -169,8 +175,12 @@ parseCmd argv state = do
[Command name action want _] -> do [Command name action want _] -> do
f <- findWanted want (drop 1 params) f <- findWanted want (drop 1 params)
(TypeInternals.repo state) (TypeInternals.repo state)
return (flags, map (doSubCmd name action) $ let actions = map (doSubCmd name action) $
filter notstate f) filter notstate f
let configactions = map (\f -> do
f
return True) flags
return (configactions, actions)
where where
-- never include files from the state directory -- never include files from the state directory
notstate f = stateLoc /= take (length stateLoc) f notstate f = stateLoc /= take (length stateLoc) f

View file

@ -18,14 +18,15 @@ import qualified Annex
import Utility import Utility
{- Sets up a git repo for git-annex. -} {- Sets up a git repo for git-annex. -}
startup :: Annex () startup :: Annex Bool
startup = do startup = do
g <- Annex.gitRepo g <- Annex.gitRepo
liftIO $ gitAttributes g liftIO $ gitAttributes g
prepUUID prepUUID
return True
{- When git-annex is done, it runs this. -} {- When git-annex is done, it runs this. -}
shutdown :: Annex () shutdown :: Annex Bool
shutdown = do shutdown = do
g <- Annex.gitRepo g <- Annex.gitRepo
@ -38,6 +39,8 @@ shutdown = do
then liftIO $ removeDirectoryRecursive $ tmp then liftIO $ removeDirectoryRecursive $ tmp
else return () else return ()
return True
{- configure git to use union merge driver on state files, if it is not {- configure git to use union merge driver on state files, if it is not
- already -} - already -}
gitAttributes :: Git.Repo -> IO () gitAttributes :: Git.Repo -> IO ()

View file

@ -1,3 +1,3 @@
If a subcommand fails w/o throwing an error, no error is propigated to the If a subcommand fails w/o throwing an error, no error is propigated to the
git-annex exit code. With --quiet, this makes it look like the command git-annex exit code. With --quiet, this makes it look like the command
succeeded. succeeded. [[done]]

View file

@ -27,7 +27,7 @@ main = do
- or more likely I missed an easy way to do it. So, I have to laboriously - or more likely I missed an easy way to do it. So, I have to laboriously
- thread AnnexState through this function. - thread AnnexState through this function.
-} -}
tryRun :: AnnexState -> [Annex ()] -> IO () tryRun :: AnnexState -> [Annex Bool] -> IO ()
tryRun state actions = tryRun' state 0 actions tryRun state actions = tryRun' state 0 actions
tryRun' state errnum (a:as) = do tryRun' state errnum (a:as) = do
result <- try $ Annex.run state a result <- try $ Annex.run state a
@ -35,7 +35,8 @@ tryRun' state errnum (a:as) = do
Left err -> do Left err -> do
showErr err showErr err
tryRun' state (errnum + 1) as tryRun' state (errnum + 1) as
Right (_,state') -> tryRun' state' errnum as Right (True,state') -> tryRun' state' errnum as
Right (False,state') -> tryRun' state' (errnum + 1) as
tryRun' state errnum [] = do tryRun' state errnum [] = do
if (errnum > 0) if (errnum > 0)
then error $ (show errnum) ++ " failed" then error $ (show errnum) ++ " failed"