]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/deb/dpkgpm.cc
* cmdline/apt-mark:
[apt.git] / apt-pkg / deb / dpkgpm.cc
index 2e85fc14ea28b2f3f5d799a83b0c078a96a4f9df..667db8ff2d98f4da38ae95d1416ec55c89f874c2 100644 (file)
@@ -357,27 +357,27 @@ bool pkgDPkgPM::Go(int OutStatusFd)
       { 
         {"half-installed", _("Preparing %s")}, 
         {"unpacked", _("Unpacking %s") }, 
-        NULL
+        {NULL, NULL}
       },
       // Configure operation
       { 
         {"unpacked",_("Preparing to configure %s") },
         {"half-configured", _("Configuring %s") },
         { "installed", _("Installed %s")},
-         NULL
+        {NULL, NULL}
       },
       // Remove operation
       { 
         {"half-configured", _("Preparing for removal of %s")},
         {"half-installed", _("Removing %s")},
         {"config-files",  _("Removed %s")},
-         NULL
+        {NULL, NULL}
       },
       // Purge operation
       { 
-        {"config-files", _("Preparing for remove with config %s")},
-        {"not-installed", _("Removed with config %s")},
-        NULL 
+        {"config-files", _("Preparing to completely remove %s")},
+        {"not-installed", _("Completely removed %s")},
+        {NULL, NULL}
       },
    };
 
@@ -612,32 +612,65 @@ bool pkgDPkgPM::Go(int OutStatusFd)
         if (_config->FindB("Debug::pkgDPkgProgressReporting",false) == true)
            std::clog << "got from dpkg '" << line << "'" << std::endl;
 
-        // pass "error" and "conffile-prompt" messages from dpkg verbatim
-        if((strncmp(line,"error",strlen("error")) == 0) ||
-           (strncmp(line,"conffile-prompt",strlen("conffile-prompt")) == 0))
-        {
-              write(OutStatusFd, line, strlen(line));
-              line[0]=0;
-              continue;
-        }
-        // line contains the dpkg status info now. it has the form:
-        // 'status:   <pkg>:  <pkg  qstate>' (see dpkg(1) for details)
+        // the status we output
+        ostringstream status;
+
+        /* dpkg sends strings like this:
+           'status:   <pkg>:  <pkg  qstate>'
+           errors look like this:
+           '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
+           
+        */
         char* list[5];
-        TokSplitString(':', line, list, 5);
+        TokSplitString(':', line, list, sizeof(list)/sizeof(list[0]));
         char *pkg = list[1];
-        char *action = list[2];
+        char *action = _strstrip(list[2]);
+
+        if(strncmp(action,"error",strlen("error")) == 0)
+        {
+           status << "pmerror:" << list[1]
+                  << ":"  << (Done/float(Total)*100.0) 
+                  << ":" << list[3]
+                  << endl;
+           if(OutStatusFd > 0)
+              write(OutStatusFd, status.str().c_str(), status.str().size());
+           line[0]=0;
+           if (_config->FindB("Debug::pkgDPkgProgressReporting",false) == true)
+              std::clog << "send: '" << status.str() << "'" << endl;
+           continue;
+        }
+        if(strncmp(action,"conffile",strlen("conffile")) == 0)
+        {
+           status << "pmconffile:" << list[1]
+                  << ":"  << (Done/float(Total)*100.0) 
+                  << ":" << list[3]
+                  << endl;
+           if(OutStatusFd > 0)
+              write(OutStatusFd, status.str().c_str(), status.str().size());
+           line[0]=0;
+           if (_config->FindB("Debug::pkgDPkgProgressReporting",false) == true)
+              std::clog << "send: '" << status.str() << "'" << endl;
+           continue;
+        }
+
         vector<struct DpkgState> &states = PackageOps[pkg];
-        const char *next_action = states[PackageOpsDone[pkg]].state;
-        const char *translation = states[PackageOpsDone[pkg]].str;
-        char s[200];
-        snprintf(s, sizeof(s), translation, pkg);
+        const char *next_action = NULL;
+        if(PackageOpsDone[pkg] < states.size())
+           next_action = states[PackageOpsDone[pkg]].state;
         // check if the package moved to the next dpkg state
         if(next_action && (strcmp(action, next_action) == 0)) 
         {
+           // only read the translation if there is actually a next
+           // action
+           const char *translation = states[PackageOpsDone[pkg]].str;
+           char s[200];
+           snprintf(s, sizeof(s), translation, pkg);
+
            // we moved from one dpkg state to a new one, report that
            PackageOpsDone[pkg]++;
            Done++;
-           ostringstream status;
            // build the status str
            status << "pmstatus:" << pkg 
                   << ":"  << (Done/float(Total)*100.0) 
@@ -646,11 +679,7 @@ bool pkgDPkgPM::Go(int OutStatusFd)
            if(OutStatusFd > 0)
               write(OutStatusFd, status.str().c_str(), status.str().size());
            if (_config->FindB("Debug::pkgDPkgProgressReporting",false) == true)
-           {
-              std::clog << "send to fd: '" << status.str() 
-                        << "'" << std::endl;
-              
-           }
+              std::clog << "send: '" << status.str() << "'" << endl;
 
         }
         if (_config->FindB("Debug::pkgDPkgProgressReporting",false) == true)