summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-08-02 15:34:09 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-08-02 15:34:09 -0400
commit0ddf8152ce1353bbbcd7c87c3f67063b4aed892b (patch)
tree766b35bcef4a38f424832ade2321f6d8db079b7a
parentd0a8e3d6217f2924b864393d425b6d7582370d07 (diff)
specialize Preparer a bit, so resourcePrepare can be added
The forall a. in Preparer made resourcePrepare not seem to be usable, so I specialized a to Bool. Which works for both Preparer Storer and Preparer Retriever, but wouldn't let the Preparer be used for hasKey as it currently stands.
-rw-r--r--Remote/Directory.hs1
-rw-r--r--Remote/Directory/LegacyChunked.hs2
-rw-r--r--Remote/Helper/ChunkedEncryptable.hs6
-rw-r--r--Types/StoreRetrieve.hs4
4 files changed, 7 insertions, 6 deletions
diff --git a/Remote/Directory.hs b/Remote/Directory.hs
index 37942a295..a87987529 100644
--- a/Remote/Directory.hs
+++ b/Remote/Directory.hs
@@ -6,7 +6,6 @@
-}
{-# LANGUAGE CPP #-}
-{-# LANGUAGE Rank2Types #-}
module Remote.Directory (remote) where
diff --git a/Remote/Directory/LegacyChunked.hs b/Remote/Directory/LegacyChunked.hs
index 312119f4e..5c200570c 100644
--- a/Remote/Directory/LegacyChunked.hs
+++ b/Remote/Directory/LegacyChunked.hs
@@ -7,8 +7,6 @@
- Licensed under the GNU GPL version 3 or higher.
-}
-{-# LANGUAGE Rank2Types #-}
-
module Remote.Directory.LegacyChunked where
import qualified Data.ByteString.Lazy as L
diff --git a/Remote/Helper/ChunkedEncryptable.hs b/Remote/Helper/ChunkedEncryptable.hs
index 2a844212b..1267f5b59 100644
--- a/Remote/Helper/ChunkedEncryptable.hs
+++ b/Remote/Helper/ChunkedEncryptable.hs
@@ -14,6 +14,7 @@ module Remote.Helper.ChunkedEncryptable (
simplyPrepare,
ContentSource,
checkPrepare,
+ resourcePrepare,
fileStorer,
byteStorer,
fileRetriever,
@@ -49,6 +50,11 @@ checkPrepare checker helper k a = ifM (checker k)
, a Nothing
)
+-- Use to acquire a resource when preparing a helper.
+resourcePrepare :: (Key -> (r -> Annex Bool) -> Annex Bool) -> (r -> helper) -> Preparer helper
+resourcePrepare withr helper k a = withr k $ \r ->
+ a (Just (helper r))
+
-- A Storer that expects to be provided with a file containing
-- the content of the key to store.
fileStorer :: (Key -> FilePath -> MeterUpdate -> Annex Bool) -> Storer
diff --git a/Types/StoreRetrieve.hs b/Types/StoreRetrieve.hs
index 33f66efb1..bde748960 100644
--- a/Types/StoreRetrieve.hs
+++ b/Types/StoreRetrieve.hs
@@ -5,8 +5,6 @@
- Licensed under the GNU GPL version 3 or higher.
-}
-{-# LANGUAGE Rank2Types #-}
-
module Types.StoreRetrieve where
import Common.Annex
@@ -16,7 +14,7 @@ import qualified Data.ByteString.Lazy as L
-- Prepares for and then runs an action that will act on a Key's
-- content, passing it a helper when the preparation is successful.
-type Preparer helper = forall a. Key -> (Maybe helper -> Annex a) -> Annex a
+type Preparer helper = Key -> (Maybe helper -> Annex Bool) -> Annex Bool
-- A source of a Key's content.
data ContentSource