avoid queuing transfers that are currently running
This commit is contained in:
parent
1f4fe92f61
commit
69a80a9a4d
2 changed files with 17 additions and 8 deletions
|
@ -151,6 +151,11 @@ adjustTransfersSTM dstatus a = do
|
||||||
s <- takeTMVar dstatus
|
s <- takeTMVar dstatus
|
||||||
putTMVar dstatus $ s { currentTransfers = a (currentTransfers s) }
|
putTMVar dstatus $ s { currentTransfers = a (currentTransfers s) }
|
||||||
|
|
||||||
|
{- Checks if a transfer is currently running. -}
|
||||||
|
checkRunningTransferSTM :: DaemonStatusHandle -> Transfer -> STM Bool
|
||||||
|
checkRunningTransferSTM dstatus t = M.member t . currentTransfers
|
||||||
|
<$> readTMVar dstatus
|
||||||
|
|
||||||
{- Alters a transfer's info, if the transfer is in the map. -}
|
{- Alters a transfer's info, if the transfer is in the map. -}
|
||||||
alterTransferInfo :: Transfer -> (TransferInfo -> TransferInfo) -> Assistant ()
|
alterTransferInfo :: Transfer -> (TransferInfo -> TransferInfo) -> Assistant ()
|
||||||
alterTransferInfo t a = updateTransferInfo' $ M.adjust a t
|
alterTransferInfo t a = updateTransferInfo' $ M.adjust a t
|
||||||
|
|
|
@ -136,14 +136,18 @@ enqueue reason schedule t info
|
||||||
notifyTransfer
|
notifyTransfer
|
||||||
add modlist = do
|
add modlist = do
|
||||||
q <- getAssistant transferQueue
|
q <- getAssistant transferQueue
|
||||||
liftIO $ atomically $ do
|
dstatus <- getAssistant daemonStatusHandle
|
||||||
l <- readTVar (queuelist q)
|
liftIO $ atomically $ ifM (checkRunningTransferSTM dstatus t)
|
||||||
if (t `notElem` map fst l)
|
( return False
|
||||||
then do
|
, do
|
||||||
void $ modifyTVar' (queuesize q) succ
|
l <- readTVar (queuelist q)
|
||||||
void $ modifyTVar' (queuelist q) modlist
|
if (t `notElem` map fst l)
|
||||||
return True
|
then do
|
||||||
else return False
|
void $ modifyTVar' (queuesize q) succ
|
||||||
|
void $ modifyTVar' (queuelist q) modlist
|
||||||
|
return True
|
||||||
|
else return False
|
||||||
|
)
|
||||||
|
|
||||||
{- Adds a transfer to the queue. -}
|
{- Adds a transfer to the queue. -}
|
||||||
queueTransfer :: Reason -> Schedule -> AssociatedFile -> Transfer -> Remote -> Assistant ()
|
queueTransfer :: Reason -> Schedule -> AssociatedFile -> Transfer -> Remote -> Assistant ()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue