diff options
author | Joey Hess <joey@kitenet.net> | 2014-08-06 13:45:19 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2014-08-06 13:45:19 -0400 |
commit | cc2606ce542e04c22cf229d536ad621f9e25c12d (patch) | |
tree | 27601f447942bcefbfcb89c6588f330d7580098c /Remote/GCrypt.hs | |
parent | 5cd02fd1a52b3f1c19b01f4a021a7c63b96796dd (diff) |
pushed checkPresent exception handling out of Remote implementations
I tend to prefer moving toward explicit exception handling, not away from
it, but in this case, I think there are good reasons to let checkPresent
throw exceptions:
1. They can all be caught in one place (Remote.hasKey), and we know
every possible exception is caught there now, which we didn't before.
2. It simplified the code of the Remotes. I think it makes sense for
Remotes to be able to be implemented without needing to worry about
catching exceptions inside them. (Mostly.)
3. Types.StoreRetrieve.Preparer can only work on things that return a
Bool, which all the other relevant remote methods already did.
I do not see a good way to generalize that type; my previous attempts
failed miserably.
Diffstat (limited to 'Remote/GCrypt.hs')
-rw-r--r-- | Remote/GCrypt.hs | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/Remote/GCrypt.hs b/Remote/GCrypt.hs index d969e02f8..f971ff754 100644 --- a/Remote/GCrypt.hs +++ b/Remote/GCrypt.hs @@ -46,7 +46,6 @@ import Utility.Tmp import Logs.Remote import Logs.Transfer import Utility.Gpg -import Utility.FileMode remote :: RemoteType remote = RemoteType { @@ -109,8 +108,8 @@ gen' r u c gc = do , retrieveKeyFile = retreiveKeyFileDummy , retrieveKeyFileCheap = \_ _ -> return False , removeKey = remove this rsyncopts - , hasKey = checkPresent this rsyncopts - , hasKeyCheap = repoCheap r + , checkPresent = checkKey this rsyncopts + , checkPresentCheap = repoCheap r , whereisKey = Nothing , remoteFsck = Nothing , repairRepo = Nothing @@ -342,16 +341,15 @@ remove r rsyncopts k removersync = Remote.Rsync.remove rsyncopts k removeshell = Ssh.dropKey (repo r) k -checkPresent :: Remote -> Remote.Rsync.RsyncOpts -> Key -> Annex (Either String Bool) -checkPresent r rsyncopts k +checkKey :: Remote -> Remote.Rsync.RsyncOpts -> Key -> Annex Bool +checkKey r rsyncopts k | not $ Git.repoIsUrl (repo r) = guardUsable (repo r) (cantCheck $ repo r) $ - liftIO $ catchDefaultIO (cantCheck $ repo r) $ - Right <$> doesFileExist (gCryptLocation r k) + liftIO $ doesFileExist (gCryptLocation r k) | Git.repoIsSsh (repo r) = shellOrRsync r checkshell checkrsync | otherwise = unsupportedUrl where - checkrsync = Remote.Rsync.checkPresent (repo r) rsyncopts k + checkrsync = Remote.Rsync.checkKey (repo r) rsyncopts k checkshell = Ssh.inAnnex (repo r) k {- Annexed objects are hashed using lower-case directories for max |