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. --- Annex/Link.hs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'Annex/Link.hs') diff --git a/Annex/Link.hs b/Annex/Link.hs index 30d8c2ae8..234e4cb2a 100644 --- a/Annex/Link.hs +++ b/Annex/Link.hs @@ -51,19 +51,15 @@ getAnnexLinkTarget file = ifM (coreSymlinks <$> Annex.getGitConfig) | otherwise -> return Nothing Nothing -> fallback - probefilecontent f = do - h <- openFile f ReadMode + probefilecontent f = withFile f ReadMode $ \h -> do fileEncoding h -- The first 8k is more than enough to read; link -- files are small. s <- take 8192 <$> hGetContents h -- If we got the full 8k, the file is too large if length s == 8192 - then do - hClose h - return "" - else do - hClose h + then return "" + else -- If there are any NUL or newline -- characters, or whitespace, we -- certianly don't have a link to a -- cgit v1.2.3