Skip to content

Commit 6125a80

Browse files
authored
Merge pull request #3655 from commercialhaskell/3647-uncompressed-tarballs
Support .tar archives #3647
2 parents 453f68b + 563a5f8 commit 6125a80

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

ChangeLog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ Behaviour changes:
1010

1111
Other enhancements:
1212

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

1520
* For versions of Cabal before 1.24, ensure that the dependencies of

src/Stack/PackageLocation.hs

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)