summaryrefslogtreecommitdiff
path: root/Command
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-02-03 10:16:05 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-02-03 10:19:06 -0400
commit19fee049f6dfba4d4294e16d6d530bc7d0e78c54 (patch)
treec7888ba624904092b280223a34a044f0c2bdbd9a /Command
parent6295ec998fb65607fb8c1d88035b41fa0cb3b0d6 (diff)
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.
Diffstat (limited to 'Command')
-rw-r--r--Command/Fsck.hs7
1 files changed, 3 insertions, 4 deletions
diff --git a/Command/Fsck.hs b/Command/Fsck.hs
index f6e4fe273..dfe1a9ab6 100644
--- a/Command/Fsck.hs
+++ b/Command/Fsck.hs
@@ -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