summaryrefslogtreecommitdiff
path: root/Remote/Helper/ChunkedEncryptable.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-07-26 23:26:10 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-07-26 23:26:10 -0400
commit748609e54c6bc6ca9d6ac68da04b8dd430416876 (patch)
tree127be7bfcaa82c00c85b093615f08a0f3c421380 /Remote/Helper/ChunkedEncryptable.hs
parent24c1d3fe0b720ad78399284a3645d0bb6dc15b0d (diff)
improve exception handling
Push it down from needing to be done in every Storer, to being checked once inside ChunkedEncryptable. Also, catch exceptions from PrepareStorer and PrepareRetriever, just in case..
Diffstat (limited to 'Remote/Helper/ChunkedEncryptable.hs')
-rw-r--r--Remote/Helper/ChunkedEncryptable.hs10
1 files changed, 8 insertions, 2 deletions
diff --git a/Remote/Helper/ChunkedEncryptable.hs b/Remote/Helper/ChunkedEncryptable.hs
index 740da58b9..cfa92406e 100644
--- a/Remote/Helper/ChunkedEncryptable.hs
+++ b/Remote/Helper/ChunkedEncryptable.hs
@@ -29,12 +29,15 @@ import Annex.Content
import Annex.Exception
-- Prepares to store a Key, and returns a Storer action if possible.
+-- May throw exceptions.
type PrepareStorer = Key -> Annex (Maybe Storer)
-- Stores a Key, which may be encrypted and/or a chunk key.
+-- May throw exceptions.
type Storer = Key -> L.ByteString -> MeterUpdate -> IO Bool
-- Prepares to retrieve a Key, and returns a Retriever action if possible.
+-- May throw exceptions.
type PrepareRetriever = Key -> Annex (Maybe Retriever)
-- Retrieves a Key, which may be encrypted and/or a chunk key.
@@ -68,8 +71,11 @@ chunkedEncryptableRemote c preparestorer prepareretriever r = encr
chunkconfig = chunkConfig c
gpgopts = getGpgEncParams encr
+ safely a = catchNonAsyncAnnex a (\e -> warning (show e) >> return False)
+
-- chunk, then encrypt, then feed to the storer
- storeKeyGen k p enc = maybe (return False) go =<< preparestorer k
+ storeKeyGen k p enc = safely $
+ maybe (return False) go =<< preparestorer k
where
go storer = sendAnnex k rollback $ \src ->
metered (Just p) k $ \p' ->
@@ -84,7 +90,7 @@ chunkedEncryptableRemote c preparestorer prepareretriever r = encr
storer (enck k') encb p'
-- call retriever to get chunks; decrypt them; stream to dest file
- retrieveKeyFileGen k dest p enc =
+ retrieveKeyFileGen k dest p enc = safely $
maybe (return False) go =<< prepareretriever k
where
go retriever = metered (Just p) k $ \p' ->