From 19fee049f6dfba4d4294e16d6d530bc7d0e78c54 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 3 Feb 2014 10:16:05 -0400 Subject: 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. --- Utility/FileMode.hs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'Utility/FileMode.hs') 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 -- cgit v1.2.3