diff options
author | Joey Hess <joey@kitenet.net> | 2014-07-29 16:22:19 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2014-07-29 16:28:44 -0400 |
commit | 99e69a42d1afc02c381657e82547dfcc9f2a6ae2 (patch) | |
tree | e38a15038aa62dfdad0873bc3b4b874d5e0f254e /Types | |
parent | 48674a62c7d1fb9932c2bd234e6f851ec75478ac (diff) |
lift types from IO to Annex
Some remotes like External need to run store and retrieve actions in Annex,
not IO. In order to do that lift, I had to dive pretty deep into the
utilities, making Utility.Gpg and Utility.Tmp be partly converted to using
MonadIO, and Control.Monad.Catch for exception handling.
There should be no behavior changes in this commit.
This commit was sponsored by Michael Barabanov.
Diffstat (limited to 'Types')
-rw-r--r-- | Types/StoreRetrieve.hs | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/Types/StoreRetrieve.hs b/Types/StoreRetrieve.hs index 2520d6309..ccbf99e3f 100644 --- a/Types/StoreRetrieve.hs +++ b/Types/StoreRetrieve.hs @@ -26,29 +26,29 @@ data ContentSource -- Action that stores a Key's content on a remote. -- Can throw exceptions. -type Storer = Key -> ContentSource -> MeterUpdate -> IO Bool +type Storer = Key -> ContentSource -> MeterUpdate -> Annex Bool -- Action that retrieves a Key's content from a remote. -- Throws exception if key is not present, or remote is not accessible. -type Retriever = Key -> IO ContentSource +type Retriever = Key -> Annex ContentSource -fileStorer :: (Key -> FilePath -> MeterUpdate -> IO Bool) -> Storer +fileStorer :: (Key -> FilePath -> MeterUpdate -> Annex Bool) -> Storer fileStorer a k (FileContent f) m = a k f m -fileStorer a k (ByteContent b) m = do - withTmpFile "tmpXXXXXX" $ \f h -> do +fileStorer a k (ByteContent b) m = withTmpFile "tmpXXXXXX" $ \f h -> do + liftIO $ do L.hPut h b hClose h - a k f m + a k f m -byteStorer :: (Key -> L.ByteString -> MeterUpdate -> IO Bool) -> Storer +byteStorer :: (Key -> L.ByteString -> MeterUpdate -> Annex Bool) -> Storer byteStorer a k c m = withBytes c $ \b -> a k b m -withBytes :: ContentSource -> (L.ByteString -> IO a) -> IO a +withBytes :: ContentSource -> (L.ByteString -> Annex a) -> Annex a withBytes (ByteContent b) a = a b -withBytes (FileContent f) a = a =<< L.readFile f +withBytes (FileContent f) a = a =<< liftIO (L.readFile f) -fileRetriever :: (Key -> IO FilePath) -> Retriever +fileRetriever :: (Key -> Annex FilePath) -> Retriever fileRetriever a k = FileContent <$> a k -byteRetriever :: (Key -> IO L.ByteString) -> Retriever +byteRetriever :: (Key -> Annex L.ByteString) -> Retriever byteRetriever a k = ByteContent <$> a k |