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:
Joey Hess 2013-03-07 12:35:42 -04:00
parent 8141b081b7
commit 265e440d22

View file

@ -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 ()