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
				
			
		
							
								
								
									
										19
									
								
								Branch.hs
									
										
									
									
									
								
							
							
						
						
									
										19
									
								
								Branch.hs
									
										
									
									
									
								
							|  | @ -65,17 +65,13 @@ withIndex' :: Bool -> Annex a -> Annex a | |||
| withIndex' bootstrapping a = do | ||||
| 	g <- gitRepo | ||||
| 	let f = index g | ||||
| 	reset <- liftIO $ Git.useIndex f | ||||
| 
 | ||||
| 	e <- liftIO $ doesFileExist f | ||||
| 	unless e $ do | ||||
| 	bracket (Git.useIndex f) id $ do | ||||
| 		unlessM (liftIO $ doesFileExist f) $ do | ||||
| 			unless bootstrapping create | ||||
| 			liftIO $ createDirectoryIfMissing True $ takeDirectory f | ||||
| 		liftIO $ unless bootstrapping $ genIndex g | ||||
| 
 | ||||
| 	r <- a | ||||
| 	liftIO reset | ||||
| 	return r | ||||
| 			unless bootstrapping $ liftIO $ genIndex g | ||||
| 		a | ||||
| 
 | ||||
| withIndexUpdate :: Annex a -> Annex a | ||||
| withIndexUpdate a = update >> withIndex a | ||||
|  | @ -332,11 +328,14 @@ lockJournal :: Annex a -> Annex a | |||
| lockJournal a = do | ||||
| 	g <- gitRepo | ||||
| 	let file = gitAnnexJournalLock g | ||||
| 	liftIOOp (Control.Exception.bracket (lock file) unlock) run | ||||
| 	bracket (lock file) unlock a | ||||
| 	where | ||||
| 		lock file = do | ||||
| 			l <- createFile file stdFileMode | ||||
| 			waitToSetLock l (WriteLock, AbsoluteSeek, 0, 0) | ||||
| 			return l | ||||
| 		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
		Add a link
		
	
		Reference in a new issue
	
	 Joey Hess
				Joey Hess