summaryrefslogtreecommitdiff
path: root/Annex
diff options
context:
space:
mode:
Diffstat (limited to 'Annex')
-rw-r--r--Annex/Content/Direct.hs3
-rw-r--r--Annex/Link.hs10
2 files changed, 4 insertions, 9 deletions
diff --git a/Annex/Content/Direct.hs b/Annex/Content/Direct.hs
index 35d2c9b8d..f897cca6a 100644
--- a/Annex/Content/Direct.hs
+++ b/Annex/Content/Direct.hs
@@ -52,8 +52,7 @@ associatedFiles key = do
associatedFilesRelative :: Key -> Annex [FilePath]
associatedFilesRelative key = do
mapping <- calcRepo $ gitAnnexMapping key
- liftIO $ catchDefaultIO [] $ do
- h <- openFile mapping ReadMode
+ liftIO $ catchDefaultIO [] $ withFile mapping ReadMode $ \h -> do
fileEncoding h
lines <$> hGetContents h
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