From 9106d7c9692e91622a828f382b85fe592bfec81d Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 21 Aug 2015 19:59:33 +0200 Subject: just-in-time removal of broken essential packages We deal with Conflicts in SmartUnpack in pretty much the same way, but Breaks weren't handled in SmartConfigure so that the remove was sheduled after the configuration of the package breaking the to-be-removed. Closes: 796070 --- apt-pkg/packagemanager.cc | 41 ++++++++++++- apt-pkg/packagemanager.h | 1 + test/integration/skip-bug-796070-downgrade | 67 ---------------------- test/integration/test-bug-796070-downgrade-realpkg | 23 ++++++++ .../integration/test-bug-796070-downgrade-simulate | 67 ++++++++++++++++++++++ 5 files changed, 129 insertions(+), 70 deletions(-) delete mode 100755 test/integration/skip-bug-796070-downgrade create mode 100755 test/integration/test-bug-796070-downgrade-realpkg create mode 100755 test/integration/test-bug-796070-downgrade-simulate diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index 06ec986ed..ceeb60a03 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -268,6 +268,33 @@ bool pkgPackageManager::CheckRConflicts(PkgIterator Pkg,DepIterator D, return true; } /*}}}*/ +// PM::CheckRBreaks - Look for reverse breaks /*{{{*/ +bool pkgPackageManager::CheckRBreaks(PkgIterator const &Pkg, DepIterator D, + const char * const Ver) +{ + for (;D.end() == false; ++D) + { + if (D->Type != pkgCache::Dep::DpkgBreaks) + continue; + + PkgIterator const DP = D.ParentPkg(); + if (Cache[DP].Delete() == false) + continue; + + // Ignore self conflicts, ignore conflicts from irrelevant versions + if (D.IsIgnorable(Pkg) || D.ParentVer() != DP.CurrentVer()) + continue; + + if (Cache.VS().CheckDep(Ver, D->CompareOp, D.TargetVer()) == false) + continue; + + // no earlyremove() here as user has already agreed to the permanent removal + if (SmartRemove(DP) == false) + return _error->Error("Internal Error, Could not early remove %s (%d)",DP.FullName().c_str(), 4); + } + return true; +} + /*}}}*/ // PM::ConfigureAll - Run the all out configuration /*{{{*/ // --------------------------------------------------------------------- /* This configures every package. It is assumed they are all unpacked and @@ -561,6 +588,14 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth) if (Bad == true) return _error->Error(_("Could not configure '%s'. "),Pkg.FullName().c_str()); + // Check for reverse conflicts. + if (CheckRBreaks(Pkg,Pkg.RevDependsList(), instVer.VerStr()) == false) + return false; + + for (PrvIterator P = instVer.ProvidesList(); P.end() == false; ++P) + if (Pkg->Group != P.OwnerPkg()->Group) + CheckRBreaks(Pkg,P.ParentPkg().RevDependsList(),P.ProvideVersion()); + if (PkgLoop) return true; static std::string const conf = _config->Find("PackageManager::Configure","all"); @@ -847,7 +882,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c clog << OutputInDepth(Depth) << "Because of conflict knot, removing " << ConflictPkg.FullName() << " temporarily" << endl; } if (EarlyRemove(ConflictPkg, &End) == false) - return _error->Error("Internal Error, Could not early remove %s (2)",ConflictPkg.FullName().c_str()); + return _error->Error("Internal Error, Could not early remove %s (%d)",ConflictPkg.FullName().c_str(), 3); SomethingBad = true; continue; } @@ -889,7 +924,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c if (Debug) clog << OutputInDepth(Depth) << "So temprorary remove/deconfigure " << ConflictPkg.FullName() << " to satisfy " << End << endl; if (EarlyRemove(ConflictPkg, &End) == false) - return _error->Error("Internal Error, Could not early remove %s (2)",ConflictPkg.FullName().c_str()); + return _error->Error("Internal Error, Could not early remove %s (%d)",ConflictPkg.FullName().c_str(), 2); } } else @@ -901,7 +936,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c clog << OutputInDepth(Depth) << "Removing " << ConflictPkg.FullName() << " now to avoid " << End << endl; // no earlyremove() here as user has already agreed to the permanent removal if (SmartRemove(Pkg) == false) - return _error->Error("Internal Error, Could not early remove %s (1)",ConflictPkg.FullName().c_str()); + return _error->Error("Internal Error, Could not early remove %s (%d)",ConflictPkg.FullName().c_str(), 1); } } } diff --git a/apt-pkg/packagemanager.h b/apt-pkg/packagemanager.h index 8de6ab3ad..e4d20fff4 100644 --- a/apt-pkg/packagemanager.h +++ b/apt-pkg/packagemanager.h @@ -76,6 +76,7 @@ class pkgPackageManager : protected pkgCache::Namespace void ImmediateAdd(PkgIterator P, bool UseInstallVer, unsigned const int &Depth = 0); virtual OrderResult OrderInstall(); bool CheckRConflicts(PkgIterator Pkg,DepIterator Dep,const char *Ver); + bool CheckRBreaks(PkgIterator const &Pkg,DepIterator Dep,const char * const Ver); bool CreateOrderList(); // Analysis helpers diff --git a/test/integration/skip-bug-796070-downgrade b/test/integration/skip-bug-796070-downgrade deleted file mode 100755 index a435cfbf1..000000000 --- a/test/integration/skip-bug-796070-downgrade +++ /dev/null @@ -1,67 +0,0 @@ -#!/bin/sh -set -e - -TESTDIR=$(readlink -f $(dirname $0)) -. $TESTDIR/framework - -setupenvironment -configarchitecture 'i386' - -insertpackage 'unstable' 'apt' 'all' '1.0.10.1' 'Depends: libapt-pkg4.16 (>= 1.0.10.1)' -insertinstalledpackage 'libapt-pkg4.16' 'all' '1.0.10.1' 'Breaks: apt (<< 0.9.4~), libapt-inst1.5 (<< 0.9.9~)' -insertinstalledpackage 'libapt-pkg5.0' 'all' '1.1~exp9' 'Breaks: apt (<< 1.1~exp4), libapt-inst1.5 (<< 0.9.9~)' -insertinstalledpackage 'apt' 'all' '1.1~exp9' 'Depends: libapt-pkg5.0' - -insertpackage 'unstable' 'napt' 'all' '1.0.10.1' 'Depends: nlibapt-pkg4.16 (>= 1.0.10.1)' -insertinstalledpackage 'nlibapt-pkg4.16' 'all' '1.0.10.1' 'Breaks: napt (<< 0.9.4~), nlibapt-inst1.5 (<< 0.9.9~)' -insertinstalledpackage 'nlibapt-pkg5.0' 'all' '1.1~exp9' 'Breaks: napt (<< 1.1~exp4), nlibapt-inst1.5 (<< 0.9.9~)' -insertinstalledpackage 'napt' 'all' '1.1~exp9' 'Depends: nlibapt-pkg5.0' - -insertpackage 'unstable' 'eapt' 'all' '1.0.10.1' 'Depends: elibapt-pkg4.16 (>= 1.0.10.1) -Essential: yes' -insertinstalledpackage 'elibapt-pkg4.16' 'all' '1.0.10.1' 'Breaks: eapt (<< 0.9.4~), elibapt-inst1.5 (<< 0.9.9~)' -insertinstalledpackage 'elibapt-pkg5.0' 'all' '1.1~exp9' 'Breaks: eapt (<< 1.1~exp4), elibapt-inst1.5 (<< 0.9.9~)' -insertinstalledpackage 'eapt' 'all' '1.1~exp9' 'Depends: elibapt-pkg5.0 -Essential: yes' - - -setupaptarchive - - -# Check with a normal package -testsuccessequal 'Reading package lists... -Building dependency tree... -The following packages will be REMOVED: - nlibapt-pkg5.0 -The following packages will be DOWNGRADED: - napt -0 upgraded, 0 newly installed, 1 downgraded, 1 to remove and 0 not upgraded. -Remv nlibapt-pkg5.0 [1.1~exp9] [napt:i386 ] -Inst napt [1.1~exp9] (1.0.10.1 unstable [all]) -Conf napt (1.0.10.1 unstable [all])' apt install -s napt=1.0.10.1 - - -# Check with Essential -testsuccessequal 'Reading package lists... -Building dependency tree... -The following packages will be REMOVED: - elibapt-pkg5.0 -The following packages will be DOWNGRADED: - eapt -0 upgraded, 0 newly installed, 1 downgraded, 1 to remove and 0 not upgraded. -Remv elibapt-pkg5.0 [1.1~exp9] -Inst eapt [1.1~exp9] (1.0.10.1 unstable [all]) -Conf eapt (1.0.10.1 unstable [all])' apt install -s eapt=1.0.10.1 - - -# Check with the APT name, aka essential -testsuccessequal 'Reading package lists... -Building dependency tree... -The following packages will be REMOVED: - libapt-pkg5.0 -The following packages will be DOWNGRADED: - apt -0 upgraded, 0 newly installed, 1 downgraded, 1 to remove and 0 not upgraded. -Remv libapt-pkg5.0 [1.1~exp9] -Inst apt [1.1~exp9] (1.0.10.1 unstable [all]) -Conf apt (1.0.10.1 unstable [all])' apt install -s apt=1.0.10.1 diff --git a/test/integration/test-bug-796070-downgrade-realpkg b/test/integration/test-bug-796070-downgrade-realpkg new file mode 100755 index 000000000..3ad4fda3e --- /dev/null +++ b/test/integration/test-bug-796070-downgrade-realpkg @@ -0,0 +1,23 @@ +#!/bin/sh +set -e + +TESTDIR=$(readlink -f $(dirname $0)) +. $TESTDIR/framework + +setupenvironment +configarchitecture 'i386' + +buildsimplenativepackage 'apt' 'all' '1.0.10.1' 'stable' 'Depends: libapt-pkg4.16 (>= 1.0.10.1)' +buildsimplenativepackage 'libapt-pkg4.16' 'all' '1.0.10.1' 'stable' 'Breaks: apt (<< 0.9.4~), libapt-inst1.5 (<< 0.9.9~)' +buildsimplenativepackage 'libapt-pkg5.0' 'all' '1.1~exp9' 'unstable' 'Breaks: apt (<< 1.1~exp4), libapt-inst1.5 (<< 0.9.9~)' +buildsimplenativepackage 'apt' 'all' '1.1~exp9' 'unstable' 'Depends: libapt-pkg5.0' + +setupaptarchive + +# Check with the APT name, aka essential +testsuccess aptget install apt -t stable -y +testsuccess aptget dist-upgrade -y + +testsuccess aptget install apt/stable -y --allow-downgrades -o Debug::pkgPackageManager=1 #-o Debug::pkgDpkgPM=1 +testdpkginstalled apt libapt-pkg4.16 +testdpkgnotinstalled libapt-pkg5.0 diff --git a/test/integration/test-bug-796070-downgrade-simulate b/test/integration/test-bug-796070-downgrade-simulate new file mode 100755 index 000000000..0b4817d39 --- /dev/null +++ b/test/integration/test-bug-796070-downgrade-simulate @@ -0,0 +1,67 @@ +#!/bin/sh +set -e + +TESTDIR=$(readlink -f $(dirname $0)) +. $TESTDIR/framework + +setupenvironment +configarchitecture 'i386' + +insertpackage 'unstable' 'apt' 'all' '1.0.10.1' 'Depends: libapt-pkg4.16 (>= 1.0.10.1)' +insertinstalledpackage 'libapt-pkg4.16' 'all' '1.0.10.1' 'Breaks: apt (<< 0.9.4~), libapt-inst1.5 (<< 0.9.9~)' +insertinstalledpackage 'libapt-pkg5.0' 'all' '1.1~exp9' 'Breaks: apt (<< 1.1~exp4), libapt-inst1.5 (<< 0.9.9~)' +insertinstalledpackage 'apt' 'all' '1.1~exp9' 'Depends: libapt-pkg5.0' + +insertpackage 'unstable' 'napt' 'all' '1.0.10.1' 'Depends: nlibapt-pkg4.16 (>= 1.0.10.1)' +insertinstalledpackage 'nlibapt-pkg4.16' 'all' '1.0.10.1' 'Breaks: napt (<< 0.9.4~), nlibapt-inst1.5 (<< 0.9.9~)' +insertinstalledpackage 'nlibapt-pkg5.0' 'all' '1.1~exp9' 'Breaks: napt (<< 1.1~exp4), nlibapt-inst1.5 (<< 0.9.9~)' +insertinstalledpackage 'napt' 'all' '1.1~exp9' 'Depends: nlibapt-pkg5.0' + +insertpackage 'unstable' 'eapt' 'all' '1.0.10.1' 'Depends: elibapt-pkg4.16 (>= 1.0.10.1) +Essential: yes' +insertinstalledpackage 'elibapt-pkg4.16' 'all' '1.0.10.1' 'Breaks: eapt (<< 0.9.4~), elibapt-inst1.5 (<< 0.9.9~)' +insertinstalledpackage 'elibapt-pkg5.0' 'all' '1.1~exp9' 'Breaks: eapt (<< 1.1~exp4), elibapt-inst1.5 (<< 0.9.9~)' +insertinstalledpackage 'eapt' 'all' '1.1~exp9' 'Depends: elibapt-pkg5.0 +Essential: yes' + + +setupaptarchive + + +# Check with a normal package +testsuccessequal 'Reading package lists... +Building dependency tree... +The following packages will be REMOVED: + nlibapt-pkg5.0 +The following packages will be DOWNGRADED: + napt +0 upgraded, 0 newly installed, 1 downgraded, 1 to remove and 0 not upgraded. +Remv nlibapt-pkg5.0 [1.1~exp9] [napt:i386 ] +Inst napt [1.1~exp9] (1.0.10.1 unstable [all]) +Conf napt (1.0.10.1 unstable [all])' apt install -s napt=1.0.10.1 + + +# Check with Essential +testsuccessequal 'Reading package lists... +Building dependency tree... +The following packages will be REMOVED: + elibapt-pkg5.0 +The following packages will be DOWNGRADED: + eapt +0 upgraded, 0 newly installed, 1 downgraded, 1 to remove and 0 not upgraded. +Inst eapt [1.1~exp9] (1.0.10.1 unstable [all]) [elibapt-pkg5.0:i386 on eapt:i386] [elibapt-pkg5.0:i386 ] +Remv elibapt-pkg5.0 [1.1~exp9] +Conf eapt (1.0.10.1 unstable [all])' apt install -s eapt=1.0.10.1 + + +# Check with the APT name, aka essential +testsuccessequal 'Reading package lists... +Building dependency tree... +The following packages will be REMOVED: + libapt-pkg5.0 +The following packages will be DOWNGRADED: + apt +0 upgraded, 0 newly installed, 1 downgraded, 1 to remove and 0 not upgraded. +Inst apt [1.1~exp9] (1.0.10.1 unstable [all]) [libapt-pkg5.0:i386 on apt:i386] [libapt-pkg5.0:i386 ] +Remv libapt-pkg5.0 [1.1~exp9] +Conf apt (1.0.10.1 unstable [all])' apt install -s apt=1.0.10.1 -- cgit v1.2.3