diff options
-rw-r--r-- | apt-pkg/depcache.cc | 38 | ||||
-rw-r--r-- | cmdline/apt-mark.cc | 33 | ||||
-rw-r--r-- | debian/apt.conf.autoremove | 12 | ||||
-rwxr-xr-x | test/integration/test-apt-move-and-forget-manual-sections | 45 | ||||
-rwxr-xr-x | test/integration/test-apt-never-markauto-sections | 3 |
5 files changed, 95 insertions, 36 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) 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; diff --git a/debian/apt.conf.autoremove b/debian/apt.conf.autoremove index 90ee8908b..10438e848 100644 --- a/debian/apt.conf.autoremove +++ b/debian/apt.conf.autoremove @@ -22,23 +22,11 @@ APT Never-MarkAuto-Sections { "metapackages"; - "contrib/metapackages"; - "non-free/metapackages"; - "restricted/metapackages"; - "universe/metapackages"; - "multiverse/metapackages"; "tasks"; - "contrib/tasks"; - "non-free/tasks"; }; Move-Autobit-Sections { "oldlibs"; - "contrib/oldlibs"; - "non-free/oldlibs"; - "restricted/oldlibs"; - "universe/oldlibs"; - "multiverse/oldlibs"; }; }; diff --git a/test/integration/test-apt-move-and-forget-manual-sections b/test/integration/test-apt-move-and-forget-manual-sections index 4617abab3..ab90be0c0 100755 --- a/test/integration/test-apt-move-and-forget-manual-sections +++ b/test/integration/test-apt-move-and-forget-manual-sections @@ -11,15 +11,18 @@ testsuccess grep '^oldlibs$' move-autobit.sections buildsimplenativepackage 'libabc' 'native' '1' 'stable' '' '' 'libs' buildsimplenativepackage 'libabc' 'native' '2' 'unstable' 'Depends: libdef' '' 'oldlibs' +buildsimplenativepackage 'libzoo' 'native' '1' 'stable' '' '' 'libs' +buildsimplenativepackage 'libzoo' 'native' '2' 'unstable' 'Depends: libdef' '' 'non-free/oldlibs' buildsimplenativepackage 'libdef' 'native' '1' 'unstable' '' '' 'libs' setupaptarchive testmarkedauto testmarkedmanual +msgmsg 'Move bit on install of replacement' testsuccess aptget install libabc/stable -y testdpkginstalled 'libabc' -testdpkgnotinstalled 'libdef' +testdpkgnotinstalled 'libdef' 'libzoo' testmarkedmanual 'libabc' testmarkedauto @@ -29,3 +32,43 @@ testdpkginstalled 'libabc' 'libdef' testmarkedauto 'libabc' testmarkedmanual 'libdef' + +testsuccess apt autopurge -y +testdpkgnotinstalled 'libabc' 'libzoo' + +msgmsg 'Do not move bit if replacement is already installed' +testsuccess aptget install libzoo/stable -y +testdpkginstalled 'libzoo' + +testmarkedmanual 'libzoo' 'libdef' +testmarkedauto + +testsuccess aptmark auto libdef +testmarkedauto 'libdef' + +testsuccess aptget dist-upgrade -y +testdpkginstalled 'libzoo' 'libdef' + +testmarkedmanual 'libzoo' +testmarkedauto 'libdef' + +testsuccess apt autopurge -y libzoo- +testdpkgnotinstalled 'libabc' 'libzoo' 'libdef' + +msgmsg 'Move bit on install of replacement (subsection)' +testfailure grep '^non-free/oldlibs$' move-autobit.sections +testsuccess aptget install libzoo/stable -y +testdpkginstalled 'libzoo' +testdpkgnotinstalled 'libdef' 'libabc' + +testmarkedmanual 'libzoo' +testmarkedauto + +testsuccess aptget dist-upgrade -y +testdpkginstalled 'libzoo' 'libdef' + +testmarkedauto 'libzoo' +testmarkedmanual 'libdef' + +testsuccess apt autopurge -y +testdpkgnotinstalled 'libabc' 'libzoo' diff --git a/test/integration/test-apt-never-markauto-sections b/test/integration/test-apt-never-markauto-sections index a77d6b22b..b47966e75 100755 --- a/test/integration/test-apt-never-markauto-sections +++ b/test/integration/test-apt-never-markauto-sections @@ -8,12 +8,13 @@ configarchitecture 'amd64' 'i386' aptconfig dump --no-empty --format '%v%n' APT::Never-MarkAuto-Sections > nevermarkauto.sections testsuccess grep '^metapackages$' nevermarkauto.sections +testfailure grep '^universe/metapackages$' nevermarkauto.sections buildsimplenativepackage 'mydesktop' 'all' '1' 'unstable' 'Depends: mydesktop-core, foreignpkg Recommends: notavailable' '' 'metapackages' buildsimplenativepackage 'mydesktop-core' 'amd64' '1' 'unstable' 'Depends: bad-texteditor | texteditor, browser (>= 42), nosection, foreignpkg Recommends: notavailable -Multi-Arch: foreign' '' 'metapackages' +Multi-Arch: foreign' '' 'universe/metapackages' buildsimplenativepackage 'browser' 'amd64' '41' 'stable' buildsimplenativepackage 'browser' 'amd64' '42' 'unstable' buildsimplenativepackage 'texteditor' 'amd64' '1' 'stable' |