From cef8c169b1d100685d7c7b7bfb921eaa43b5521b Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 2 May 2017 15:28:35 +0200 Subject: Fix "nix ... --all" When "--all" is used, we should not fill in a default installable. --- src/nix/command.hh | 6 +++++- src/nix/installables.cc | 22 +++++++++++----------- 2 files changed, 16 insertions(+), 12 deletions(-) (limited to 'src/nix') diff --git a/src/nix/command.hh b/src/nix/command.hh index dc7b2637d66a..cf0097d78926 100644 --- a/src/nix/command.hh +++ b/src/nix/command.hh @@ -78,7 +78,7 @@ struct InstallablesCommand : virtual Args, StoreCommand = import ...; bla = import ...; }’. */ Value * getSourceExpr(EvalState & state); - std::vector> parseInstallables(ref store, Strings installables); + std::vector> parseInstallables(ref store, Strings ss); PathSet buildInstallables(ref store, bool dryRun); @@ -86,6 +86,8 @@ struct InstallablesCommand : virtual Args, StoreCommand void prepare() override; + virtual bool useDefaultInstallables() { return true; } + private: Strings _installables; @@ -112,6 +114,8 @@ public: virtual void run(ref store, Paths storePaths) = 0; void run(ref store) override; + + bool useDefaultInstallables() override { return !all; } }; typedef std::map> Commands; diff --git a/src/nix/installables.cc b/src/nix/installables.cc index 57580049f25f..4756fc44bba7 100644 --- a/src/nix/installables.cc +++ b/src/nix/installables.cc @@ -177,21 +177,21 @@ struct InstallableAttrPath : Installable std::string attrRegex = R"([A-Za-z_][A-Za-z0-9-_+]*)"; static std::regex attrPathRegex(fmt(R"(%1%(\.%1%)*)", attrRegex)); -std::vector> InstallablesCommand::parseInstallables(ref store, Strings installables) +std::vector> InstallablesCommand::parseInstallables(ref store, Strings ss) { std::vector> result; - if (installables.empty()) { + if (ss.empty() && useDefaultInstallables()) { if (file == "") file = "."; - installables = Strings{""}; + ss = Strings{""}; } - for (auto & installable : installables) { + for (auto & s : ss) { - if (installable.find("/") != std::string::npos) { + if (s.find("/") != std::string::npos) { - auto path = store->toStorePath(store->followLinksToStore(installable)); + auto path = store->toStorePath(store->followLinksToStore(s)); if (store->isStorePath(path)) { if (isDerivation(path)) @@ -201,14 +201,14 @@ std::vector> InstallablesCommand::parseInstallables } } - else if (installable.compare(0, 1, "(") == 0) - result.push_back(std::make_shared(*this, installable)); + else if (s.compare(0, 1, "(") == 0) + result.push_back(std::make_shared(*this, s)); - else if (installable == "" || std::regex_match(installable, attrPathRegex)) - result.push_back(std::make_shared(*this, installable)); + else if (s == "" || std::regex_match(s, attrPathRegex)) + result.push_back(std::make_shared(*this, s)); else - throw UsageError("don't know what to do with argument ‘%s’", installable); + throw UsageError("don't know what to do with argument ‘%s’", s); } return result; -- cgit 1.4.1