diff options
author | Joey Hess <joey@kitenet.net> | 2011-11-10 20:24:24 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2011-11-10 20:57:28 -0400 |
commit | 49d2177d51b95b4a01c05ee07e166e93751b4c51 (patch) | |
tree | b818865e5a924dc90bf0a79608351b1aeffe458a /Remote/Bup.hs | |
parent | a71c03bc5162916853ff520d5c7c89e849c6a047 (diff) |
factored out some useful error catching methods
Diffstat (limited to 'Remote/Bup.hs')
-rw-r--r-- | Remote/Bup.hs | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/Remote/Bup.hs b/Remote/Bup.hs index 866d4b42d..4c826498d 100644 --- a/Remote/Bup.hs +++ b/Remote/Bup.hs @@ -110,21 +110,21 @@ storeEncrypted :: Git.Repo -> BupRepo -> (Cipher, Key) -> Key -> Annex Bool storeEncrypted r buprepo (cipher, enck) k = do src <- fromRepo $ gitAnnexLocation k params <- bupSplitParams r buprepo enck (Param "-") - liftIO $ catchBool $ + liftIO $ catchBoolIO $ withEncryptedHandle cipher (L.readFile src) $ \h -> pipeBup params (Just h) Nothing retrieve :: BupRepo -> Key -> FilePath -> Annex Bool retrieve buprepo k f = do let params = bupParams "join" buprepo [Param $ show k] - liftIO $ catchBool $ do + liftIO $ catchBoolIO $ do tofile <- openFile f WriteMode pipeBup params Nothing (Just tofile) retrieveEncrypted :: BupRepo -> (Cipher, Key) -> FilePath -> Annex Bool retrieveEncrypted buprepo (cipher, enck) f = do let params = bupParams "join" buprepo [Param $ show enck] - liftIO $ catchBool $ do + liftIO $ catchBoolIO $ do (pid, h) <- hPipeFrom "bup" $ toCommand params withDecryptedContent cipher (L.hGetContents h) $ L.writeFile f forceSuccess pid @@ -145,15 +145,12 @@ checkPresent r bupr k showAction $ "checking " ++ Git.repoDescribe r ok <- onBupRemote bupr boolSystem "git" params return $ Right ok - | otherwise = dispatch <$> localcheck + | otherwise = liftIO $ catchMsgIO $ + boolSystem "git" $ Git.gitCommandLine params bupr where params = [ Params "show-ref --quiet --verify" , Param $ "refs/heads/" ++ show k] - localcheck = liftIO $ try $ - boolSystem "git" $ Git.gitCommandLine params bupr - dispatch (Left e) = Left $ show e - dispatch (Right v) = Right v {- Store UUID in the annex.uuid setting of the bup repository. -} storeBupUUID :: UUID -> BupRepo -> Annex () |