X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/cfc6566d5097ef5518e12f5c1e5f15a8f5b182cf..4adc750a2a8d0c6b2c03353b5538bc7446020f68:/apt-pkg/deb/dpkgpm.cc diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 5e27c2686..c1b9a28f4 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -39,7 +39,9 @@ #include #include #include + #include +#include #include #include #include @@ -696,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); + } } } } @@ -960,51 +989,60 @@ void pkgDPkgPM::BuildPackagesProgressMap() { // map the dpkg states to the operations that are performed // (this is sorted in the same way as Item::Ops) - static const struct DpkgState DpkgStatesOpMap[][7] = { + static const std::array, 4> DpkgStatesOpMap = {{ // Install operation - { + {{ {"half-installed", N_("Preparing %s")}, {"unpacked", N_("Unpacking %s") }, - {NULL, NULL} - }, + {nullptr, nullptr} + }}, // Configure operation - { + {{ {"unpacked",N_("Preparing to configure %s") }, {"half-configured", N_("Configuring %s") }, { "installed", N_("Installed %s")}, - {NULL, NULL} - }, + }}, // Remove operation - { + {{ {"half-configured", N_("Preparing for removal of %s")}, {"half-installed", N_("Removing %s")}, {"config-files", N_("Removed %s")}, - {NULL, NULL} - }, + }}, // Purge operation - { + {{ {"config-files", N_("Preparing to completely remove %s")}, {"not-installed", N_("Completely removed %s")}, - {NULL, NULL} - }, - }; + {nullptr, nullptr} + }}, + }}; + static_assert(Item::Purge == 3, "Enum item has unexpected index for mapping array"); // init the PackageOps map, go over the list of packages that // that will be [installed|configured|removed|purged] and add // them to the PackageOps map (the dpkg states it goes through) // and the PackageOpsTranslations (human readable strings) - for (vector::const_iterator I = List.begin(); I != List.end(); ++I) + for (auto &&I : List) { - if((*I).Pkg.end() == true) + if(I.Pkg.end() == true) continue; - string const name = (*I).Pkg.FullName(); + string const name = I.Pkg.FullName(); PackageOpsDone[name] = 0; - for(int i=0; (DpkgStatesOpMap[(*I).Op][i]).state != NULL; ++i) + auto AddToPackageOps = std::back_inserter(PackageOps[name]); + if (I.Op == Item::Purge && I.Pkg->CurrentVer != 0) { - PackageOps[name].push_back(DpkgStatesOpMap[(*I).Op][i]); - PackagesTotal++; + // purging a package which is installed first passes through remove states + auto const DpkgOps = DpkgStatesOpMap[Item::Remove]; + std::copy(DpkgOps.begin(), DpkgOps.end(), AddToPackageOps); + PackagesTotal += DpkgOps.size(); } + auto const DpkgOps = DpkgStatesOpMap[I.Op]; + std::copy_if(DpkgOps.begin(), DpkgOps.end(), AddToPackageOps, [&](DpkgState const &state) { + if (state.state == nullptr) + return false; + ++PackagesTotal; + return true; + }); } /* one extra: We don't want the progress bar to reach 100%, especially not if we call dpkg --configure --pending and process a bunch of triggers @@ -1216,6 +1254,11 @@ bool pkgDPkgPM::Go(APT::Progress::PackageManager *progress) if (RunScriptsWithPkgs("DPkg::Pre-Install-Pkgs") == false) return false; + auto const noopDPkgInvocation = _config->FindB("Debug::pkgDPkgPM",false); + // store auto-bits as they are supposed to be after dpkg is run + if (noopDPkgInvocation == false) + Cache.writeStateFile(NULL); + decltype(List)::const_iterator::difference_type const notconfidx = _config->FindB("Dpkg::ExplicitLastConfigure", false) ? std::numeric_limits::max() : std::distance(List.cbegin(), std::find_if_not(List.crbegin(), List.crend(), [](Item const &i) { return i.Op == Item::Configure; }).base()); @@ -1396,7 +1439,7 @@ bool pkgDPkgPM::Go(APT::Progress::PackageManager *progress) J = I; - if (_config->FindB("Debug::pkgDPkgPM",false) == true) + if (noopDPkgInvocation == true) { for (std::vector::const_iterator a = Args.begin(); a != Args.end(); ++a) @@ -1577,7 +1620,7 @@ bool pkgDPkgPM::Go(APT::Progress::PackageManager *progress) if (pkgPackageManager::SigINTStop) _error->Warning(_("Operation was interrupted before it could finish")); - if (_config->FindB("Debug::pkgDPkgPM",false) == false) + if (noopDPkgInvocation == false) { std::string const oldpkgcache = _config->FindFile("Dir::cache::pkgcache"); if (oldpkgcache.empty() == false && RealFileExists(oldpkgcache) == true && @@ -1594,7 +1637,9 @@ bool pkgDPkgPM::Go(APT::Progress::PackageManager *progress) } } - Cache.writeStateFile(NULL); + // disappearing packages can forward their auto-bit + if (disappearedPkgs.empty() == false) + Cache.writeStateFile(NULL); d->progress->Stop(); @@ -1723,7 +1768,8 @@ void pkgDPkgPM::WriteApportReport(const char *pkgpath, const char *errormsg) // we overwrite it. This is the same behaviour as apport // - if we have a report with the same pkgversion already // then we skip it - reportfile = flCombine("/var/crash",pkgname+".0.crash"); + _config->CndSet("Dir::Apport", "var/crash"); + reportfile = flCombine(_config->FindDir("Dir::Apport", "var/crash"), pkgname+".0.crash"); if(FileExists(reportfile)) { struct stat buf;