aboutsummaryrefslogtreecommitdiff
path: root/Remote/Ddar.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-08-03 01:12:24 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-08-03 01:12:24 -0400
commit237cceb715438809f9ddf7b45695f000f65f82b8 (patch)
treec6db0a6b1b79258fe0b85572640a69f6da837245 /Remote/Ddar.hs
parenta4a09a104747501f80ef93c4814e8dcf8bf51cb9 (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/Ddar.hs')
-rw-r--r--Remote/Ddar.hs12
1 files changed, 6 insertions, 6 deletions
diff --git a/Remote/Ddar.hs b/Remote/Ddar.hs
index 365506a22..bc4755a81 100644
--- a/Remote/Ddar.hs
+++ b/Remote/Ddar.hs
@@ -10,8 +10,8 @@ module Remote.Ddar (remote) where
import Control.Exception
import qualified Data.Map as M
+import qualified Data.ByteString.Lazy as L
import System.IO.Error
-import System.Process
import Data.String.Utils
import Common.Annex
@@ -127,12 +127,12 @@ ddarExtractRemoteCall ddarrepo k =
ddarRemoteCall ddarrepo 'x' [Param "--force-stdout", Param $ key2file k]
retrieve :: DdarRepo -> Retriever
-retrieve ddarrepo = fileRetriever $ \d k _p -> do
+retrieve ddarrepo = byteRetriever $ \k sink -> do
(cmd, params) <- ddarExtractRemoteCall ddarrepo k
- liftIO $ withFile d WriteMode $ \h -> do
- let p = (proc cmd $ toCommand params){ std_out = UseHandle h }
- (_, _, _, pid) <- Common.Annex.createProcess p
- forceSuccessProcess p pid
+ let p = (proc cmd $ toCommand params) { std_out = CreatePipe }
+ (_, Just h, _, pid) <- liftIO $ createProcess p
+ liftIO (hClose h >> forceSuccessProcess p pid)
+ `after` (sink =<< liftIO (L.hGetContents h))
retrieveCheap :: Key -> FilePath -> Annex Bool
retrieveCheap _ _ = return False