summaryrefslogtreecommitdiff
path: root/Utility/FileMode.hs
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 /Utility/FileMode.hs
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 'Utility/FileMode.hs')
-rw-r--r--Utility/FileMode.hs4
1 files changed, 1 insertions, 3 deletions
diff --git a/Utility/FileMode.hs b/Utility/FileMode.hs
index 46c6a31f5..b17cadc3b 100644
--- a/Utility/FileMode.hs
+++ b/Utility/FileMode.hs
@@ -133,10 +133,8 @@ setSticky f = modifyFileMode f $ addModes [stickyMode]
- as writeFile.
-}
writeFileProtected :: FilePath -> String -> IO ()
-writeFileProtected file content = do
- h <- openFile file WriteMode
+writeFileProtected file content = withFile file WriteMode $ \h -> do
void $ tryIO $
modifyFileMode file $
removeModes [groupReadMode, otherReadMode]
hPutStr h content
- hClose h