Skip to content
Closed
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
4 changes: 1 addition & 3 deletions src/libfetchers/tarball.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,7 @@ DownloadTarballResult downloadTarball(
AutoDelete autoDelete(tmpDir, true);
unpackTarfile(store->toRealPath(res.storePath), tmpDir);
auto members = readDirectory(tmpDir);
if (members.size() != 1)
throw nix::Error("tarball '%s' contains an unexpected number of top-level files", url);
auto topDir = tmpDir + "/" + members.begin()->name;
auto topDir = members.size() == 1 ? tmpDir + "/" + members.begin()->name : tmpDir;
lastModified = lstat(topDir).st_mtime;
unpackedStorePath = store->addToStore(name, topDir, FileIngestionMethod::Recursive, htSHA256, defaultPathFilter, NoRepair);
}
Expand Down
9 changes: 8 additions & 1 deletion tests/tarball.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@ hash=$(nix hash path $tarroot)
test_tarball() {
local ext="$1"
local compressor="$2"
local noroot="${3:-false}"

tarball=$TEST_ROOT/tarball.tar$ext
(cd $TEST_ROOT && tar cf - tarball) | $compressor > $tarball
if [ "$noroot" = true ]; then
local tarargs="-C tarball ."
else
local tarargs="tarball"
fi
(cd $TEST_ROOT && tar cf - $tarargs) | $compressor > $tarball

nix-env -f file://$tarball -qa --out-path | grepQuiet dependencies

Expand Down Expand Up @@ -55,6 +61,7 @@ test_tarball() {
}

test_tarball '' cat
test_tarball '' cat true
test_tarball .xz xz
test_tarball .gz gzip

Expand Down