From e01c08b0206b54c2d977a360beab2d72cf079f0c Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 25 Jul 2008 20:21:53 +0200 Subject: * improve apt progress reporting, display trigger actions --- apt-pkg/deb/dpkgpm.cc | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'apt-pkg/deb/dpkgpm.cc') diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index bc15b8819..77143e671 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -333,6 +333,12 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line) 'status: /var/cache/apt/archives/krecipes_0.8.1-0ubuntu1_i386.deb : error : trying to overwrite `/usr/share/doc/kde/HTML/en/krecipes/krectip.png', which is also in package krecipes-data and conffile-prompt like this 'status: conffile-prompt: conffile : 'current-conffile' 'new-conffile' useredited distedited + + Newer versions of dpkg sent also: + 'processing: install: pkg' + 'processing: configure: pkg' + 'processing: remove: pkg' + 'processing: trigproc: trigger' */ char* list[5]; @@ -351,6 +357,34 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line) char *pkg = list[1]; char *action = _strstrip(list[2]); + // 'processing' from dpkg looks like + // 'processing: action: pkg' + if(strncmp(list[0], "processing", strlen("processing")) == 0) + { + char s[200]; + map::iterator iter; + char *pkg_or_trigger = _strstrip(list[2]); + action =_strstrip( list[1]); + iter = PackageProcessingOps.find(action); + if(iter == PackageProcessingOps.end()) + { + if (_config->FindB("Debug::pkgDPkgProgressReporting",false) == true) + std::clog << "ignoring unknwon action: " << action << std::endl; + return; + } + snprintf(s, sizeof(s), _(iter->second.c_str()), pkg_or_trigger); + + status << "pmstatus:" << pkg_or_trigger + << ":" << (PackagesDone/float(PackagesTotal)*100.0) + << ":" << s + << endl; + if(OutStatusFd > 0) + write(OutStatusFd, status.str().c_str(), status.str().size()); + if (_config->FindB("Debug::pkgDPkgProgressReporting",false) == true) + std::clog << "send: '" << status.str() << "'" << endl; + return; + } + if(strncmp(action,"error",strlen("error")) == 0) { status << "pmerror:" << list[1] @@ -526,7 +560,7 @@ bool pkgDPkgPM::Go(int OutStatusFd) if (RunScriptsWithPkgs("DPkg::Pre-Install-Pkgs") == false) return false; - + // 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] = { @@ -566,6 +600,12 @@ bool pkgDPkgPM::Go(int OutStatusFd) }, }; + // populate the "processing" map + PackageProcessingOps.insert( make_pair("install",N_("Installing %s")) ); + PackageProcessingOps.insert( make_pair("configure",N_("Configuring %s")) ); + PackageProcessingOps.insert( make_pair("remove",N_("Removing %s")) ); + PackageProcessingOps.insert( make_pair("trigproc",N_("Running post-installation trigger %s")) ); + // 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) -- cgit v1.2.3 From e2c79929482ba04ed1a576e4bc837d434c71756e Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 25 Jul 2008 20:33:10 +0200 Subject: * add DPkg::NoTriggers option so that applications that call apt/aptitude (like the installer) defer trigger processing (thanks to Joey Hess) --- apt-pkg/deb/dpkgpm.cc | 3 +++ 1 file changed, 3 insertions(+) (limited to 'apt-pkg/deb/dpkgpm.cc') diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 77143e671..0071c151e 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -554,6 +554,7 @@ bool pkgDPkgPM::Go(int OutStatusFd) { unsigned int MaxArgs = _config->FindI("Dpkg::MaxArgs",8*1024); unsigned int MaxArgBytes = _config->FindI("Dpkg::MaxArgBytes",32*1024); + bool NoTriggers = _config->FindB("DPkg::NoTriggers",false); if (RunScripts("DPkg::Pre-Invoke") == false) return false; @@ -689,6 +690,8 @@ bool pkgDPkgPM::Go(int OutStatusFd) case Item::Configure: Args[n++] = "--configure"; + if (NoTriggers) + Args[n++] = "--no-triggers"; Size += strlen(Args[n-1]); break; -- cgit v1.2.3 From f7dec19f5ce3b876c5d2eaeb2d26cf513780c935 Mon Sep 17 00:00:00 2001 From: Daniel Burrows Date: Thu, 25 Sep 2008 18:24:09 -0700 Subject: Restore the apt ABI. The problem was that the size of pkgDpkgPM and its member offsets changed because a map giving the names of the trigger states was inserted into the middle of the structure. I fixed it by using a statically allocated array instead. This changes the procedure for looking up a string to a linear search, which should be fine (or even faster than before) since there are only 4 state strings. If it becomes a problem, sorting the array by key will allow us to use std::equal_range(), but I would advise against this unless it's really necessary, since sooner or later someone will forget to maintain the sort order. --- apt-pkg/deb/dpkgpm.cc | 51 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 11 deletions(-) (limited to 'apt-pkg/deb/dpkgpm.cc') diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 0071c151e..70dd09bc6 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -25,6 +25,8 @@ #include #include #include +#include +#include #include #include @@ -39,7 +41,38 @@ using namespace std; - +namespace +{ + // Maps the dpkg "processing" info to human readable names. Entry 0 + // of each array is the key, entry 1 is the value. + const std::pair PackageProcessingOps[] = { + std::make_pair("install", N_("Installing %s")), + std::make_pair("configure", N_("Configuring %s")), + std::make_pair("remove", N_("Removing %s")), + std::make_pair("trigproc", N_("Running post-installation trigger %s")) + }; + + const std::pair * const PackageProcessingOpsBegin = PackageProcessingOps; + const std::pair * const PackageProcessingOpsEnd = PackageProcessingOps + sizeof(PackageProcessingOps) / sizeof(PackageProcessingOps[0]); + + // Predicate to test whether an entry in the PackageProcessingOps + // array matches a string. + class MatchProcessingOp + { + const char *target; + + public: + MatchProcessingOp(const char *the_target) + : target(the_target) + { + } + + bool operator()(const std::pair &pair) const + { + return strcmp(pair.first, target) == 0; + } + }; +} // DPkgPM::pkgDPkgPM - Constructor /*{{{*/ // --------------------------------------------------------------------- @@ -362,17 +395,19 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line) if(strncmp(list[0], "processing", strlen("processing")) == 0) { char s[200]; - map::iterator iter; char *pkg_or_trigger = _strstrip(list[2]); action =_strstrip( list[1]); - iter = PackageProcessingOps.find(action); - if(iter == PackageProcessingOps.end()) + const std::pair * const iter = + std::find_if(PackageProcessingOpsBegin, + PackageProcessingOpsEnd, + MatchProcessingOp(action)); + if(iter == PackageProcessingOpsEnd) { if (_config->FindB("Debug::pkgDPkgProgressReporting",false) == true) std::clog << "ignoring unknwon action: " << action << std::endl; return; } - snprintf(s, sizeof(s), _(iter->second.c_str()), pkg_or_trigger); + snprintf(s, sizeof(s), _(iter->second), pkg_or_trigger); status << "pmstatus:" << pkg_or_trigger << ":" << (PackagesDone/float(PackagesTotal)*100.0) @@ -601,12 +636,6 @@ bool pkgDPkgPM::Go(int OutStatusFd) }, }; - // populate the "processing" map - PackageProcessingOps.insert( make_pair("install",N_("Installing %s")) ); - PackageProcessingOps.insert( make_pair("configure",N_("Configuring %s")) ); - PackageProcessingOps.insert( make_pair("remove",N_("Removing %s")) ); - PackageProcessingOps.insert( make_pair("trigproc",N_("Running post-installation trigger %s")) ); - // 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) -- cgit v1.2.3 From 496d5c709d9811f03b70ef0eaf6733c13d2564d2 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 1 Oct 2008 18:35:23 +0200 Subject: * apt-pkg/packagemanager.cc, apt-pkg/deb/dpkgpm.cc: - move the state file writting into the Go() implementation of dpkgpm (closes: #498799) * apt-pkg/algorithms.cc: - fix simulation performance drop (thanks to Ferenc Wagner for reporting the issue) --- apt-pkg/deb/dpkgpm.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'apt-pkg/deb/dpkgpm.cc') diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 70dd09bc6..4fad0fd52 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -956,6 +956,8 @@ bool pkgDPkgPM::Go(int OutStatusFd) if (RunScripts("DPkg::Post-Invoke") == false) return false; + + Cache.writeStateFile(NULL); return true; } /*}}}*/ -- cgit v1.2.3