fix cleanup of FileContents once done when them when retrieving
This commit is contained in:
parent
53b87a859e
commit
444944c7a9
1 changed files with 17 additions and 11 deletions
|
@ -65,20 +65,15 @@ byteStorer a k c m = withBytes c $ \b -> a k b m
|
||||||
-- A Retriever that writes the content of a Key to a provided file.
|
-- A Retriever that writes the content of a Key to a provided file.
|
||||||
-- It is responsible for updating the progress meter as it retrieves data.
|
-- It is responsible for updating the progress meter as it retrieves data.
|
||||||
fileRetriever :: (FilePath -> Key -> MeterUpdate -> Annex ()) -> Retriever
|
fileRetriever :: (FilePath -> Key -> MeterUpdate -> Annex ()) -> Retriever
|
||||||
fileRetriever a k m callback = bracketAnnex (prepTmp k) (liftIO . nukeFile) go
|
fileRetriever a k m callback = do
|
||||||
where
|
f <- prepTmp k
|
||||||
go f = do
|
a f k m
|
||||||
a f k m
|
callback (FileContent f)
|
||||||
callback (FileContent f)
|
|
||||||
|
|
||||||
-- A Retriever that generates a L.ByteString containing the Key's content.
|
-- A Retriever that generates a L.ByteString containing the Key's content.
|
||||||
byteRetriever :: (Key -> Annex L.ByteString) -> Retriever
|
byteRetriever :: (Key -> Annex L.ByteString) -> Retriever
|
||||||
byteRetriever a k _m callback = callback =<< (ByteContent <$> a k)
|
byteRetriever a k _m callback = callback =<< (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)
|
|
||||||
|
|
||||||
{- The base Remote that is provided to chunkedEncryptableRemote
|
{- The base Remote that is provided to chunkedEncryptableRemote
|
||||||
- needs to have storeKey and retreiveKeyFile methods, but they are
|
- needs to have storeKey and retreiveKeyFile methods, but they are
|
||||||
- never actually used (since chunkedEncryptableRemote replaces
|
- never actually used (since chunkedEncryptableRemote replaces
|
||||||
|
@ -178,11 +173,18 @@ sink dest enc mh mp content = do
|
||||||
(Nothing, Nothing, FileContent f)
|
(Nothing, Nothing, FileContent f)
|
||||||
| f == dest -> noop
|
| f == dest -> noop
|
||||||
| otherwise -> liftIO $ moveFile f dest
|
| otherwise -> liftIO $ moveFile f dest
|
||||||
(Just (cipher, _), _, _) ->
|
(Just (cipher, _), _, ByteContent b) ->
|
||||||
|
decrypt cipher (feedBytes b) $
|
||||||
|
readBytes write
|
||||||
|
(Just (cipher, _), _, FileContent f) -> do
|
||||||
withBytes content $ \b ->
|
withBytes content $ \b ->
|
||||||
decrypt cipher (feedBytes b) $
|
decrypt cipher (feedBytes b) $
|
||||||
readBytes write
|
readBytes write
|
||||||
(Nothing, _, _) -> withBytes content write
|
liftIO $ nukeFile f
|
||||||
|
(Nothing, _, FileContent f) -> do
|
||||||
|
withBytes content write
|
||||||
|
liftIO $ nukeFile f
|
||||||
|
(Nothing, _, ByteContent b) -> write b
|
||||||
return True
|
return True
|
||||||
where
|
where
|
||||||
write b = case mh of
|
write b = case mh of
|
||||||
|
@ -192,3 +194,7 @@ sink dest enc mh mp content = do
|
||||||
Just p -> meteredWrite p h b
|
Just p -> meteredWrite p h b
|
||||||
Nothing -> L.hPut h b
|
Nothing -> L.hPut h b
|
||||||
opendest = openBinaryFile dest WriteMode
|
opendest = openBinaryFile dest WriteMode
|
||||||
|
|
||||||
|
withBytes :: ContentSource -> (L.ByteString -> Annex a) -> Annex a
|
||||||
|
withBytes (ByteContent b) a = a b
|
||||||
|
withBytes (FileContent f) a = a =<< liftIO (L.readFile f)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue