summaryrefslogtreecommitdiff
path: root/cmdline
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2023-01-29 16:54:39 +0100
committerDavid Kalnischkies <david@kalnischkies.de>2023-01-30 00:55:05 +0100
commit8aeb07448c09375c730c76a6baf31303b129bb96 (patch)
tree45e6007657f9a1ba3b0d80c7e9c4a74da2f31aa4 /cmdline
parent0dd4e0b4caeeb3e943a993db79c416d491c469cd (diff)
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 "<undefined>/" 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.
Diffstat (limited to 'cmdline')
-rw-r--r--cmdline/apt-mark.cc33
1 files changed, 23 insertions, 10 deletions
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,25 +140,38 @@ 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{"<undefined>/"};
+ special.append(Needle);
+ return ConfigValueInSubTree(SubTree, special);
+ }
+ return ConfigValueInSubTree(SubTree, Needle.substr(sub + 1));
+}
/*}}}*/
/* DoMinimize - minimize manually installed {{{*/
/* Traverses dependencies of meta packages and marks them as manually
@@ -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;