summaryrefslogtreecommitdiff
path: root/Logs/Transfer.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-09-21 15:11:45 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-09-21 15:11:45 -0400
commit34ca1d698cf890016f8674fba7ef83b093103b83 (patch)
treed01ac0ae95b1dd929f6f3a69fda3f644ffb92ad8 /Logs/Transfer.hs
parentff32ee515244976961ef0753a5291d212c6138e2 (diff)
avoid updating transfer info file until another 1% of the total has been transferred
Diffstat (limited to 'Logs/Transfer.hs')
-rw-r--r--Logs/Transfer.hs21
1 files changed, 18 insertions, 3 deletions
diff --git a/Logs/Transfer.hs b/Logs/Transfer.hs
index 3d1040c2c..e9ac5bd87 100644
--- a/Logs/Transfer.hs
+++ b/Logs/Transfer.hs
@@ -100,9 +100,8 @@ runTransfer t file a = do
<*> pure Nothing
<*> pure file
<*> pure False
- ok <- bracketIO (prep tfile mode info) (cleanup tfile) $ a $ \bytes ->
- writeTransferInfoFile (info { bytesComplete = Just bytes }) tfile
-
+ meter <- liftIO $ progressupdater tfile info
+ ok <- bracketIO (prep tfile mode info) (cleanup tfile) (a meter)
unless ok $ failed info
return ok
where
@@ -123,6 +122,22 @@ runTransfer t file a = do
failedtfile <- fromRepo $ failedTransferFile t
createAnnexDirectory $ takeDirectory failedtfile
liftIO $ writeTransferInfoFile info failedtfile
+ {- Updates transfer info file as transfer progresses. -}
+ progressupdater tfile info = do
+ mvar <- newMVar 0
+ return $ \bytes -> modifyMVar_ mvar $ \oldbytes -> do
+ if (bytes - oldbytes >= mindelta)
+ then do
+ let info' = info { bytesComplete = Just bytes }
+ writeTransferInfoFile info' tfile
+ return bytes
+ else return oldbytes
+ {- The minimum change in bytesComplete that is worth
+ - updating a transfer info file for is 1% of the total
+ - keySize, rounded down. -}
+ mindelta = case keySize (transferKey t) of
+ Just sz -> sz `div` 100
+ Nothing -> 100 * 1024 -- arbitrarily, 100 kb
{- If a transfer is still running, returns its TransferInfo. -}
checkTransfer :: Transfer -> Annex (Maybe TransferInfo)