summaryrefslogtreecommitdiff
path: root/kiki.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2014-04-11 22:18:20 -0400
committerjoe <joe@jerkface.net>2014-04-11 22:18:20 -0400
commit2f9432b33bf5c8f9c89d8c8d3c255466fc3eb361 (patch)
tree7578e1a0da6a9e9b6296b15f967b559cf5a88fde /kiki.hs
parentb9c338d14e8d95164dfe3719abb4cf8064e22bd2 (diff)
reorganized lockFiles
Diffstat (limited to 'kiki.hs')
-rw-r--r--kiki.hs15
1 files changed, 8 insertions, 7 deletions
diff --git a/kiki.hs b/kiki.hs
index 414d185..e4c0dc4 100644
--- a/kiki.hs
+++ b/kiki.hs
@@ -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.
729lockFiles :: [FilePath] -> IO ( [(DotLock,FilePath)], [FilePath] )
726lockFiles fs = do 730lockFiles 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