summaryrefslogtreecommitdiff
path: root/Utility/CoProcess.hs
diff options
context:
space:
mode:
authorJoey Hess <joey@kitenet.net>2014-01-13 18:10:21 -0400
committerJoey Hess <joey@kitenet.net>2014-01-13 18:10:21 -0400
commit14ce1badd4210ebb2660e0fb22ba4ff7f2986dee (patch)
treea0eb1548d7d879631cef51266e8f2ee65fa7a66f /Utility/CoProcess.hs
parentdd1d8e69d4c190c7bb60d5187f7a889c6fea0d62 (diff)
downloadgit-repair-14ce1badd4210ebb2660e0fb22ba4ff7f2986dee.tar.gz
merge from git-annex
Diffstat (limited to 'Utility/CoProcess.hs')
-rw-r--r--Utility/CoProcess.hs13
1 files changed, 7 insertions, 6 deletions
diff --git a/Utility/CoProcess.hs b/Utility/CoProcess.hs
index 710d2af..c113401 100644
--- a/Utility/CoProcess.hs
+++ b/Utility/CoProcess.hs
@@ -30,15 +30,15 @@ data CoProcessState = CoProcessState
}
data CoProcessSpec = CoProcessSpec
- { coProcessRestartable :: Bool
+ { coProcessNumRestarts :: Int
, coProcessCmd :: FilePath
, coProcessParams :: [String]
, coProcessEnv :: Maybe [(String, String)]
}
-start :: Bool -> FilePath -> [String] -> Maybe [(String, String)] -> IO CoProcessHandle
-start restartable cmd params env = do
- s <- start' $ CoProcessSpec restartable cmd params env
+start :: Int -> FilePath -> [String] -> Maybe [(String, String)] -> IO CoProcessHandle
+start numrestarts cmd params env = do
+ s <- start' $ CoProcessSpec numrestarts cmd params env
newMVar s
start' :: CoProcessSpec -> IO CoProcessState
@@ -66,7 +66,7 @@ query ch send receive = do
return
where
restartable s a cont
- | coProcessRestartable (coProcessSpec s) =
+ | coProcessNumRestarts (coProcessSpec s) > 0 =
maybe restart cont =<< catchMaybeIO a
| otherwise = cont =<< a
restart = do
@@ -75,7 +75,8 @@ query ch send receive = do
hClose $ coProcessTo s
hClose $ coProcessFrom s
void $ waitForProcess $ coProcessPid s
- s' <- start' (coProcessSpec s)
+ s' <- start' $ (coProcessSpec s)
+ { coProcessNumRestarts = coProcessNumRestarts (coProcessSpec s) - 1 }
putMVar ch s'
query ch send receive