aboutsummaryrefslogtreecommitdiff
path: root/Annex/Link.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 /Annex/Link.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 'Annex/Link.hs')
-rw-r--r--Annex/Link.hs10
1 files changed, 3 insertions, 7 deletions
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