]> git.saurik.com Git - apt.git/commitdiff
add APT::String::Strip(), start cleanup of ProcessDpkgStatusLine
authorMichael Vogt <mvo@debian.org>
Fri, 18 Oct 2013 06:10:29 +0000 (08:10 +0200)
committerMichael Vogt <mvo@debian.org>
Fri, 18 Oct 2013 06:10:29 +0000 (08:10 +0200)
apt-pkg/contrib/strutl.cc
apt-pkg/contrib/strutl.h
apt-pkg/deb/dpkgpm.cc

index 77e48962c086ec7be659736b1fd6e9d62e303994..9f794927d0e3280f1a3f9e5072b28c0c896d533a 100644 (file)
 
 using namespace std;
                                                                        /*}}}*/
-
+// Strip - Remove white space from the front and back of a string       /*{{{*/
+// ---------------------------------------------------------------------
+namespace APT {
+   namespace String {
+std::string Strip(const std::string &s)
+{
+   size_t start = s.find_first_not_of(" \t\n");
+   // only whitespace
+   if (start == string::npos)
+      return "";
+   size_t end = s.find_last_not_of(" \t\n");
+   return s.substr(start, end-start+1);
+}
+}
+}
+                                                                       /*}}}*/
 // UTF8ToCodeset - Convert some UTF-8 string for some codeset          /*{{{*/
 // ---------------------------------------------------------------------
 /* This is handy to use before display some information for enduser  */
index b42e0649171ceae71131f3236132af199a53d400..c8fc317c029685df1b1aa6b3a269785899076566 100644 (file)
@@ -33,6 +33,13 @@ using std::vector;
 using std::ostream;
 #endif
 
+namespace APT {
+   namespace String {
+      std::string Strip(const std::string &s);
+   };
+};
+
+
 bool UTF8ToCodeset(const char *codeset, const std::string &orig, std::string *dest);
 char *_strstrip(char *String);
 char *_strrstrip(char *String); // right strip only
index f870fab936f7139c7b04cb726b0090e599aeb3aa..c5d40c0338e4e5dd36cdfba6cc7c7ade37fc4406 100644 (file)
@@ -540,6 +540,7 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line)
       'processing: trigproc: trigger'
            
    */
+
    // we need to split on ": " (note the appended space) as the ':' is
    // part of the pkgname:arch information that dpkg sends
    // 
@@ -553,8 +554,26 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line)
         std::clog << "ignoring line: not enough ':'" << std::endl;
       return;
    }
+
+   std::string prefix = APT::String::Strip(list[0]);
+   std::string pkgname;
+   std::string action_str;
+   if (prefix == "processing")
+   {
+      pkgname = APT::String::Strip(list[2]);
+      action_str = APT::String::Strip(list[1]);
+   }
+   else if (prefix == "status")
+   {
+      pkgname = APT::String::Strip(list[1]);
+      action_str = APT::String::Strip(list[2]);
+   } else {
+      if (Debug == true)
+        std::clog << "unknown prefix '" << prefix << "'" << 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)
    {
       // find the package in the group that is in a touched by dpkg
@@ -574,13 +593,12 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line)
       }
    }
    const char* const pkg = pkgname.c_str();
-   const char* action = list[2].c_str();
-   
+   const char* action = action_str.c_str();
    std::string short_pkgname = StringSplit(pkgname, ":")[0];
 
    // 'processing' from dpkg looks like
    // 'processing: action: pkg'
-   if(strncmp(list[0].c_str(), "processing", strlen("processing")) == 0)
+   if(prefix == "processing")
    {
       char s[200];
       const char* const pkg_or_trigger = list[2].c_str();
@@ -609,7 +627,11 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line)
       if (strncmp(action, "disappear", strlen("disappear")) == 0)
         handleDisappearAction(pkg_or_trigger);
       return;
-   }
+   } 
+
+   // FIXME: fix indent once the progress-refactor branch is merged
+   if (prefix == "status")
+   {
 
    if(strncmp(action,"error",strlen("error")) == 0)
    {
@@ -670,6 +692,7 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line)
    if (Debug == true) 
       std::clog << "(parsed from dpkg) pkg: " << short_pkgname
                << " action: " << action << endl;
+   }
 }
                                                                        /*}}}*/
 // DPkgPM::handleDisappearAction                                       /*{{{*/