summaryrefslogtreecommitdiff
path: root/Logs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-05-12 15:19:08 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-05-12 15:20:22 -0400
commitb94eafec8c4a7868da753f9b22ca823552e9764c (patch)
treeb56d9b021182fa6e143cae726a9417f7233c3752 /Logs
parentfd33ca1ed6709837bc92d065ff345478e359a7d2 (diff)
Take space that will be used by running downloads into account when checking annex.diskreserve.
Diffstat (limited to 'Logs')
-rw-r--r--Logs/Transfer.hs20
1 files changed, 18 insertions, 2 deletions
diff --git a/Logs/Transfer.hs b/Logs/Transfer.hs
index 078157208..6d655033d 100644
--- a/Logs/Transfer.hs
+++ b/Logs/Transfer.hs
@@ -147,16 +147,32 @@ checkTransfer t = do
{- Gets all currently running transfers. -}
getTransfers :: Annex [(Transfer, TransferInfo)]
-getTransfers = do
+getTransfers = getTransfers' [Download, Upload]
+
+getTransfers' :: [Direction] -> Annex [(Transfer, TransferInfo)]
+getTransfers' dirs = do
transfers <- mapMaybe parseTransferFile . concat <$> findfiles
infos <- mapM checkTransfer transfers
return $ map (\(t, Just i) -> (t, i)) $
filter running $ zip transfers infos
where
findfiles = liftIO . mapM dirContentsRecursive
- =<< mapM (fromRepo . transferDir) [Download, Upload]
+ =<< mapM (fromRepo . transferDir) dirs
running (_, i) = isJust i
+{- Number of bytes remaining to download from matching downloads that are in
+ - progress. -}
+sizeOfDownloadsInProgress :: (Key -> Bool) -> Annex Integer
+sizeOfDownloadsInProgress match = sum . map remaining . filter wanted
+ <$> getTransfers' [Download]
+ where
+ wanted (t, _) = match (transferKey t)
+ remaining (t, info) =
+ case (keySize (transferKey t), bytesComplete info) of
+ (Just sz, Just done) -> sz - done
+ (Just sz, Nothing) -> sz
+ (Nothing, _) -> 0
+
{- Gets failed transfers for a given remote UUID. -}
getFailedTransfers :: UUID -> Annex [(Transfer, TransferInfo)]
getFailedTransfers u = catMaybes <$> (liftIO . getpairs =<< concat <$> findfiles)