Skip to content

Commit e8de003

Browse files
committed
Support .tar archives #3647
1 parent 06d14db commit e8de003

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
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: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ 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
112+
let tryTargz = do
113+
logDebug $ "Trying to ungzip/untar " <> T.pack fp
114114
liftIO $ withBinaryFile fp ReadMode $ \h -> do
115115
lbs <- L.hGetContents h
116116
let entries = Tar.read $ GZip.decompress lbs
@@ -120,14 +120,20 @@ resolveSinglePackageLocation projRoot (PLArchive (Archive url subdir msha)) = do
120120
archive <- fmap Zip.toArchive $ liftIO $ L.readFile fp
121121
liftIO $ Zip.extractFilesFromArchive [Zip.OptDestination
122122
(toFilePath dirTmp)] archive
123+
tryTar = do
124+
logDebug $ "Trying to untar (no ungzip) " <> T.pack fp
125+
liftIO $ withBinaryFile fp ReadMode $ \h -> do
126+
lbs <- L.hGetContents h
127+
let entries = Tar.read lbs
128+
Tar.unpack (toFilePath dirTmp) entries
123129
err = throwM $ UnableToExtractArchive url file
124130

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

130-
tryTar `catchAnyLog` tryZip `catchAnyLog` err
136+
tryTargz `catchAnyLog` tryZip `catchAnyLog` tryTar `catchAnyLog` err
131137
renameDir dirTmp dir
132138

133139
x <- listDir dir

0 commit comments

Comments
 (0)