diff options
-rw-r--r-- | apt-pkg/deb/deblistparser.cc | 16 | ||||
-rw-r--r-- | apt-pkg/deb/deblistparser.h | 4 | ||||
-rw-r--r-- | doc/examples/configure-index | 7 | ||||
-rwxr-xr-x | test/integration/test-bug-767891-force-essential-important | 100 |
4 files changed, 122 insertions, 5 deletions
diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index 99e806470..0f9fe310f 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -50,8 +50,18 @@ static const debListParser::WordList PrioList[] = { in Step(), if no Architecture is given we will accept every arch we would accept in general with checkArchitecture() */ debListParser::debListParser(FileFd *File) : - pkgCacheListParser(), d(NULL), Tags(File) + pkgCacheListParser(), Tags(File) { + // this dance allows an empty value to override the default + if (_config->Exists("pkgCacheGen::ForceEssential")) + { + forceEssential = _config->FindVector("pkgCacheGen::ForceEssential"); + if (forceEssential.empty() == false && _config->Find("pkgCacheGen::ForceEssential").empty()) + forceEssential.emplace_back("apt"); + } + else + forceEssential.emplace_back("apt"); + forceImportant = _config->FindVector("pkgCacheGen::ForceImportant"); } /*}}}*/ // ListParser::Package - Return the package name /*{{{*/ @@ -311,7 +321,7 @@ bool debListParser::UsePackage(pkgCache::PkgIterator &Pkg, if (Section.FindFlag("Important",Pkg->Flags,pkgCache::Flag::Important) == false) return false; - if (strcmp(Pkg.Name(),"apt") == 0) + if (std::find(forceEssential.begin(), forceEssential.end(), Pkg.Name()) != forceEssential.end()) { if ((essential == "native" && Pkg->Arch != 0 && myArch == Pkg.Arch()) || essential == "all") @@ -319,6 +329,8 @@ bool debListParser::UsePackage(pkgCache::PkgIterator &Pkg, else Pkg->Flags |= pkgCache::Flag::Important; } + else if (std::find(forceImportant.begin(), forceImportant.end(), Pkg.Name()) != forceImportant.end()) + Pkg->Flags |= pkgCache::Flag::Important; if (ParseStatus(Pkg,Ver) == false) return false; diff --git a/apt-pkg/deb/deblistparser.h b/apt-pkg/deb/deblistparser.h index a78312f9d..102cd62aa 100644 --- a/apt-pkg/deb/deblistparser.h +++ b/apt-pkg/deb/deblistparser.h @@ -43,8 +43,8 @@ class APT_HIDDEN debListParser : public pkgCacheListParser #endif private: - /** \brief dpointer placeholder (for later in case we need it) */ - void * const d; + std::vector<std::string> forceEssential; + std::vector<std::string> forceImportant; protected: pkgTagFile Tags; diff --git a/doc/examples/configure-index b/doc/examples/configure-index index dc579c394..2d0fb6c64 100644 --- a/doc/examples/configure-index +++ b/doc/examples/configure-index @@ -461,7 +461,12 @@ Debug RunScripts "false"; // debug invocation of external scripts } -pkgCacheGen::Essential "native"; // other modes: all, none, installed +pkgCacheGen +{ + Essential "native"; // other modes: all, none, installed + ForceEssential { "apt"; }; + ForceImportant ""; +} /* Whatever you do, do not use this configuration file!! Take out ONLY the portions you need! */ diff --git a/test/integration/test-bug-767891-force-essential-important b/test/integration/test-bug-767891-force-essential-important new file mode 100755 index 000000000..7a23de557 --- /dev/null +++ b/test/integration/test-bug-767891-force-essential-important @@ -0,0 +1,100 @@ +#!/bin/sh +set -e + +TESTDIR="$(readlink -f "$(dirname "$0")")" +. "$TESTDIR/framework" +setupenvironment +configarchitecture 'amd64' 'i386' + +insertinstalledpackage 'apt' 'amd64' '1' +insertinstalledpackage 'foo' 'amd64,i386' '1' 'Multi-Arch: same' +insertinstalledpackage 'bar' 'amd64' '1' 'Provides: foo' + +insertpackage 'unstable' 'foo2' 'amd64,i386' '1' 'Multi-Arch: same' + +setupaptarchive + +rm -f rootdir/var/cache/apt/*.bin +testsuccessequal 'Reading package lists... +Building dependency tree... +The following packages will be REMOVED: + apt* bar* foo* foo:i386* +WARNING: The following essential packages will be removed. +This should NOT be done unless you know exactly what you are doing! + apt +0 upgraded, 0 newly installed, 4 to remove and 0 not upgraded. +Purg apt [1] +Purg bar [1] +Purg foo [1] +Purg foo:i386 [1]' apt purge apt foo foo:i386 bar -s + +rm -f rootdir/var/cache/apt/*.bin +testsuccessequal 'Reading package lists... +Building dependency tree... +The following packages will be REMOVED: + apt* bar* foo* foo:i386* +0 upgraded, 0 newly installed, 4 to remove and 0 not upgraded. +Purg apt [1] +Purg bar [1] +Purg foo [1] +Purg foo:i386 [1]' apt purge apt foo foo:i386 bar -s -o pkgCacheGen::ForceEssential='' + +msgmsg 'foo:i386 got the Important flag' +rm -f rootdir/var/cache/apt/*.bin +testsuccessequal 'Reading package lists... +Building dependency tree... +The following packages will be REMOVED: + apt* bar* foo* foo:i386* +WARNING: The following essential packages will be removed. +This should NOT be done unless you know exactly what you are doing! + foo foo:i386 +0 upgraded, 0 newly installed, 4 to remove and 0 not upgraded. +Purg apt [1] +Purg bar [1] +Purg foo [1] +Purg foo:i386 [1]' apt purge apt foo foo:i386 bar -s -o pkgCacheGen::ForceEssential='foo' + +rm -f rootdir/var/cache/apt/*.bin +testsuccessequal 'Reading package lists... +Building dependency tree... +The following packages will be REMOVED: + apt* bar* foo* foo:i386* +WARNING: The following essential packages will be removed. +This should NOT be done unless you know exactly what you are doing! + apt foo foo:i386 +0 upgraded, 0 newly installed, 4 to remove and 0 not upgraded. +Purg apt [1] +Purg bar [1] +Purg foo [1] +Purg foo:i386 [1]' apt purge apt foo foo:i386 bar -s -o pkgCacheGen::ForceEssential::='foo' + +msgmsg 'essentials only from native' +rm -f rootdir/var/cache/apt/*.bin +testsuccessequal 'Reading package lists... +Building dependency tree... +Calculating upgrade... +The following NEW packages will be installed: + foo2 +0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. +Inst foo2 (1 unstable [amd64]) +Conf foo2 (1 unstable [amd64])' apt full-upgrade -s -o pkgCacheGen::ForceEssential::='foo2' + +msgmsg 'important only effects installed' +rm -f rootdir/var/cache/apt/*.bin +testsuccessequal 'Reading package lists... +Building dependency tree... +The following packages will be REMOVED: + apt* bar* foo* foo:i386* +WARNING: The following essential packages will be removed. +This should NOT be done unless you know exactly what you are doing! + apt foo foo:i386 +0 upgraded, 0 newly installed, 4 to remove and 0 not upgraded. +Purg apt [1] +Purg bar [1] +Purg foo [1] +Purg foo:i386 [1]' apt purge apt foo foo:i386 bar -s -o pkgCacheGen::ForceImportant::='foo' +rm -f rootdir/var/cache/apt/*.bin +testsuccessequal 'Reading package lists... +Building dependency tree... +Calculating upgrade... +0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.' apt full-upgrade -s -o pkgCacheGen::ForceImportant::='foo2' |