1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2024-09-19 10:50:24 -04:00

Merge pull request #11019 from DeterminateSystems/fix-failed-to-open-archive

Tarball fetcher: Fix handling of cached tarballs
This commit is contained in:
Eelco Dolstra 2024-07-05 17:10:02 +02:00 committed by GitHub
commit 8f280d72ff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 7 deletions

View file

@ -67,6 +67,17 @@ int getArchiveFilterCodeByName(const std::string & method)
return code;
}
static void enableSupportedFormats(struct archive * archive)
{
archive_read_support_format_tar(archive);
archive_read_support_format_zip(archive);
/* Enable support for empty files so we don't throw an exception
for empty HTTP 304 "Not modified" responses. See
downloadTarball(). */
archive_read_support_format_empty(archive);
}
TarArchive::TarArchive(Source & source, bool raw, std::optional<std::string> compression_method)
: archive{archive_read_new()}
, source{&source}
@ -78,10 +89,9 @@ TarArchive::TarArchive(Source & source, bool raw, std::optional<std::string> com
archive_read_support_filter_by_code(archive, getArchiveFilterCodeByName(*compression_method));
}
if (!raw) {
archive_read_support_format_tar(archive);
archive_read_support_format_zip(archive);
} else {
if (!raw)
enableSupportedFormats(archive);
else {
archive_read_support_format_raw(archive);
archive_read_support_format_empty(archive);
}
@ -97,8 +107,7 @@ TarArchive::TarArchive(const Path & path)
, buffer(defaultBufferSize)
{
archive_read_support_filter_all(archive);
archive_read_support_format_tar(archive);
archive_read_support_format_zip(archive);
enableSupportedFormats(archive);
archive_read_set_option(archive, NULL, "mac-ext", NULL);
check(archive_read_open_filename(archive, path.c_str(), 16384), "failed to open archive: %s");
}

View file

@ -77,8 +77,10 @@ in
assert info["revision"] == "${nixpkgs.rev}"
assert info["revCount"] == 1234
# Check that fetching with rev/revCount/narHash succeeds.
# Check that a 0-byte HTTP 304 "Not modified" result works.
machine.succeed("nix flake metadata --refresh --json http://localhost/tags/latest.tar.gz")
# Check that fetching with rev/revCount/narHash succeeds.
machine.succeed("nix flake metadata --json http://localhost/tags/latest.tar.gz?rev=" + info["revision"])
machine.succeed("nix flake metadata --json http://localhost/tags/latest.tar.gz?revCount=" + str(info["revCount"]))
machine.succeed("nix flake metadata --json http://localhost/tags/latest.tar.gz?narHash=" + info["locked"]["narHash"])