1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2024-09-19 23:03:53 -04:00

Handle zip files containing symlinks

In streaming mode, libarchive doesn't handle symlinks in zip files
correctly. So write the entire file to disk so libarchive can access
it in random-access mode.

Fixes #10649. This was broken in cabee98152.

(cherry picked from commit 9951e14ae0)
This commit is contained in:
Eelco Dolstra 2024-05-09 19:33:09 +02:00 committed by github-actions[bot]
parent f06bf9d4f7
commit 92b4adcab8
4 changed files with 26 additions and 1 deletions

View file

@ -155,9 +155,27 @@ DownloadTarballResult downloadTarball(
// TODO: fall back to cached value if download fails. // TODO: fall back to cached value if download fails.
AutoDelete cleanupTemp;
/* Note: if the download is cached, `importTarball()` will receive /* Note: if the download is cached, `importTarball()` will receive
no data, which causes it to import an empty tarball. */ no data, which causes it to import an empty tarball. */
TarArchive archive { *source }; auto archive =
hasSuffix(toLower(parseURL(url).path), ".zip")
? ({
/* In streaming mode, libarchive doesn't handle
symlinks in zip files correctly (#10649). So write
the entire file to disk so libarchive can access it
in random-access mode. */
auto [fdTemp, path] = createTempFile("nix-zipfile");
cleanupTemp.reset(path);
debug("downloading '%s' into '%s'...", url, path);
{
FdSink sink(fdTemp.get());
source->drainInto(sink);
}
TarArchive{path};
})
: TarArchive{*source};
auto parseSink = getTarballCache()->getFileSystemObjectSink(); auto parseSink = getTarballCache()->getFileSystemObjectSink();
auto lastModified = unpackTarfileToSink(archive, *parseSink); auto lastModified = unpackTarfileToSink(archive, *parseSink);

View file

@ -0,0 +1,6 @@
source common.sh
# Test symlinks in zip files (#10649).
path=$(nix flake prefetch --json file://$(pwd)/tree.zip | jq -r .storePath)
[[ $(cat $path/foo) = foo ]]
[[ $(readlink $path/bar) = foo ]]

Binary file not shown.

View file

@ -16,6 +16,7 @@ nix_tests = \
flakes/absolute-attr-paths.sh \ flakes/absolute-attr-paths.sh \
flakes/build-paths.sh \ flakes/build-paths.sh \
flakes/flake-in-submodule.sh \ flakes/flake-in-submodule.sh \
flakes/prefetch.sh \
gc.sh \ gc.sh \
nix-collect-garbage-d.sh \ nix-collect-garbage-d.sh \
remote-store.sh \ remote-store.sh \