summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2020-06-29 17:31:06 +0200
committerJulian Andres Klode <julian.klode@canonical.com>2020-06-29 17:32:17 +0200
commitddd8fc3d28cd8e668868158049ced7fa3c8c71b8 (patch)
treeac3241a7d46070a3be4f7d09dd913fd3855dea3f
parentb5faca7a90e1aa25adb8ee69b979d1f4bd7e8d78 (diff)
Add basic support for the Protected field
This will be mapped to Important for the time being.
-rw-r--r--apt-pkg/deb/deblistparser.cc2
-rw-r--r--apt-pkg/deb/debsystem.cc7
-rw-r--r--apt-pkg/deb/debsystem.h1
-rw-r--r--apt-pkg/deb/dpkgpm.cc14
-rw-r--r--apt-pkg/tagfile-keys.list1
-rw-r--r--apt-pkg/tagfile-order.c3
-rw-r--r--doc/examples/configure-index1
-rwxr-xr-xtest/integration/test-dpkg-protected20
8 files changed, 47 insertions, 2 deletions
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
@@ -466,8 +466,13 @@ pid_t debSystem::ExecDpkg(std::vector<std::string> const &sArgs, int * const inp
/*}}}*/
bool debSystem::MultiArchSupported() const /*{{{*/
{
+ return AssertFeature("multi-arch");
+}
+ /*}}}*/
+bool debSystem::AssertFeature(std::string const &feature) /*{{{*/
+{
std::vector<std::string> 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<std::string> const &sArgs, int * const inputFd, int * const outputFd, bool const DiscardOutput);
bool MultiArchSupported() const override;
+ static bool AssertFeature(std::string const &Feature);
std::vector<std::string> 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<Item> &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",
diff --git a/doc/examples/configure-index b/doc/examples/configure-index
index 47715a9e1..f04e32502 100644
--- a/doc/examples/configure-index
+++ b/doc/examples/configure-index
@@ -558,6 +558,7 @@ Debug
pkgCacheGen
{
Essential "<STRING>"; // native,all, none, installed
+ Protected "<STRING>"; // native,all, none, installed
ForceEssential "<STRING_OR_LIST>"; // package names
ForceImportant "<LIST>"; // package names
};
diff --git a/test/integration/test-dpkg-protected b/test/integration/test-dpkg-protected
new file mode 100755
index 000000000..3d0994d89
--- /dev/null
+++ b/test/integration/test-dpkg-protected
@@ -0,0 +1,20 @@
+#!/bin/sh
+set -e
+
+TESTDIR="$(readlink -f "$(dirname "$0")")"
+. "$TESTDIR/framework"
+setupenvironment
+configarchitecture 'amd64'
+
+insertinstalledpackage 'protected-package' 'native' '1' 'Protected: yes'
+
+setupaptarchive
+
+
+if dpkg --assert-protected-field 2>/dev/null; then
+ testsuccess aptget remove protected-package "$@" -o Debug::pkgDpkgPm=1 -y --allow-remove-essential
+ cp rootdir/tmp/testsuccess.output rootdir/tmp/output
+ testsuccess grep -- '--force-remove-protected' rootdir/tmp/output
+else
+ msgskip "dpkg does not support protected field"
+fi