From d6f5da51d3ae11c6771c68ebb65e7a560af167b5 Mon Sep 17 00:00:00 2001 From: Bob van der Linden Date: Wed, 28 Feb 2024 22:33:37 +0100 Subject: [PATCH] profile: match on package name instead of regex --- src/nix/profile.cc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/nix/profile.cc b/src/nix/profile.cc index 41dcccc50..d79f1158b 100644 --- a/src/nix/profile.cc +++ b/src/nix/profile.cc @@ -457,6 +457,7 @@ enum MatcherType { Regex, StorePath, + Name, }; struct Matcher @@ -489,6 +490,16 @@ Matcher createStorePathMatcher(const nix::StorePath & storePath) }; } +Matcher createNameMatcher(const std::string & name) { + return { + .type = MatcherType::Name, + .title = fmt("Package name '%s'", name), + .matches = [name](const std::string &elementName, const ProfileElement & element) { + return elementName == name; + } + }; +} + class MixProfileElementMatchers : virtual Args, virtual StoreCommand { std::vector _matchers; @@ -507,7 +518,7 @@ public: } else if (getStore()->isStorePath(arg)) { _matchers.push_back(createStorePathMatcher(getStore()->parseStorePath(arg))); } else { - _matchers.push_back(createRegexMatcher(arg)); + _matchers.push_back(createNameMatcher(arg)); } } }}