diff options
author | Joey Hess <joey@kitenet.net> | 2013-03-07 12:35:42 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2013-03-07 12:35:42 -0400 |
commit | 00f0c51990dedd39bb8ac89c04eb7f43a88726a5 (patch) | |
tree | a696f468f6c15565d44a42beae59bc116cdd7945 /Assistant | |
parent | fe0a56c1222e64c32a324597797bd319efa75c8a (diff) |
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.
Diffstat (limited to 'Assistant')
-rw-r--r-- | Assistant/TransferQueue.hs | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/Assistant/TransferQueue.hs b/Assistant/TransferQueue.hs index 7c41f0399..3f38b37a3 100644 --- a/Assistant/TransferQueue.hs +++ b/Assistant/TransferQueue.hs @@ -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 () |