avoid queuing transfers that are already queued
I saw this happen in real life, when syncing to a newly added usb drive. I think it got scanned twice, and files were doubled in the queue. This could be optimised a little bit more, to only read from the mvar once, rather than twice.
This commit is contained in:
parent
8141b081b7
commit
265e440d22
1 changed files with 11 additions and 5 deletions
|
@ -122,13 +122,19 @@ enqueue reason schedule t info
|
|||
| otherwise = go (\l -> l++[new])
|
||||
where
|
||||
new = (t, info)
|
||||
go modlist = do
|
||||
q <- getAssistant transferQueue
|
||||
liftIO $ atomically $ do
|
||||
void $ modifyTVar' (queuesize q) succ
|
||||
void $ modifyTVar' (queuelist q) modlist
|
||||
go modlist = whenM (add modlist) $ do
|
||||
debug [ "queued", describeTransfer t info, ": " ++ reason ]
|
||||
notifyTransfer
|
||||
add modlist = do
|
||||
q <- getAssistant transferQueue
|
||||
liftIO $ atomically $ do
|
||||
l <- readTVar (queuelist q)
|
||||
if (new `elem` l)
|
||||
then do
|
||||
void $ modifyTVar' (queuesize q) succ
|
||||
void $ modifyTVar' (queuelist q) modlist
|
||||
return True
|
||||
else return False
|
||||
|
||||
{- Adds a transfer to the queue. -}
|
||||
queueTransfer :: Reason -> Schedule -> AssociatedFile -> Transfer -> Remote -> Assistant ()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue