From 8b21456acba3cbbc28f35eba684d8f21b0c290b4 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 10 Jul 2016 14:14:43 +0200 Subject: report progress for triggered actions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit APT doesn't know which packages will be triggered in the course of actions, so it can't plan to see them for progress beforehand, but if it sees that dpkg says that a package was triggered we can add additional states. This is pretty much magic – after all it sets back the progress – and there are cornercases in which this will result in incorrect totals (package in partial states may or may not loose trigger states), but the worst which can happen is that the progress is slightly incorrect and doesn't reach 100%, but so be it. Better than being stuck at 100% for a while as apt isn't realizing that a bunch of triggers still need to be processed. --- apt-pkg/deb/dpkgpm.cc | 57 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 0c61a5e36..c1b9a28f4 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -698,28 +698,55 @@ void pkgDPkgPM::ProcessDpkgStatusLine(char *line) if (prefix == "status") { - vector const &states = PackageOps[pkg]; - if(PackageOpsDone[pkg] < states.size()) + std::vector &states = PackageOps[pkg]; + if (action == "triggers-pending") { - char const * const next_action = states[PackageOpsDone[pkg]].state; - if (next_action && Debug == true) + if (Debug == true) std::clog << "(parsed from dpkg) pkg: " << short_pkgname - << " action: " << action << " (expected: '" << next_action << "' " + << " action: " << action << " (prefix 2 to " << PackageOpsDone[pkg] << " of " << states.size() << ")" << endl; - // check if the package moved to the next dpkg state - if(next_action && (action == next_action)) + states.insert(states.begin(), {"installed", N_("Installed %s")}); + states.insert(states.begin(), {"half-configured", N_("Configuring %s")}); + PackagesTotal += 2; + } + else if(PackageOpsDone[pkg] < states.size()) + { + char const * next_action = states[PackageOpsDone[pkg]].state; + if (next_action) { - // only read the translation if there is actually a next action - char const * const translation = _(states[PackageOpsDone[pkg]].str); + /* + if (action == "half-installed" && strcmp("half-configured", next_action) == 0 && + PackageOpsDone[pkg] + 2 < states.size() && action == states[PackageOpsDone[pkg] + 2].state) + { + if (Debug == true) + std::clog << "(parsed from dpkg) pkg: " << short_pkgname << " action: " << action + << " pending trigger defused by unpack" << std::endl; + // unpacking a package defuses the pending trigger + PackageOpsDone[pkg] += 2; + PackagesDone += 2; + next_action = states[PackageOpsDone[pkg]].state; + } + */ + if (Debug == true) + std::clog << "(parsed from dpkg) pkg: " << short_pkgname + << " action: " << action << " (expected: '" << next_action << "' " + << PackageOpsDone[pkg] << " of " << states.size() << ")" << endl; + + // check if the package moved to the next dpkg state + if(action == next_action) + { + // only read the translation if there is actually a next action + char const * const translation = _(states[PackageOpsDone[pkg]].str); - // we moved from one dpkg state to a new one, report that - ++PackageOpsDone[pkg]; - ++PackagesDone; + // we moved from one dpkg state to a new one, report that + ++PackageOpsDone[pkg]; + ++PackagesDone; - std::string msg; - strprintf(msg, translation, i18n_pkgname.c_str()); - d->progress->StatusChanged(pkgname, PackagesDone, PackagesTotal, msg); + std::string msg; + strprintf(msg, translation, i18n_pkgname.c_str()); + d->progress->StatusChanged(pkgname, PackagesDone, PackagesTotal, msg); + } } } } -- cgit v1.2.3