summaryrefslogtreecommitdiff
path: root/Types/StoreRetrieve.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-07-29 18:40:40 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-07-29 18:41:41 -0400
commita2dfbf18972339929c49cb77e76cf246ada2acdc (patch)
treeb37fa5150d4a5c7ab76b58181fbd900157d915cb /Types/StoreRetrieve.hs
parente55bc5640997362f1f77a5423f7556b307377f61 (diff)
better type for Retriever
Putting a callback in the Retriever type allows for the callback to remove the retrieved file when it's done with it. I did not really want to make Retriever be fixed to Annex Bool, but when I tried to use Annex a, I got into some type of type mess.
Diffstat (limited to 'Types/StoreRetrieve.hs')
-rw-r--r--Types/StoreRetrieve.hs27
1 files changed, 4 insertions, 23 deletions
diff --git a/Types/StoreRetrieve.hs b/Types/StoreRetrieve.hs
index dfee20758..0ee2fd501 100644
--- a/Types/StoreRetrieve.hs
+++ b/Types/StoreRetrieve.hs
@@ -1,4 +1,4 @@
-{- Types for Storer and Retriever
+{- Types for Storer and Retriever actions for remotes.
-
- Copyright 2014 Joey Hess <joey@kitenet.net>
-
@@ -10,7 +10,6 @@
module Types.StoreRetrieve where
import Common.Annex
-import Annex.Content
import Utility.Metered
import qualified Data.ByteString.Lazy as L
@@ -28,25 +27,7 @@ data ContentSource
-- Can throw exceptions.
type Storer = Key -> ContentSource -> MeterUpdate -> Annex Bool
--- Action that retrieves a Key's content from a remote.
+-- Action that retrieves a Key's content from a remote, passing it to a
+-- callback.
-- Throws exception if key is not present, or remote is not accessible.
-type Retriever = Key -> MeterUpdate -> Annex ContentSource
-
-fileStorer :: (Key -> FilePath -> MeterUpdate -> Annex Bool) -> Storer
-fileStorer a k (FileContent f) m = a k f m
-fileStorer a k (ByteContent b) m = withTmp k $ \tmp -> do
- liftIO $ L.writeFile tmp b
- a k tmp m
-
-byteStorer :: (Key -> L.ByteString -> MeterUpdate -> Annex Bool) -> Storer
-byteStorer a k c m = withBytes c $ \b -> a k b m
-
-fileRetriever :: (Key -> MeterUpdate -> Annex FilePath) -> Retriever
-fileRetriever a k m = FileContent <$> a k m
-
-byteRetriever :: (Key -> Annex L.ByteString) -> Retriever
-byteRetriever a k _m = ByteContent <$> a k
-
-withBytes :: ContentSource -> (L.ByteString -> Annex a) -> Annex a
-withBytes (ByteContent b) a = a b
-withBytes (FileContent f) a = a =<< liftIO (L.readFile f)
+type Retriever = Key -> MeterUpdate -> (ContentSource -> Annex Bool) -> Annex Bool