diff options
author | David Kalnischkies <david@kalnischkies.de> | 2014-08-17 12:30:21 +0200 |
---|---|---|
committer | David Kalnischkies <david@kalnischkies.de> | 2014-09-27 00:10:05 +0200 |
commit | 2a884c612b10b27f4be2cc6dd689bfe448d9361a (patch) | |
tree | 2b5b31e255115ac3b9221a39e852723d6d48438d /apt-pkg | |
parent | b13ce62c7e7db6a0e80a0f4729ee00105466c3ac (diff) |
fix progress output for (dist-)upgrade calculation
Previously, we had a start and a done of the calculation printed by
higher-level code, but this got intermixed by progress reporting from an
external solver or the output of autoremove codeā¦
The higherlevel code is now only responsible for instantiating a
progress object of its choosing (if it wants progress after all) and the
rest will be handled by the upgrade code. Either it is used to show the
progress of the external solver or the internal solver will give some
hints about its overall progress. The later isn't really a proper
progress as it will jump forward after each substep, but that is at
least a bit better than before without any progress indication.
Fixes also the 'strange' non-display of this progress line in -q=1, while
all others are shown, which is reflected by all testcase changes.
Diffstat (limited to 'apt-pkg')
-rw-r--r-- | apt-pkg/algorithms.cc | 16 | ||||
-rw-r--r-- | apt-pkg/algorithms.h | 10 | ||||
-rw-r--r-- | apt-pkg/upgrade.cc | 104 | ||||
-rw-r--r-- | apt-pkg/upgrade.h | 12 |
4 files changed, 87 insertions, 55 deletions
diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.cc index 608ec7fce..71b5ac2c1 100644 --- a/apt-pkg/algorithms.cc +++ b/apt-pkg/algorithms.cc @@ -640,13 +640,11 @@ bool pkgProblemResolver::DoUpgrade(pkgCache::PkgIterator Pkg) // ProblemResolver::Resolve - calls a resolver to fix the situation /*{{{*/ // --------------------------------------------------------------------- /* */ -bool pkgProblemResolver::Resolve(bool BrokenFix) +bool pkgProblemResolver::Resolve(bool BrokenFix, OpProgress * const Progress) { std::string const solver = _config->Find("APT::Solver", "internal"); - if (solver != "internal") { - OpTextProgress Prog(*_config); - return EDSP::ResolveExternal(solver.c_str(), Cache, false, false, false, &Prog); - } + if (solver != "internal") + return EDSP::ResolveExternal(solver.c_str(), Cache, false, false, false, Progress); return ResolveInternal(BrokenFix); } /*}}}*/ @@ -1140,13 +1138,11 @@ bool pkgProblemResolver::InstOrNewPolicyBroken(pkgCache::PkgIterator I) /* This is the work horse of the soft upgrade routine. It is very gental in that it does not install or remove any packages. It is assumed that the system was non-broken previously. */ -bool pkgProblemResolver::ResolveByKeep() +bool pkgProblemResolver::ResolveByKeep(OpProgress * const Progress) { std::string const solver = _config->Find("APT::Solver", "internal"); - if (solver != "internal") { - OpTextProgress Prog(*_config); - return EDSP::ResolveExternal(solver.c_str(), Cache, true, false, false, &Prog); - } + if (solver != "internal") + return EDSP::ResolveExternal(solver.c_str(), Cache, true, false, false, Progress); return ResolveByKeepInternal(); } /*}}}*/ diff --git a/apt-pkg/algorithms.h b/apt-pkg/algorithms.h index f35bd9a13..4d3bfa81f 100644 --- a/apt-pkg/algorithms.h +++ b/apt-pkg/algorithms.h @@ -136,12 +136,12 @@ class pkgProblemResolver /*{{{*/ inline void Protect(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] |= Protected; Cache.MarkProtected(Pkg);}; inline void Remove(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] |= ToRemove;}; inline void Clear(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] &= ~(Protected | ToRemove);}; - - // Try to intelligently resolve problems by installing and removing packages - bool Resolve(bool BrokenFix = false); - + + // Try to intelligently resolve problems by installing and removing packages + bool Resolve(bool BrokenFix = false, OpProgress * const Progress = NULL); + // Try to resolve problems only by using keep - bool ResolveByKeep(); + bool ResolveByKeep(OpProgress * const Progress = NULL); APT_DEPRECATED void InstallProtect(); diff --git a/apt-pkg/upgrade.cc b/apt-pkg/upgrade.cc index 29b11937b..20a38ecee 100644 --- a/apt-pkg/upgrade.cc +++ b/apt-pkg/upgrade.cc @@ -24,13 +24,14 @@ The problem resolver is used to resolve the problems. */ -bool pkgDistUpgrade(pkgDepCache &Cache) +bool pkgDistUpgrade(pkgDepCache &Cache, OpProgress * const Progress) { std::string const solver = _config->Find("APT::Solver", "internal"); - if (solver != "internal") { - OpTextProgress Prog(*_config); - return EDSP::ResolveExternal(solver.c_str(), Cache, false, true, false, &Prog); - } + if (solver != "internal") + return EDSP::ResolveExternal(solver.c_str(), Cache, false, true, false, Progress); + + if (Progress != NULL) + Progress->OverallProgress(0, 100, 1, _("Calculating upgrade")); pkgDepCache::ActionGroup group(Cache); @@ -41,12 +42,18 @@ bool pkgDistUpgrade(pkgDepCache &Cache) if (I->CurrentVer != 0) Cache.MarkInstall(I, false, 0, false); + if (Progress != NULL) + Progress->Progress(10); + /* Auto upgrade all installed packages, this provides the basis for the installation */ for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) if (I->CurrentVer != 0) Cache.MarkInstall(I, true, 0, false); + if (Progress != NULL) + Progress->Progress(50); + /* Now, install each essential package which is not installed (and not provided by another package in the same name group) */ std::string essential = _config->Find("pkgCacheGen::Essential", "all"); @@ -77,15 +84,24 @@ bool pkgDistUpgrade(pkgDepCache &Cache) for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) if ((I->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential) Cache.MarkInstall(I, true, 0, false); - + + if (Progress != NULL) + Progress->Progress(55); + /* We do it again over all previously installed packages to force conflict resolution on them all. */ for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) if (I->CurrentVer != 0) Cache.MarkInstall(I, false, 0, false); + if (Progress != NULL) + Progress->Progress(65); + pkgProblemResolver Fix(&Cache); + if (Progress != NULL) + Progress->Progress(95); + // Hold back held packages. if (_config->FindB("APT::Ignore-Hold",false) == false) { @@ -98,18 +114,22 @@ bool pkgDistUpgrade(pkgDepCache &Cache) } } } - - return Fix.Resolve(); + + bool const success = Fix.Resolve(false, Progress); + if (Progress != NULL) + Progress->Done(); + return success; } /*}}}*/ // AllUpgradeNoNewPackages - Upgrade but no removals or new pkgs /*{{{*/ -static bool pkgAllUpgradeNoNewPackages(pkgDepCache &Cache) +static bool pkgAllUpgradeNoNewPackages(pkgDepCache &Cache, OpProgress * const Progress) { std::string const solver = _config->Find("APT::Solver", "internal"); - if (solver != "internal") { - OpTextProgress Prog(*_config); - return EDSP::ResolveExternal(solver.c_str(), Cache, true, false, false, &Prog); - } + if (solver != "internal") + return EDSP::ResolveExternal(solver.c_str(), Cache, true, false, false, Progress); + + if (Progress != NULL) + Progress->OverallProgress(0, 100, 1, _("Calculating upgrade")); pkgDepCache::ActionGroup group(Cache); @@ -131,8 +151,15 @@ static bool pkgAllUpgradeNoNewPackages(pkgDepCache &Cache) if (I->CurrentVer != 0 && Cache[I].InstallVer != 0) Cache.MarkInstall(I, false, 0, false); } - - return Fix.ResolveByKeep(); + + if (Progress != NULL) + Progress->Progress(50); + + // resolve remaining issues via keep + bool const success = Fix.ResolveByKeep(Progress); + if (Progress != NULL) + Progress->Done(); + return success; } /*}}}*/ // AllUpgradeWithNewInstalls - Upgrade + install new packages as needed /*{{{*/ @@ -141,13 +168,14 @@ static bool pkgAllUpgradeNoNewPackages(pkgDepCache &Cache) * Upgrade as much as possible without deleting anything (useful for * stable systems) */ -static bool pkgAllUpgradeWithNewPackages(pkgDepCache &Cache) +static bool pkgAllUpgradeWithNewPackages(pkgDepCache &Cache, OpProgress * const Progress) { std::string const solver = _config->Find("APT::Solver", "internal"); - if (solver != "internal") { - OpTextProgress Prog(*_config); - return EDSP::ResolveExternal(solver.c_str(), Cache, true, false, false, &Prog); - } + if (solver != "internal") + return EDSP::ResolveExternal(solver.c_str(), Cache, true, false, false, Progress); + + if (Progress != NULL) + Progress->OverallProgress(0, 100, 1, _("Calculating upgrade")); pkgDepCache::ActionGroup group(Cache); @@ -170,18 +198,30 @@ static bool pkgAllUpgradeWithNewPackages(pkgDepCache &Cache) } } + if (Progress != NULL) + Progress->Progress(10); + // then let auto-install loose for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) if (Cache[I].Install()) Cache.MarkInstall(I, true, 0, false); + if (Progress != NULL) + Progress->Progress(50); + // ... but it may remove stuff, we we need to clean up afterwards again for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) if (Cache[I].Delete() == true) Cache.MarkKeep(I, false, false); + if (Progress != NULL) + Progress->Progress(60); + // resolve remaining issues via keep - return Fix.ResolveByKeep(); + bool const success = Fix.ResolveByKeep(Progress); + if (Progress != NULL) + Progress->Done(); + return success; } /*}}}*/ // AllUpgrade - Upgrade as many packages as possible /*{{{*/ @@ -189,9 +229,9 @@ static bool pkgAllUpgradeWithNewPackages(pkgDepCache &Cache) /* Right now the system must be consistent before this can be called. It also will not change packages marked for install, it only tries to install packages not marked for install */ -bool pkgAllUpgrade(pkgDepCache &Cache) +bool pkgAllUpgrade(pkgDepCache &Cache, OpProgress * const Progress) { - return pkgAllUpgradeNoNewPackages(Cache); + return pkgAllUpgradeNoNewPackages(Cache, Progress); } /*}}}*/ // MinimizeUpgrade - Minimizes the set of packages to be upgraded /*{{{*/ @@ -239,21 +279,15 @@ bool pkgMinimizeUpgrade(pkgDepCache &Cache) return true; } /*}}}*/ -// APT::Upgrade::Upgrade - Upgrade using a specific strategy /*{{{*/ -bool APT::Upgrade::Upgrade(pkgDepCache &Cache, int mode) +// APT::Upgrade::Upgrade - Upgrade using a specific strategy /*{{{*/ +bool APT::Upgrade::Upgrade(pkgDepCache &Cache, int mode, OpProgress * const Progress) { - if (mode == 0) - { - return pkgDistUpgrade(Cache); - } + if (mode == 0) + return pkgDistUpgrade(Cache, Progress); else if ((mode & ~FORBID_REMOVE_PACKAGES) == 0) - { - return pkgAllUpgradeWithNewPackages(Cache); - } + return pkgAllUpgradeWithNewPackages(Cache, Progress); else if ((mode & ~(FORBID_REMOVE_PACKAGES|FORBID_INSTALL_NEW_PACKAGES)) == 0) - { - return pkgAllUpgradeNoNewPackages(Cache); - } + return pkgAllUpgradeNoNewPackages(Cache, Progress); else _error->Error("pkgAllUpgrade called with unsupported mode %i", mode); diff --git a/apt-pkg/upgrade.h b/apt-pkg/upgrade.h index aa883df10..894f0625e 100644 --- a/apt-pkg/upgrade.h +++ b/apt-pkg/upgrade.h @@ -10,7 +10,10 @@ #ifndef PKGLIB_UPGRADE_H #define PKGLIB_UPGRADE_H +#include <stddef.h> + class pkgDepCache; +class OpProgress; namespace APT { namespace Upgrade { @@ -19,14 +22,13 @@ namespace APT { FORBID_REMOVE_PACKAGES = 1, FORBID_INSTALL_NEW_PACKAGES = 2 }; - bool Upgrade(pkgDepCache &Cache, int UpgradeMode); + bool Upgrade(pkgDepCache &Cache, int UpgradeMode, OpProgress * const Progress = NULL); } } // please use APT::Upgrade::Upgrade() instead -bool pkgDistUpgrade(pkgDepCache &Cache); -bool pkgAllUpgrade(pkgDepCache &Cache); -bool pkgMinimizeUpgrade(pkgDepCache &Cache); - +bool pkgDistUpgrade(pkgDepCache &Cache, OpProgress * const Progress = NULL); +bool pkgAllUpgrade(pkgDepCache &Cache, OpProgress * const Progress = NULL); +bool pkgMinimizeUpgrade(pkgDepCache &Cache); #endif |