mirror of
https://github.com/NixOS/nix.git
synced 2025-12-08 18:11:02 +01:00
src/nix/prefetch: fix prefetch containing current directory instead of tarball
When --unpack was used the nix would add the current directory to the
nix store instead of the content of unpacked.
The reason for this is that std::distance already consumes the iterator.
To fix this we re-instantiate the directory iterator in case the
directory only contains a single entry.
(cherry picked from commit 8cea1fbd97)
This commit is contained in:
parent
df877f4522
commit
73f3179954
2 changed files with 18 additions and 5 deletions
|
|
@ -113,14 +113,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();
|
||||
unsigned fileCount = std::distance(entries, std::filesystem::directory_iterator{});
|
||||
if (fileCount != 1) {
|
||||
/* otherwise, use the directory itself */
|
||||
tmpFile = unpacked;
|
||||
}
|
||||
}
|
||||
|
||||
Activity act(*logger, lvlChatty, actUnknown,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue