diff options
-rw-r--r-- | kiki.hs | 15 |
1 files changed, 8 insertions, 7 deletions
@@ -723,17 +723,18 @@ readPacketsFromFile fname = do | |||
723 | return $ decode input | 723 | return $ decode input |
724 | #endif | 724 | #endif |
725 | 725 | ||
726 | -- | Attempts to lock each file in the list. | ||
727 | -- Returns a list of locks and a list of filenames | ||
728 | -- that could not be locked. | ||
729 | lockFiles :: [FilePath] -> IO ( [(DotLock,FilePath)], [FilePath] ) | ||
726 | lockFiles fs = do | 730 | lockFiles fs = do |
727 | let dolock f = do | 731 | ls <- forM fs $ \f -> do |
728 | lk <- dotlock_create f 0 | 732 | lk <- dotlock_create f 0 |
729 | let fail = return Nothing | 733 | v <- flip (maybe $ return Nothing) lk $ \lk -> do |
730 | dotake lk = do | ||
731 | e <- dotlock_take lk (-1) | 734 | e <- dotlock_take lk (-1) |
732 | if e==0 then return (Just lk) | 735 | return $ if e==0 then Just lk |
733 | else fail | 736 | else Nothing |
734 | v <- maybe fail dotake lk | ||
735 | return (v,f) | 737 | return (v,f) |
736 | ls <- mapM dolock fs | ||
737 | let (lks, fails) = partition (isJust . fst) ls | 738 | let (lks, fails) = partition (isJust . fst) ls |
738 | return (map (\(lk,f)->(fromJust lk,f)) lks, map snd fails) | 739 | return (map (\(lk,f)->(fromJust lk,f)) lks, map snd fails) |
739 | 740 | ||