Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support .tar archives #3647 #3655

Merged
merged 2 commits into from
Dec 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ Behaviour changes:

Other enhancements:

* In addition to supporting `.tar.gz` and `.zip` files as remote archives,
plain `.tar` files are now accepted too. This will additionally help with
cases where HTTP servers mistakenly set the transfer encoding to `gzip`. See
[#3647](https://github.com/commercialhaskell/stack/issues/3647).

Bug fixes:

* For versions of Cabal before 1.24, ensure that the dependencies of
Expand Down
37 changes: 23 additions & 14 deletions src/Stack/PackageLocation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -109,25 +109,34 @@ resolveSinglePackageLocation projRoot (PLArchive (Archive url subdir msha)) = do

let fp = toFilePath file

let tryTar = do
logDebug $ "Trying to untar " <> T.pack fp
liftIO $ withBinaryFile fp ReadMode $ \h -> do
lbs <- L.hGetContents h
let entries = Tar.read $ GZip.decompress lbs
Tar.unpack (toFilePath dirTmp) entries
tryZip = do
withBinaryFile fp ReadMode $ \h -> do
-- Share a single file read among all of the different
-- parsing attempts. We're not worried about unbounded
-- memory usage, as we will detect almost immediately if
-- this is the wrong type of file.
lbs <- liftIO $ L.hGetContents h

let tryTargz = do
logDebug $ "Trying to ungzip/untar " <> T.pack fp
let entries = Tar.read $ GZip.decompress lbs
liftIO $ Tar.unpack (toFilePath dirTmp) entries
tryZip = do
logDebug $ "Trying to unzip " <> T.pack fp
archive <- fmap Zip.toArchive $ liftIO $ L.readFile fp
let archive = Zip.toArchive lbs
liftIO $ Zip.extractFilesFromArchive [Zip.OptDestination
(toFilePath dirTmp)] archive
err = throwM $ UnableToExtractArchive url file
tryTar = do
logDebug $ "Trying to untar (no ungzip) " <> T.pack fp
let entries = Tar.read lbs
liftIO $ Tar.unpack (toFilePath dirTmp) entries
err = throwM $ UnableToExtractArchive url file

catchAnyLog goodpath handler =
catchAny goodpath $ \e -> do
logDebug $ "Got exception: " <> T.pack (show e)
handler
catchAnyLog goodpath handler =
catchAny goodpath $ \e -> do
logDebug $ "Got exception: " <> T.pack (show e)
handler

tryTar `catchAnyLog` tryZip `catchAnyLog` err
tryTargz `catchAnyLog` tryZip `catchAnyLog` tryTar `catchAnyLog` err
renameDir dirTmp dir

x <- listDir dir
Expand Down