From ddd8fc3d28cd8e668868158049ced7fa3c8c71b8 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 29 Jun 2020 17:31:06 +0200 Subject: Add basic support for the Protected field This will be mapped to Important for the time being. --- apt-pkg/deb/deblistparser.cc | 2 ++ apt-pkg/deb/debsystem.cc | 7 ++++++- apt-pkg/deb/debsystem.h | 1 + apt-pkg/deb/dpkgpm.cc | 14 ++++++++++++++ apt-pkg/tagfile-keys.list | 1 + apt-pkg/tagfile-order.c | 3 ++- 6 files changed, 26 insertions(+), 2 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index a86f49dc0..240946529 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -318,6 +318,8 @@ bool debListParser::UsePackage(pkgCache::PkgIterator &Pkg, return false; if (Section.FindFlag(pkgTagSection::Key::Important,Pkg->Flags,pkgCache::Flag::Important) == false) return false; + if (Section.FindFlag(pkgTagSection::Key::Protected, Pkg->Flags, pkgCache::Flag::Important) == false) + return false; if (std::find(forceEssential.begin(), forceEssential.end(), Pkg.Name()) != forceEssential.end()) { diff --git a/apt-pkg/deb/debsystem.cc b/apt-pkg/deb/debsystem.cc index 7d4bf7213..eac43c3b7 100644 --- a/apt-pkg/deb/debsystem.cc +++ b/apt-pkg/deb/debsystem.cc @@ -465,9 +465,14 @@ pid_t debSystem::ExecDpkg(std::vector const &sArgs, int * const inp } /*}}}*/ bool debSystem::MultiArchSupported() const /*{{{*/ +{ + return AssertFeature("multi-arch"); +} + /*}}}*/ +bool debSystem::AssertFeature(std::string const &feature) /*{{{*/ { std::vector Args = GetDpkgBaseCommand(); - Args.push_back("--assert-multi-arch"); + Args.push_back("--assert-" + feature); pid_t const dpkgAssertMultiArch = ExecDpkg(Args, nullptr, nullptr, true); if (dpkgAssertMultiArch > 0) { diff --git a/apt-pkg/deb/debsystem.h b/apt-pkg/deb/debsystem.h index 2e5a8550c..b3d241512 100644 --- a/apt-pkg/deb/debsystem.h +++ b/apt-pkg/deb/debsystem.h @@ -45,6 +45,7 @@ class debSystem : public pkgSystem APT_HIDDEN static void DpkgChrootDirectory(); APT_HIDDEN static pid_t ExecDpkg(std::vector const &sArgs, int * const inputFd, int * const outputFd, bool const DiscardOutput); bool MultiArchSupported() const override; + static bool AssertFeature(std::string const &Feature); std::vector ArchitecturesSupported() const override; bool LockInner(OpProgress *const Progress, int timeoutSec) override; diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index ef73881c8..c496538cc 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -1416,6 +1416,15 @@ static bool ItemIsEssential(pkgDPkgPM::Item const &I) return true; return (I.Pkg->Flags & pkgCache::Flag::Essential) != 0; } +static bool ItemIsProtected(pkgDPkgPM::Item const &I) +{ + static auto const cachegen = _config->Find("pkgCacheGen::Protected"); + if (cachegen == "none" || cachegen == "native") + return true; + if (unlikely(I.Pkg.end())) + return true; + return (I.Pkg->Flags & pkgCache::Flag::Important) != 0; +} bool pkgDPkgPM::ExpandPendingCalls(std::vector &List, pkgDepCache &Cache) { { @@ -1712,6 +1721,7 @@ bool pkgDPkgPM::Go(APT::Progress::PackageManager *progress) OpenLog(); bool dpkgMultiArch = _system->MultiArchSupported(); + bool dpkgProtectedField = debSystem::AssertFeature("protected-field"); // start pty magic before the loop StartPtyMagic(); @@ -1780,6 +1790,10 @@ bool pkgDPkgPM::Go(APT::Progress::PackageManager *progress) { ADDARGC("--force-remove-essential"); } + if (dpkgProtectedField && std::any_of(I, J, ItemIsProtected)) + { + ADDARGC("--force-remove-protected"); + } ADDARGC("--remove"); break; diff --git a/apt-pkg/tagfile-keys.list b/apt-pkg/tagfile-keys.list index a979a404b..a16bc686a 100644 --- a/apt-pkg/tagfile-keys.list +++ b/apt-pkg/tagfile-keys.list @@ -48,6 +48,7 @@ Package-Revision Package-Type Pre-Depends Priority +Protected Provides Recommended Recommends diff --git a/apt-pkg/tagfile-order.c b/apt-pkg/tagfile-order.c index 4c2068c00..bb199b32e 100644 --- a/apt-pkg/tagfile-order.c +++ b/apt-pkg/tagfile-order.c @@ -11,7 +11,7 @@ static const char *iTFRewritePackageOrder[] = { "Architecture", "Subarchitecture", // Used only by d-i "Version", - "Revision", // Obsolete (warning in dpkg) + "Revision", // Obsolete (warning in dpkg) "Package-Revision", // Obsolete (warning in dpkg) "Package_Revision", // Obsolete (warning in dpkg) "Kernel-Version", // Used only by d-i @@ -23,6 +23,7 @@ static const char *iTFRewritePackageOrder[] = { "Priority", "Class", // dpkg nickname for Priority "Build-Essential", + "Protected", "Essential", "Installer-Menu-Item", // Used only by d-i "Section", -- cgit v1.2.3