From 4b2b15113196e403bc32ce0d7b4338971d7954a8 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 27 Sep 2021 10:57:11 +0200 Subject: [PATCH] nix path-info -r: Don't duplicate the root paths This fixes $ nix path-info -r $(type -P ls) /nix/store/vfilzcp8a467w3p0mp54ybq6bdzb8w49-coreutils-8.32 /nix/store/5d821pjgzb90lw4zbg6xwxs7llm335wr-libunistring-0.9.10 ... /nix/store/mrv4y369nw6hg4pw8d9p9bfdxj9pjw0x-acl-2.3.0 /nix/store/vfilzcp8a467w3p0mp54ybq6bdzb8w49-coreutils-8.32 Also, output the paths in topologically sorted order like we used to. --- src/libcmd/command.cc | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/libcmd/command.cc b/src/libcmd/command.cc index 2b9902677..0d61e12d0 100644 --- a/src/libcmd/command.cc +++ b/src/libcmd/command.cc @@ -120,7 +120,7 @@ void BuiltPathsCommand::run(ref store) // XXX: This only computes the store path closure, ignoring // intermediate realisations StorePathSet pathsRoots, pathsClosure; - for (auto & root: paths) { + for (auto & root : paths) { auto rootFromThis = root.outPaths(); pathsRoots.insert(rootFromThis.begin(), rootFromThis.end()); } @@ -140,12 +140,15 @@ StorePathsCommand::StorePathsCommand(bool recursive) void StorePathsCommand::run(ref store, BuiltPaths && paths) { - StorePaths storePaths; - for (auto& builtPath : paths) - for (auto& p : builtPath.outPaths()) - storePaths.push_back(p); + StorePathSet storePaths; + for (auto & builtPath : paths) + for (auto & p : builtPath.outPaths()) + storePaths.insert(p); - run(store, std::move(storePaths)); + auto sorted = store->topoSortPaths(storePaths); + std::reverse(sorted.begin(), sorted.end()); + + run(store, std::move(sorted)); } void StorePathCommand::run(ref store, std::vector && storePaths)