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.
This commit is contained in:
parent
19b71cfb8f
commit
d05b7b9182
8 changed files with 44 additions and 42 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue