]> git.saurik.com Git - apt.git/commitdiff
cleanup
authorMichael Vogt <mvo@debian.org>
Fri, 18 Oct 2013 06:02:29 +0000 (08:02 +0200)
committerMichael Vogt <mvo@debian.org>
Fri, 18 Oct 2013 06:02:29 +0000 (08:02 +0200)
apt-pkg/deb/dpkgpm.cc
apt-pkg/deb/dpkgpm.h
apt-pkg/iprogress.cc
test/integration/test-apt-progress-fd

index 19de440018ac752aaba98fb8b0a02a0135e5a8fb..7fba04a30166b22d466e24971723846cde1bed81 100644 (file)
@@ -507,6 +507,34 @@ void pkgDPkgPM::DoTerminalPty(int master)
       fwrite(term_buf, len, sizeof(char), d->term_out);
 }
                                                                        /*}}}*/
+
+std::string pkgDPkgPM::ExpandShortPackageName(pkgDepCache &Cache,
+                                   const std::string &short_pkgname)
+{
+   if (short_pkgname.find(":") != string::npos)
+      return short_pkgname;
+
+   std::string pkgname = short_pkgname;
+   // find the package in the group that is in a touched by dpkg
+   // if there are multiple dpkg will send us a full pkgname:arch
+   pkgCache::GrpIterator Grp = Cache.FindGrp(pkgname);
+   if (Grp.end() == false) 
+   {
+      pkgCache::PkgIterator P = Grp.PackageList();
+      for (; P.end() != true; P = Grp.NextPkg(P))
+      {
+         if(Cache[P].Install() || Cache[P].ReInstall() || 
+            Cache[P].Upgrade() || Cache[P].Downgrade() ||
+            Cache[P].Delete() || Cache[P].Purge())
+         {
+            pkgname = P.FullName();
+            return pkgname;
+         }
+      }
+   }
+   return pkgname;
+}
+
 // DPkgPM::ProcessDpkgStatusBuf                                                /*{{{*/
 // ---------------------------------------------------------------------
 /*
@@ -549,32 +577,35 @@ void pkgDPkgPM::ProcessDpkgStatusLine(char *line)
         std::clog << "ignoring line: not enough ':'" << std::endl;
       return;
    }
-   // dpkg does not send always send "pkgname:arch" so we add it here if needed
-   std::string pkgname = list[1];
-   if (pkgname.find(":") == std::string::npos)
+
+   if (list[0] != "processing" && list[0] != "status")
    {
-      // find the package in the group that is in a touched by dpkg
-      // if there are multiple dpkg will send us a full pkgname:arch
-      pkgCache::GrpIterator Grp = Cache.FindGrp(pkgname);
-      if (Grp.end() == false) 
-      {
-          pkgCache::PkgIterator P = Grp.PackageList();
-          for (; P.end() != true; P = Grp.NextPkg(P))
-          {
-             if(Cache[P].Install() || Cache[P].ReInstall() || 
-                Cache[P].Upgrade() || Cache[P].Downgrade() ||
-                Cache[P].Delete() || Cache[P].Purge())
-              {
-                  pkgname = P.FullName();
-                  break;
-              }
-          }
-      }
+      if (Debug == true)
+        std::clog << "ignoring line: unknown prefix '" << list[0] << "'"
+                   << std::endl;
+      return;
+   }
+
+   std::string prefix = list[0];
+   std::string pkgname;
+   std::string action;
+   if (prefix == "processing")
+   {
+      action = list[1];
+      pkgname = list[2];
+      if (action != "install" && action != "configure" &&
+          action != "remove" && action != "purge" &&
+          action != "disappear")
+         return;
+   } else if (prefix == "status") {
+      pkgname = list[1];
+      action = list[2];
    }
 
+   // dpkg does not always send out the architecture so we need to guess
+   // it here
+   pkgname = ExpandShortPackageName(Cache, pkgname);
    const char* const pkg = pkgname.c_str();
-   const char* action = list[2].c_str();
-   
    std::string short_pkgname = StringSplit(pkgname, ":")[0];
    std::string i18n_pkgname = short_pkgname;
    if (pkgname.find(":") != string::npos)
@@ -587,48 +618,52 @@ void pkgDPkgPM::ProcessDpkgStatusLine(char *line)
    // 'processing: action: pkg'
    if(strncmp(list[0].c_str(), "processing", strlen("processing")) == 0)
    {
-      const char* const pkg_or_trigger = list[2].c_str();
-      action =  list[1].c_str();
       const std::pair<const char *, const char *> * const iter =
        std::find_if(PackageProcessingOpsBegin,
                     PackageProcessingOpsEnd,
-                    MatchProcessingOp(action));
+                    MatchProcessingOp(action.c_str()));
       if(iter == PackageProcessingOpsEnd)
       {
         if (Debug == true)
            std::clog << "ignoring unknown action: " << action << std::endl;
         return;
       }
+
       std::string pkg_action;
-      strprintf(pkg_action, _(iter->second), pkg_or_trigger);
+      strprintf(pkg_action, _(iter->second), short_pkgname.c_str());
 
-      d->progress->StatusChanged(pkg_or_trigger, PackagesDone, PackagesTotal,
+      d->progress->StatusChanged(pkgname, PackagesDone, PackagesTotal,
                                  pkg_action);
-      if (strncmp(action, "disappear", strlen("disappear")) == 0)
-        handleDisappearAction(pkg_or_trigger);
+
+      if (strncmp(action.c_str(), "disappear", strlen("disappear")) == 0)
+        handleDisappearAction(pkgname);
       return;
    }
 
-   if(strncmp(action,"error",strlen("error")) == 0)
+   // FIXME: fix indent once this goes into debian/sid
+   if(strncmp(prefix.c_str(), "status", strlen("processing")) == 0)
+   {
+
+   if(strncmp(action.c_str(),"error",strlen("error")) == 0)
    {
       d->progress->Error(list[1], PackagesDone, PackagesTotal, list[3]);
       pkgFailures++;
       WriteApportReport(list[1].c_str(), list[3].c_str());
       return;
    }
-   else if(strncmp(action,"conffile",strlen("conffile")) == 0)
+   else if(strncmp(action.c_str(),"conffile",strlen("conffile")) == 0)
    {
       d->progress->ConffilePrompt(list[1], PackagesDone, PackagesTotal,
                                   list[3]);
       return;
-   }
+   } else {
 
    vector<struct DpkgState> const &states = PackageOps[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)) 
+   if(next_action && (strcmp(action.c_str(), next_action) == 0)) 
    {
       // only read the translation if there is actually a next
       // action
@@ -644,9 +679,12 @@ void pkgDPkgPM::ProcessDpkgStatusLine(char *line)
       d->progress->StatusChanged(pkgname, PackagesDone, PackagesTotal,
                                  translation);
    }
+   
    if (Debug == true) 
       std::clog << "(parsed from dpkg) pkg: " << pkgname
                << " action: " << action << endl;
+   }
+   }
 }
                                                                        /*}}}*/
 // DPkgPM::handleDisappearAction                                       /*{{{*/
index 302507105982e8d344244e3668f610245b918b94..922631ba80ad3f0ead4295a1574bff602fc8d526 100644 (file)
@@ -84,11 +84,12 @@ class pkgDPkgPM : public pkgPackageManager
    __deprecated bool SendV2Pkgs(FILE *F);
    bool SendPkgsInfo(FILE * const F, unsigned int const &Version);
    void WriteHistoryTag(std::string const &tag, std::string value);
+   std::string ExpandShortPackageName(pkgDepCache &Cache,
+                                      const std::string &short_pkgname);
 
    // Terminal progress 
    void SetupTerminalScrollArea(int nr_scrolled_rows);
    void SendTerminalProgress(float percentage);
-   void CleanupTerminal();
 
    // apport integration
    void WriteApportReport(const char *pkgpath, const char *errormsg);
index bed991d68f3eda0e0b44a610c96c58586920bc32..318d626d42866e4baed8d9646be355ba0b487d2e 100644 (file)
@@ -101,7 +101,7 @@ bool PackageManagerProgressFd::StatusChanged(std::string PackageName,
 
    // build the status str
    std::ostringstream status;
-   status << "pmstatus:" << PackageName
+   status << "pmstatus:" << StringSplit(PackageName, ":")[0]
           << ":"  << (StepsDone/float(StepsTotal)*100.0) 
           << ":" << pkg_action
           << std::endl;
index 5f73c8f8c04837c7cdca9d375b93040298ca293a..cdf8d4a2393401eb5ab7655f39f1d23a3614c381 100755 (executable)
@@ -18,14 +18,14 @@ testsuccess aptget install testing=0.1 -y -o APT::Status-Fd=3
 testequal "dlstatus:1:0:Retrieving file 1 of 1
 dlstatus:1:0:Retrieving file 1 of 1
 pmstatus:dpkg-exec:0:Running dpkg
-pmstatus:testing:0:Installing testing
-pmstatus:testing:20:Preparing testing
-pmstatus:testing:40:Unpacking testing
+pmstatus:testing:0:Installing testing (amd64)
+pmstatus:testing:20:Preparing testing (amd64)
+pmstatus:testing:40:Unpacking testing (amd64)
 pmstatus:testing:60:Preparing to configure testing
 pmstatus:dpkg-exec:60:Running dpkg
-pmstatus:testing:60:Configuring testing
-pmstatus:testing:80:Configuring testing
-pmstatus:testing:100:Installed testing" cat apt-progress.log
+pmstatus:testing:60:Configuring testing (amd64)
+pmstatus:testing:80:Configuring testing (amd64)
+pmstatus:testing:100:Installed testing (amd64)" cat apt-progress.log
 
 # upgrade
 exec 3> apt-progress.log
@@ -33,22 +33,22 @@ testsuccess aptget install testing=0.8.15 -y -o APT::Status-Fd=3
 testequal "dlstatus:1:0:Retrieving file 1 of 1
 dlstatus:1:0:Retrieving file 1 of 1
 pmstatus:dpkg-exec:0:Running dpkg
-pmstatus:testing:20:Preparing testing
-pmstatus:testing:40:Unpacking testing
+pmstatus:testing:20:Preparing testing (amd64)
+pmstatus:testing:40:Unpacking testing (amd64)
 pmstatus:testing:60:Preparing to configure testing
 pmstatus:dpkg-exec:60:Running dpkg
-pmstatus:testing:60:Configuring testing
-pmstatus:testing:80:Configuring testing
-pmstatus:testing:100:Installed testing" cat apt-progress.log
+pmstatus:testing:60:Configuring testing (amd64)
+pmstatus:testing:80:Configuring testing (amd64)
+pmstatus:testing:100:Installed testing (amd64)" cat apt-progress.log
 
 # and remove
 exec 3> apt-progress.log
 testsuccess aptget remove testing -y -o APT::Status-Fd=3
 testequal "pmstatus:dpkg-exec:0:Running dpkg
-pmstatus:testing:0:Removing testing
-pmstatus:testing:33.3333:Preparing for removal of testing
-pmstatus:testing:66.6667:Removing testing
-pmstatus:testing:100:Removed testing" cat apt-progress.log
+pmstatus:testing:0:Removing testing (amd64)
+pmstatus:testing:33.3333:Preparing for removal of testing (amd64)
+pmstatus:testing:66.6667:Removing testing (amd64)
+pmstatus:testing:100:Removed testing (amd64)" cat apt-progress.log
 
 
 # install non-native and ensure we get proper progress info
@@ -59,13 +59,13 @@ testsuccess aptget install testing2:i386 -y -o APT::Status-Fd=3
 testequal "dlstatus:1:0:Retrieving file 1 of 1
 dlstatus:1:0:Retrieving file 1 of 1
 pmstatus:dpkg-exec:0:Running dpkg
-pmstatus:testing2:0:Installing testing2
-pmstatus:testing2:20:Preparing testing2
-pmstatus:testing2:40:Unpacking testing2
-pmstatus:testing2:60:Preparing to configure testing2
+pmstatus:testing2:0:Installing testing2 (i386)
+pmstatus:testing2:20:Preparing testing2 (i386)
+pmstatus:testing2:40:Unpacking testing2 (i386)
+pmstatus:testing2:60:Preparing to configure testing2 (i386)
 pmstatus:dpkg-exec:60:Running dpkg
-pmstatus:testing2:60:Configuring testing2
-pmstatus:testing2:80:Configuring testing2
-pmstatus:testing2:100:Installed testing2" cat apt-progress.log
+pmstatus:testing2:60:Configuring testing2 (i386)
+pmstatus:testing2:80:Configuring testing2 (i386)
+pmstatus:testing2:100:Installed testing2 (i386)" cat apt-progress.log
 
-rm -f apt-progress*.log
\ No newline at end of file
+rm -f apt-progress*.log