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.
This commit is contained in:
Joey Hess 2016-04-04 15:42:33 -04:00
parent cfe274e6f7
commit 2046502407
Failed to extract signature
4 changed files with 30 additions and 3 deletions

View file

@ -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.