diff options
author | Joey Hess <joey@kitenet.net> | 2010-10-10 11:08:40 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2010-10-10 11:08:40 -0400 |
commit | f98fa53d7f6d851b8a1ae804c02780769c98e07c (patch) | |
tree | d82ad5c4bd8037c8ae548c21946930d21cadf528 /Utility.hs | |
parent | 11ad93f023fa5e867b5b7bd47f45393caceb401a (diff) |
fixed close after locking
Diffstat (limited to 'Utility.hs')
-rw-r--r-- | Utility.hs | 7 |
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 |