summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2025-02-17 21:33:30 +0100
committerJulian Andres Klode <julian.klode@canonical.com>2025-02-18 10:56:45 +0100
commite8b240eb3aab7e2584e245f03700ede30a3fc23a (patch)
tree4f191f0a9b367adfdbd5bb011c3048486dee1a7a /apt-pkg/contrib
parentf82dcd7e4ebb3f70d28e9feb3621676f8c0cc024 (diff)
refactor: Deduplicate and Move SectionInSubTree to Configuration
Deduplicate the copies in a central one, mark it unavailable to external users.
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r--apt-pkg/contrib/configuration.cc33
-rw-r--r--apt-pkg/contrib/configuration.h3
2 files changed, 36 insertions, 0 deletions
diff --git a/apt-pkg/contrib/configuration.cc b/apt-pkg/contrib/configuration.cc
index 28cf3e480..cf72aa3d7 100644
--- a/apt-pkg/contrib/configuration.cc
+++ b/apt-pkg/contrib/configuration.cc
@@ -1226,3 +1226,36 @@ bool Configuration::MatchAgainstConfig::Match(char const * str) const
return false;
}
/*}}}*/
+// helper for Install-Recommends-Sections and Never-MarkAuto-Sections /*{{{*/
+static bool ConfigValueInSubTree(Configuration *config, const char *SubTree, std::string_view const needle)
+{
+ if (needle.empty())
+ return false;
+ Configuration::Item const *Opts = config->Tree(SubTree);
+ if (Opts != nullptr && Opts->Child != nullptr)
+ {
+ Opts = Opts->Child;
+ for (; Opts != nullptr; Opts = Opts->Next)
+ {
+ if (Opts->Value.empty())
+ continue;
+ if (needle == Opts->Value)
+ return true;
+ }
+ }
+ return false;
+}
+bool Configuration::SectionInSubTree(char const *const SubTree, std::string_view Needle)
+{
+ if (ConfigValueInSubTree(this, SubTree, Needle))
+ return true;
+ auto const sub = Needle.rfind('/');
+ if (sub == std::string_view::npos)
+ {
+ std::string special{"/"};
+ special.append(Needle);
+ return ConfigValueInSubTree(this, SubTree, special);
+ }
+ return ConfigValueInSubTree(this, SubTree, Needle.substr(sub + 1));
+}
+ /*}}}*/
diff --git a/apt-pkg/contrib/configuration.h b/apt-pkg/contrib/configuration.h
index 4a21d977b..30a1cbf43 100644
--- a/apt-pkg/contrib/configuration.h
+++ b/apt-pkg/contrib/configuration.h
@@ -117,6 +117,9 @@ class APT_PUBLIC Configuration
void Dump(std::ostream& str, char const * const root,
char const * const format, bool const emptyValue);
+#ifdef APT_COMPILING_APT
+ bool SectionInSubTree(char const *const SubTree, std::string_view Needle);
+#endif
explicit Configuration(const Item *Root);
Configuration();
~Configuration();