diff options
| author | David Kalnischkies <david@kalnischkies.de> | 2023-01-29 16:54:39 +0100 |
|---|---|---|
| committer | David Kalnischkies <david@kalnischkies.de> | 2023-01-30 00:55:05 +0100 |
| commit | 8aeb07448c09375c730c76a6baf31303b129bb96 (patch) | |
| tree | 45e6007657f9a1ba3b0d80c7e9c4a74da2f31aa4 /apt-pkg/depcache.cc | |
| parent | 0dd4e0b4caeeb3e943a993db79c416d491c469cd (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 'apt-pkg/depcache.cc')
| -rw-r--r-- | apt-pkg/depcache.cc | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc index bc5843153..b19d180a4 100644 --- a/apt-pkg/depcache.cc +++ b/apt-pkg/depcache.cc @@ -67,24 +67,38 @@ class DefaultRootSetFunc2 : public pkgDepCache::DefaultRootSetFunc /*}}}*/ // helper for Install-Recommends-Sections and Never-MarkAuto-Sections /*{{{*/ -static bool -ConfigValueInSubTree(const char* SubTree, const char *needle) +// FIXME: Has verbatim copy in cmdline/apt-mark.cc +static bool ConfigValueInSubTree(const char* SubTree, std::string_view const needle) { - 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)); +} /*}}}*/ pkgDepCache::ActionGroup::ActionGroup(pkgDepCache &cache) : /*{{{*/ d(NULL), cache(cache), released(false) @@ -1050,7 +1064,7 @@ bool pkgDepCache::MarkDelete(PkgIterator const &Pkg, bool rPurge, // We do not check for or-groups here as we don't know which package takes care of // providing the feature the user likes e.g.: browser1 | browser2 | browser3 // Temporary removals are effected by this as well, which is bad, but unlikely in practice - bool const PinNeverMarkAutoSection = (PV->Section != 0 && ConfigValueInSubTree("APT::Never-MarkAuto-Sections", PV.Section())); + bool const PinNeverMarkAutoSection = (PV->Section != 0 && SectionInSubTree("APT::Never-MarkAuto-Sections", PV.Section())); if (PinNeverMarkAutoSection) { for (DepIterator D = PV.DependsList(); D.end() != true; ++D) @@ -1761,8 +1775,8 @@ bool pkgDepCache::MarkInstall(PkgIterator const &Pkg, bool AutoInst, VerIterator const CurVer = Pkg.CurrentVer(); if (not CurVer.end() && CurVer->Section != 0 && strcmp(CurVer.Section(), PV.Section()) != 0) { - bool const CurVerInMoveSection = ConfigValueInSubTree("APT::Move-Autobit-Sections", CurVer.Section()); - bool const InstVerInMoveSection = ConfigValueInSubTree("APT::Move-Autobit-Sections", PV.Section()); + bool const CurVerInMoveSection = SectionInSubTree("APT::Move-Autobit-Sections", CurVer.Section()); + bool const InstVerInMoveSection = SectionInSubTree("APT::Move-Autobit-Sections", PV.Section()); return (not CurVerInMoveSection && InstVerInMoveSection); } return false; @@ -2254,7 +2268,7 @@ bool pkgDepCache::Policy::IsImportantDep(DepIterator const &Dep) const // FIXME: this is a meant as a temporary solution until the // recommends are cleaned up const char *sec = Dep.ParentVer().Section(); - if (sec && ConfigValueInSubTree("APT::Install-Recommends-Sections", sec)) + if (sec && SectionInSubTree("APT::Install-Recommends-Sections", sec)) return true; } else if(Dep->Type == pkgCache::Dep::Suggests) |
