an optimization that also fixes a reversion
authorJoey Hess <joeyh@joeyh.name>
Tue, 12 May 2015 22:34:49 +0000 (18:34 -0400)
committerJoey Hess <joeyh@joeyh.name>
Tue, 12 May 2015 22:34:49 +0000 (18:34 -0400)
This is a little optimisation; avoid loading the info file for the
download of the current key when checking for other downloads.

The reversion it fixes is sorta strange.
a812d598ef90b3778258f197b2fcb86d51d83d72 broke checking for transfers
that were already in progress. Indeed, the transfer lock was not held
after getTransfers was called.

Why? I think it's magic in ghc's handling of getLock and setLock,
although it's hard to tell since those functions are almost entirely
undocumented as to their semantics.

Something, either the RTS (or maybe it's linux?) notices that the
same process has taken a lock and is now calling getLock on a FD attached
to the same file. So, it drops the lock.

So, this optimisation avoids that problematic behavior.

Logs/Transfer.hs

index 6d655033d60f89b621bd76e65c90d8c79efe82e5..0ee69b63f37238e6f23df428e3614a3ed55f68c4 100644 (file)
@@ -147,11 +147,12 @@ checkTransfer t = do
 
 {- Gets all currently running transfers. -}
 getTransfers :: Annex [(Transfer, TransferInfo)]
-getTransfers = getTransfers' [Download, Upload]
+getTransfers = getTransfers' [Download, Upload] (const True)
 
-getTransfers' :: [Direction] -> Annex [(Transfer, TransferInfo)]
-getTransfers' dirs = do
-       transfers <- mapMaybe parseTransferFile . concat <$> findfiles
+getTransfers' :: [Direction] -> (Key -> Bool) -> Annex [(Transfer, TransferInfo)]
+getTransfers' dirs wanted = do
+       transfers <- filter (wanted . transferKey)
+               <$> mapMaybe parseTransferFile . concat <$> findfiles
        infos <- mapM checkTransfer transfers
        return $ map (\(t, Just i) -> (t, i)) $
                filter running $ zip transfers infos
@@ -163,10 +164,9 @@ getTransfers' dirs = do
 {- 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]
+sizeOfDownloadsInProgress wanted = sum . map remaining
+       <$> getTransfers' [Download] wanted
   where
-       wanted (t, _) = match (transferKey t)
        remaining (t, info) =
                case (keySize (transferKey t), bytesComplete info) of
                        (Just sz, Just done) -> sz - done