summaryrefslogtreecommitdiff
path: root/Utility.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Utility.hs')
-rw-r--r--Utility.hs7
1 files changed, 5 insertions, 2 deletions
diff --git a/Utility.hs b/Utility.hs
index ab9ce04f3..d1eb247d3 100644
--- a/Utility.hs
+++ b/Utility.hs
@@ -9,12 +9,15 @@ import Data.String.Utils
{- Let's just say that Haskell makes reading/writing a file with
- file locking excessively difficult. -}
-openLocked file mode = do
+withFileLocked file mode action = do
+ -- TODO: find a way to use bracket here
handle <- openFile file mode
lockfd <- handleToFd handle -- closes handle
waitToSetLock lockfd (lockType mode, AbsoluteSeek, 0, 0)
handle' <- fdToHandle lockfd
- return handle'
+ ret <- action handle'
+ hClose handle'
+ return ret
where
lockType ReadMode = ReadLock
lockType _ = WriteLock