1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-07 06:01:48 +02:00

Merge pull request #11051 from Mic92/fix-prefetch

src/nix/prefetch: fix prefetch containing current directory instead o…
This commit is contained in:
Eelco Dolstra 2024-07-05 20:33:05 +02:00 committed by GitHub
commit d5461b9009
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 5 deletions

View file

@ -114,14 +114,15 @@ std::tuple<StorePath, Hash> prefetchFile(
createDirs(unpacked);
unpackTarfile(tmpFile.string(), unpacked);
auto entries = std::filesystem::directory_iterator{unpacked};
/* If the archive unpacks to a single file/directory, then use
that as the top-level. */
auto entries = std::filesystem::directory_iterator{unpacked};
auto file_count = std::distance(entries, std::filesystem::directory_iterator{});
if (file_count == 1)
tmpFile = entries->path();
else
tmpFile = entries->path();
auto fileCount = std::distance(entries, std::filesystem::directory_iterator{});
if (fileCount != 1) {
/* otherwise, use the directory itself */
tmpFile = unpacked;
}
}
Activity act(*logger, lvlChatty, actUnknown,