summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-07-24 16:42:35 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-07-24 16:42:35 -0400
commit477243a87dd07ac8282745c482708205c5fa474f (patch)
tree8b3155b20a916755a0ff91b1037d067a3dfa174b
parent2b414feaf2d20452794d0cdd608c6dd91feb1ec1 (diff)
move meteredWriteFileChunks out of legacy
-rw-r--r--Remote/Directory.hs2
-rw-r--r--Remote/Helper/Chunked.hs19
-rw-r--r--Remote/Helper/Chunked/Legacy.hs11
-rw-r--r--Remote/WebDAV.hs2
4 files changed, 20 insertions, 14 deletions
diff --git a/Remote/Directory.hs b/Remote/Directory.hs
index 82d38c884..62c01e370 100644
--- a/Remote/Directory.hs
+++ b/Remote/Directory.hs
@@ -222,7 +222,7 @@ retrieve :: FilePath -> ChunkConfig -> Key -> AssociatedFile -> FilePath -> Mete
retrieve d chunkconfig k _ f p = metered (Just p) k $ \meterupdate ->
liftIO $ withStoredFiles chunkconfig d k $ \files ->
catchBoolIO $ do
- Legacy.meteredWriteFileChunks meterupdate f files L.readFile
+ meteredWriteFileChunks meterupdate f files L.readFile
return True
retrieveEncrypted :: FilePath -> ChunkConfig -> (Cipher, Key) -> Key -> FilePath -> MeterUpdate -> Annex Bool
diff --git a/Remote/Helper/Chunked.hs b/Remote/Helper/Chunked.hs
index edd9dd8c9..031ff63d6 100644
--- a/Remote/Helper/Chunked.hs
+++ b/Remote/Helper/Chunked.hs
@@ -5,14 +5,21 @@
- Licensed under the GNU GPL version 3 or higher.
-}
-module Remote.Helper.Chunked where
+module Remote.Helper.Chunked
+ ( ChunkSize
+ , ChunkConfig(..)
+ , chunkConfig
+ , meteredWriteFileChunks
+ ) where
+import Common.Annex
import Utility.DataUnits
import Types.Remote
import Logs.Chunk.Pure (ChunkSize)
+import Utility.Metered
+import qualified Data.ByteString.Lazy as L
import qualified Data.Map as M
-import Data.Int
data ChunkConfig
= NoChunks
@@ -30,3 +37,11 @@ chunkConfig m =
readsz v f = case readSize dataUnits v of
Just size | size > 0 -> fromInteger size
_ -> error ("bad " ++ f)
+
+{- Writes a series of chunks to a file. The feeder is called to get
+ - each chunk. -}
+meteredWriteFileChunks :: MeterUpdate -> FilePath -> [v] -> (v -> IO L.ByteString) -> IO ()
+meteredWriteFileChunks meterupdate dest chunks feeder =
+ withBinaryFile dest WriteMode $ \h ->
+ forM_ chunks $
+ meteredWrite meterupdate h <=< feeder
diff --git a/Remote/Helper/Chunked/Legacy.hs b/Remote/Helper/Chunked/Legacy.hs
index 3b6b0d47f..1ec0eb68f 100644
--- a/Remote/Helper/Chunked/Legacy.hs
+++ b/Remote/Helper/Chunked/Legacy.hs
@@ -8,8 +8,7 @@
module Remote.Helper.Chunked.Legacy where
import Common.Annex
-import Utility.Metered
-import Remote.Helper.Chunked (ChunkSize)
+import Remote.Helper.Chunked
import qualified Data.ByteString.Lazy as L
import qualified Control.Exception as E
@@ -115,11 +114,3 @@ storeChunked chunksize dests storer content = either onerr return
let (chunk, b') = L.splitAt sz b
storer d chunk
storechunks sz (d:useddests) ds b'
-
-{- Writes a series of chunks to a file. The feeder is called to get
- - each chunk. -}
-meteredWriteFileChunks :: MeterUpdate -> FilePath -> [v] -> (v -> IO L.ByteString) -> IO ()
-meteredWriteFileChunks meterupdate dest chunks feeder =
- withBinaryFile dest WriteMode $ \h ->
- forM_ chunks $
- meteredWrite meterupdate h <=< feeder
diff --git a/Remote/WebDAV.hs b/Remote/WebDAV.hs
index 36df60945..4be7e4701 100644
--- a/Remote/WebDAV.hs
+++ b/Remote/WebDAV.hs
@@ -140,7 +140,7 @@ retrieve :: Remote -> Key -> AssociatedFile -> FilePath -> MeterUpdate -> Annex
retrieve r k _f d p = metered (Just p) k $ \meterupdate ->
davAction r False $ \(baseurl, user, pass) -> liftIO $ catchBoolIO $
withStoredFiles r k baseurl user pass onerr $ \urls -> do
- Legacy.meteredWriteFileChunks meterupdate d urls $ \url -> do
+ meteredWriteFileChunks meterupdate d urls $ \url -> do
mb <- getDAV url user pass
case mb of
Nothing -> throwIO "download failed"