factored out some useful error catching methods

This commit is contained in:
Joey Hess 2011-11-10 20:24:24 -04:00
parent a71c03bc51
commit 49d2177d51
15 changed files with 54 additions and 61 deletions

View file

@ -8,7 +8,6 @@
module Remote.Directory (remote) where
import qualified Data.ByteString.Lazy.Char8 as L
import System.IO.Error
import qualified Data.Map as M
import Common.Annex
@ -72,13 +71,13 @@ store :: FilePath -> Key -> Annex Bool
store d k = do
src <- fromRepo $ gitAnnexLocation k
let dest = dirKey d k
liftIO $ catchBool $ storeHelper dest $ copyFileExternal src dest
liftIO $ catchBoolIO $ storeHelper dest $ copyFileExternal src dest
storeEncrypted :: FilePath -> (Cipher, Key) -> Key -> Annex Bool
storeEncrypted d (cipher, enck) k = do
src <- fromRepo $ gitAnnexLocation k
let dest = dirKey d enck
liftIO $ catchBool $ storeHelper dest $ encrypt src dest
liftIO $ catchBoolIO $ storeHelper dest $ encrypt src dest
where
encrypt src dest = do
withEncryptedContent cipher (L.readFile src) $ L.writeFile dest
@ -100,12 +99,12 @@ retrieve d k f = liftIO $ copyFileExternal (dirKey d k) f
retrieveEncrypted :: FilePath -> (Cipher, Key) -> FilePath -> Annex Bool
retrieveEncrypted d (cipher, enck) f =
liftIO $ catchBool $ do
liftIO $ catchBoolIO $ do
withDecryptedContent cipher (L.readFile (dirKey d enck)) $ L.writeFile f
return True
remove :: FilePath -> Key -> Annex Bool
remove d k = liftIO $ catchBool $ do
remove d k = liftIO $ catchBoolIO $ do
allowWrite dir
removeFile file
removeDirectory dir
@ -115,8 +114,4 @@ remove d k = liftIO $ catchBool $ do
dir = parentDir file
checkPresent :: FilePath -> Key -> Annex (Either String Bool)
checkPresent d k = dispatch <$> check
where
check = liftIO $ try $ doesFileExist (dirKey d k)
dispatch (Left e) = Left $ show e
dispatch (Right v) = Right v
checkPresent d k = liftIO $ catchMsgIO $ doesFileExist (dirKey d k)