use bracket to reset environment
In case the exception is caught higher up, don't leave the environment dirty.
This commit is contained in:
parent
8ef2095fa0
commit
1a96d4ab35
1 changed files with 11 additions and 12 deletions
23
Branch.hs
23
Branch.hs
|
@ -65,17 +65,13 @@ withIndex' :: Bool -> Annex a -> Annex a
|
||||||
withIndex' bootstrapping a = do
|
withIndex' bootstrapping a = do
|
||||||
g <- gitRepo
|
g <- gitRepo
|
||||||
let f = index g
|
let f = index g
|
||||||
reset <- liftIO $ Git.useIndex f
|
|
||||||
|
|
||||||
e <- liftIO $ doesFileExist f
|
bracket (Git.useIndex f) id $ do
|
||||||
unless e $ do
|
unlessM (liftIO $ doesFileExist f) $ do
|
||||||
unless bootstrapping create
|
unless bootstrapping create
|
||||||
liftIO $ createDirectoryIfMissing True $ takeDirectory f
|
liftIO $ createDirectoryIfMissing True $ takeDirectory f
|
||||||
liftIO $ unless bootstrapping $ genIndex g
|
unless bootstrapping $ liftIO $ genIndex g
|
||||||
|
a
|
||||||
r <- a
|
|
||||||
liftIO reset
|
|
||||||
return r
|
|
||||||
|
|
||||||
withIndexUpdate :: Annex a -> Annex a
|
withIndexUpdate :: Annex a -> Annex a
|
||||||
withIndexUpdate a = update >> withIndex a
|
withIndexUpdate a = update >> withIndex a
|
||||||
|
@ -332,11 +328,14 @@ lockJournal :: Annex a -> Annex a
|
||||||
lockJournal a = do
|
lockJournal a = do
|
||||||
g <- gitRepo
|
g <- gitRepo
|
||||||
let file = gitAnnexJournalLock g
|
let file = gitAnnexJournalLock g
|
||||||
liftIOOp (Control.Exception.bracket (lock file) unlock) run
|
bracket (lock file) unlock a
|
||||||
where
|
where
|
||||||
lock file = do
|
lock file = do
|
||||||
l <- createFile file stdFileMode
|
l <- createFile file stdFileMode
|
||||||
waitToSetLock l (WriteLock, AbsoluteSeek, 0, 0)
|
waitToSetLock l (WriteLock, AbsoluteSeek, 0, 0)
|
||||||
return l
|
return l
|
||||||
unlock = closeFd
|
unlock = closeFd
|
||||||
run _ = a
|
|
||||||
|
bracket :: IO c -> (c -> IO b) -> Annex a -> Annex a
|
||||||
|
bracket start cleanup go =
|
||||||
|
liftIOOp (Control.Exception.bracket start cleanup) (const go)
|
||||||
|
|
Loading…
Add table
Reference in a new issue