[Hugs-bugs] File remains locked after crash

Ross Paterson ross at soi.city.ac.uk
Mon May 1 12:12:52 EDT 2006


On Mon, May 01, 2006 at 04:32:30PM +0100, Neil Mitchell wrote:
> On Windows, Hugs CVS Head:
> 
> Change to a directory and run, at the prompt:
> writeFile "test.txt" (error "fail")
> 
> The file test.txt is created, and the error "fail" is given.
> 
> Now flipping to Windows explorer, try to delete the file test.txt and
> you can't because its still held open by hugs. The only way I can find
> for Hugs to release the file is to close hugs and restart it.
> 
> My guess is that the handle that is openned by writeFile is not closed on 
> error.

This should be a better implementation of writeFile:

	import Control.Exception
	import System.IO

	writeFile' :: FilePath -> String -> IO ()
	writeFile' f txt = bracket (openFile f WriteMode) hClose
				(flip hPutStr txt)



More information about the Hugs-Bugs mailing list