-
Notifications
You must be signed in to change notification settings - Fork 19
Closed
Labels
out-of-scopeUnrelated to CLC or does not need a CLC approvalUnrelated to CLC or does not need a CLC approval
Description
Data.ByteString.Lazy.hGetContents closes handle. This is not obvious and redundant, because handle is usually created in a bracket which takes care of closing handle.
hGetContents should be deprecated and
hGetContents'
introduced with new semantics.
data GitObject
= GitObject
{ gobHash :: !(Digest SHA1State)
, gobOrigin :: !FilePath
}
deriving (Show, Eq)
mkGitObject :: PhoenixM m => FilePath -> m (Maybe GitObject)
mkGitObject fp = do
s <- asks inHandlesSem
U.bracket_ (U.waitQSem s) (U.signalQSem s) $
U.withBinaryFile fp U.ReadMode $ \inH -> do
magicBs <- hGet inH 2
if zlibP magicBs
then do
!headerBs <- (magicBs <>) <$> hGet inH 10
(`U.catch` skipCorruptedFile inH) $ do
if gitObjectP $ Z.decompress (toLazy headerBs)
then do
!goh <- sha1 . Z.decompress . (toLazy headerBs <>) <$> hGetContents inH
pure . Just $ GitObject goh fp
else pure Nothing
else pure Nothing
where
skipCorruptedFile inH (e :: Z.DecompressError) =
case e of
Z.TruncatedInput -> do
fsz <- liftIO $ U.hFileSize inH
Metadata
Metadata
Assignees
Labels
out-of-scopeUnrelated to CLC or does not need a CLC approvalUnrelated to CLC or does not need a CLC approval