avoid using openFile when withFile can be used

Potentially fixes some FD leak if an action on an opened file handle fails
for some reason. There have been some hard to reproduce reports of
git-annex leaking FDs, and this may solve them.
This commit is contained in:
Joey Hess 2014-02-03 10:16:05 -04:00
parent fd1382f96f
commit 1572c460e8
6 changed files with 14 additions and 28 deletions

View file

@ -478,10 +478,9 @@ recordStartTime = do
createAnnexDirectory $ parentDir f
liftIO $ do
nukeFile f
h <- openFile f WriteMode
t <- modificationTime <$> getFileStatus f
hPutStr h $ showTime $ realToFrac t
hClose h
withFile f WriteMode $ \h -> do
t <- modificationTime <$> getFileStatus f
hPutStr h $ showTime $ realToFrac t
where
showTime :: POSIXTime -> String
showTime = show