- 
                Notifications
    
You must be signed in to change notification settings  - Fork 144
 
Open
Description
hGetContents doesn't create Handle and therefore it is not obvious why it closes it. Handle is closed on a bracket.
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
No labels