diff options
author | Joey Hess <joey@kitenet.net> | 2014-08-03 01:12:24 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2014-08-03 01:12:24 -0400 |
commit | 237cceb715438809f9ddf7b45695f000f65f82b8 (patch) | |
tree | c6db0a6b1b79258fe0b85572640a69f6da837245 /Remote/Bup.hs | |
parent | a4a09a104747501f80ef93c4814e8dcf8bf51cb9 (diff) |
better byteRetriever
Make the byteRetriever be passed the callback that consumes the bytestring.
This way, there's no worries about the lazy bytestring not all being read
when the resource that's creating it is closed.
Which in turn lets bup, ddar, and S3 each switch from using an unncessary
fileRetriver to a byteRetriever. So, more efficient on chunks and encrypted
files.
The only remaining fileRetrievers are hook and external, which really do
retrieve to files.
Diffstat (limited to 'Remote/Bup.hs')
-rw-r--r-- | Remote/Bup.hs | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/Remote/Bup.hs b/Remote/Bup.hs index 06679c4b8..44ea8c7d8 100644 --- a/Remote/Bup.hs +++ b/Remote/Bup.hs @@ -8,6 +8,7 @@ module Remote.Bup (remote) where import qualified Data.Map as M +import qualified Data.ByteString.Lazy as L import Data.ByteString.Lazy.UTF8 (fromString) import Common.Annex @@ -127,12 +128,12 @@ store r buprepo = byteStorer $ \k b p -> do return True retrieve :: BupRepo -> Retriever -retrieve buprepo = fileRetriever $ \d k _p -> - liftIO $ withFile d WriteMode $ \h -> do - let params = bupParams "join" buprepo [Param $ bupRef k] - let p = proc "bup" (toCommand params) - (_, _, _, pid) <- createProcess $ p { std_out = UseHandle h } - forceSuccessProcess p pid +retrieve buprepo = byteRetriever $ \k sink -> do + let params = bupParams "join" buprepo [Param $ bupRef k] + let p = proc "bup" (toCommand params) + (_, Just h, _, pid) <- liftIO $ createProcess $ p { std_out = CreatePipe } + liftIO (hClose h >> forceSuccessProcess p pid) + `after` (sink =<< liftIO (L.hGetContents h)) retrieveCheap :: BupRepo -> Key -> FilePath -> Annex Bool retrieveCheap _ _ _ = return False |