implement pausing of transfers

A paused transfer's thread keeps running, keeping the slot in use.
This is intentional; pausing a transfer should not let other
queued transfers to run in its place.
This commit is contained in:
Joey Hess 2012-08-10 18:42:44 -04:00
parent 21bd92f077
commit 8ba9830653
5 changed files with 62 additions and 26 deletions

View file

@ -183,17 +183,19 @@ adjustTransfersSTM dstatus a = do
s <- takeTMVar dstatus
putTMVar dstatus $ s { currentTransfers = a (currentTransfers s) }
{- Updates a transfer's info. Preserves any transferTid value, which is not
- written to disk. -}
{- Updates a transfer's info.
- Preserves the transferTid and transferPaused values,
- which are not written to disk. -}
updateTransferInfo :: DaemonStatusHandle -> Transfer -> TransferInfo -> IO ()
updateTransferInfo dstatus t info =
notifyTransfer dstatus `after` modifyDaemonStatus_ dstatus go
where
go s = s { currentTransfers = update (currentTransfers s) }
update m = M.insertWith' merge t info m
merge new old = case transferTid old of
Nothing -> new
Just _ -> new { transferTid = transferTid old }
merge new old = new
{ transferTid = maybe (transferTid new) Just (transferTid old)
, transferPaused = transferPaused new || transferPaused old
}
{- Removes a transfer from the map, and returns its info. -}
removeTransfer :: DaemonStatusHandle -> Transfer -> IO (Maybe TransferInfo)