From 8aeb07448c09375c730c76a6baf31303b129bb96 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 29 Jan 2023 16:54:39 +0100 Subject: Have values in Section config trees refer to them in all components Hard coding each and every component is not only boring but given that everyone is free to add or use more we end up in situations in which apt behaves differently for the same binary package just because metadata said it is in different components (e.g. non-free vs. non-free-firmware). It is also probably not what the casual user would expect. So we instead treat a value without a component as if it applies for all of them. The previous behaviour can be restored by prefixing the value with "/" as in the component is not defined. In an ideal world we would probably use "*/foo" for the new default instead of changing the behaviour for "foo", but it seems rather unlikely that the old behaviour is actually desired. All existing values were duplicated for all (previously) known components in Debian and Ubuntu. --- cmdline/apt-mark.cc | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-mark.cc b/cmdline/apt-mark.cc index 5eaed2c71..46d3ca5b8 100644 --- a/cmdline/apt-mark.cc +++ b/cmdline/apt-mark.cc @@ -140,24 +140,37 @@ static bool DoMarkAuto(CommandLine &CmdL) } /*}}}*/ // helper for Install-Recommends-Sections and Never-MarkAuto-Sections /*{{{*/ -static bool -ConfigValueInSubTree(const char *SubTree, const char *needle) +// FIXME: Copied verbatim from apt-pkg/depcache.cc +static bool ConfigValueInSubTree(const char* SubTree, std::string_view const needle) { - // copied from depcache.cc - Configuration::Item const *Opts; - Opts = _config->Tree(SubTree); - if (Opts != 0 && Opts->Child != 0) + if (needle.empty()) + return false; + Configuration::Item const *Opts = _config->Tree(SubTree); + if (Opts != nullptr && Opts->Child != nullptr) { Opts = Opts->Child; - for (; Opts != 0; Opts = Opts->Next) + for (; Opts != nullptr; Opts = Opts->Next) { - if (Opts->Value.empty() == true) + if (Opts->Value.empty()) continue; - if (strcmp(needle, Opts->Value.c_str()) == 0) + if (needle == Opts->Value) return true; } } return false; +} +static bool SectionInSubTree(char const * const SubTree, std::string_view Needle) +{ + if (ConfigValueInSubTree(SubTree, Needle)) + return true; + auto const sub = Needle.find('/'); + if (sub == std::string_view::npos) + { + std::string special{"/"}; + special.append(Needle); + return ConfigValueInSubTree(SubTree, special); + } + return ConfigValueInSubTree(SubTree, Needle.substr(sub + 1)); } /*}}}*/ /* DoMinimize - minimize manually installed {{{*/ @@ -179,7 +192,7 @@ static bool DoMinimize(CommandLine &CmdL) auto ver = pkg.CurrentVer(); return ver.end() == false && ((*DepCache)[pkg].Flags & pkgCache::Flag::Auto) == 0 && ver->Section != 0 && - ConfigValueInSubTree("APT::Never-MarkAuto-Sections", ver.Section()); + SectionInSubTree("APT::Never-MarkAuto-Sections", ver.Section()); }; APT::PackageSet roots; -- cgit v1.2.3-70-g09d2