summaryrefslogtreecommitdiff
path: root/Assistant/ScanRemotes.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Assistant/ScanRemotes.hs')
-rw-r--r--Assistant/ScanRemotes.hs12
1 files changed, 8 insertions, 4 deletions
diff --git a/Assistant/ScanRemotes.hs b/Assistant/ScanRemotes.hs
index 05b2a2ca9..2362bd9b4 100644
--- a/Assistant/ScanRemotes.hs
+++ b/Assistant/ScanRemotes.hs
@@ -26,10 +26,14 @@ newScanRemoteMap = atomically newEmptyTMVar
getScanRemote :: ScanRemoteMap -> IO Remote
getScanRemote v = atomically $ do
m <- takeTMVar v
- let newest = Prelude.head $ reverse $
- map fst $ sortBy (compare `on` snd) $ M.toList m
- putTMVar v $ M.delete newest m
- return newest
+ let l = reverse $ map fst $ sortBy (compare `on` snd) $ M.toList m
+ case l of
+ [] -> retry -- should never happen
+ (newest:_) -> do
+ let m' = M.delete newest m
+ unless (M.null m') $
+ putTMVar v m'
+ return newest
{- Adds new remotes that need scanning to the map. -}
addScanRemotes :: ScanRemoteMap -> [Remote] -> IO ()