summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-10-03 18:20:29 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-10-03 18:20:29 -0400
commit003a604a6e48a8a0ffd1564e3399b54e8c673e92 (patch)
tree8c81a6321d0fb65d8324570411ce33ece5d4be14
parent2636ea79c342f23f28a050bf8ad7f344a05210aa (diff)
drop the lock on error
-rw-r--r--Branch.hs16
1 files changed, 11 insertions, 5 deletions
diff --git a/Branch.hs b/Branch.hs
index 82ae7029f..f1ba97c94 100644
--- a/Branch.hs
+++ b/Branch.hs
@@ -32,6 +32,8 @@ import System.Posix.IO
import System.Posix.Files
import System.Exit
import qualified Data.ByteString.Lazy.Char8 as L
+import Control.Monad.IO.Control (liftIOOp)
+import qualified Control.Exception.Base
import Types.BranchState
import qualified Git
@@ -345,8 +347,12 @@ fileJournal = replace "//" "_" . replace "_" "/"
lockJournal :: Annex a -> Annex a
lockJournal a = do
g <- Annex.gitRepo
- h <- liftIO $ createFile (gitAnnexJournalLock g) stdFileMode
- liftIO $ waitToSetLock h (WriteLock, AbsoluteSeek, 0, 0)
- r <- a
- liftIO $ closeFd h
- return r
+ let file = gitAnnexJournalLock g
+ liftIOOp (Control.Exception.Base.bracket (lock file) unlock) run
+ where
+ lock file = do
+ l <- createFile file stdFileMode
+ waitToSetLock l (WriteLock, AbsoluteSeek, 0, 0)
+ return l
+ unlock = closeFd
+ run _ = a