@@ -109,25 +109,34 @@ resolveSinglePackageLocation projRoot (PLArchive (Archive url subdir msha)) = do
109109
110110 let fp = toFilePath file
111111
112- let tryTar = do
113- logDebug $ " Trying to untar " <> T. pack fp
114- liftIO $ withBinaryFile fp ReadMode $ \ h -> do
115- lbs <- L. hGetContents h
116- let entries = Tar. read $ GZip. decompress lbs
117- Tar. unpack (toFilePath dirTmp) entries
118- tryZip = do
112+ withBinaryFile fp ReadMode $ \ h -> do
113+ -- Share a single file read among all of the different
114+ -- parsing attempts. We're not worried about unbounded
115+ -- memory usage, as we will detect almost immediately if
116+ -- this is the wrong type of file.
117+ lbs <- liftIO $ L. hGetContents h
118+
119+ let tryTargz = do
120+ logDebug $ " Trying to ungzip/untar " <> T. pack fp
121+ let entries = Tar. read $ GZip. decompress lbs
122+ liftIO $ Tar. unpack (toFilePath dirTmp) entries
123+ tryZip = do
119124 logDebug $ " Trying to unzip " <> T. pack fp
120- archive <- fmap Zip. toArchive $ liftIO $ L. readFile fp
125+ let archive = Zip. toArchive lbs
121126 liftIO $ Zip. extractFilesFromArchive [Zip. OptDestination
122127 (toFilePath dirTmp)] archive
123- err = throwM $ UnableToExtractArchive url file
128+ tryTar = do
129+ logDebug $ " Trying to untar (no ungzip) " <> T. pack fp
130+ let entries = Tar. read lbs
131+ liftIO $ Tar. unpack (toFilePath dirTmp) entries
132+ err = throwM $ UnableToExtractArchive url file
124133
125- catchAnyLog goodpath handler =
126- catchAny goodpath $ \ e -> do
127- logDebug $ " Got exception: " <> T. pack (show e)
128- handler
134+ catchAnyLog goodpath handler =
135+ catchAny goodpath $ \ e -> do
136+ logDebug $ " Got exception: " <> T. pack (show e)
137+ handler
129138
130- tryTar `catchAnyLog` tryZip `catchAnyLog` err
139+ tryTargz `catchAnyLog` tryZip `catchAnyLog` tryTar `catchAnyLog` err
131140 renameDir dirTmp dir
132141
133142 x <- listDir dir
0 commit comments