aboutsummaryrefslogtreecommitdiff
path: root/Annex/Link.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2016-04-04 15:42:33 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2016-04-04 15:42:33 -0400
commit18851f0e8fc12978907bc596e3392de3b8f27e3a (patch)
tree258f0c66e61a9aeed147f018c09d29e0bb6c6c70 /Annex/Link.hs
parent34b94d09278cd4deb1157230a05360163245188f (diff)
v6: Close pointer file handles more quickly, to avoid problems on Windows.
Was using L.readFile, so the Handle would remain open until the garbage collector got around to it. Changed to explicit open and close, so we know it's always closed when the function returns.
Diffstat (limited to 'Annex/Link.hs')
-rw-r--r--Annex/Link.hs10
1 files changed, 7 insertions, 3 deletions
diff --git a/Annex/Link.hs b/Annex/Link.hs
index b191bce6f..44c567837 100644
--- a/Annex/Link.hs
+++ b/Annex/Link.hs
@@ -157,10 +157,14 @@ formatPointer k =
-
- Unlocked files whose content is present are not detected by this. -}
isPointerFile :: FilePath -> IO (Maybe Key)
-isPointerFile f = catchDefaultIO Nothing $ do
- b <- L.take maxPointerSz <$> L.readFile f
- let !mk = parseLinkOrPointer' (decodeBS b)
+isPointerFile f = catchDefaultIO Nothing $ bracket open close $ \h -> do
+ b <- take (fromIntegral maxPointerSz) <$> hGetContents h
+ -- strict so it reads before the file handle is closed
+ let !mk = parseLinkOrPointer' b
return mk
+ where
+ open = openBinaryFile f ReadMode
+ close = hClose
{- Checks a symlink target or pointer file first line to see if it
- appears to point to annexed content.