Просмотр исходного кода

add APT::String::Strip(), start cleanup of ProcessDpkgStatusLine

Michael Vogt лет назад: 12
Родитель
Сommit
2842f8f3e3
3 измененных файлов с 51 добавлено и 6 удалено
  1. 16 1
      apt-pkg/contrib/strutl.cc
  2. 7 0
      apt-pkg/contrib/strutl.h
  3. 28 5
      apt-pkg/deb/dpkgpm.cc

+ 16 - 1
apt-pkg/contrib/strutl.cc

@@ -36,7 +36,22 @@
 
 
 using namespace std;
 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   	/*{{{*/
 // UTF8ToCodeset - Convert some UTF-8 string for some codeset   	/*{{{*/
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
 /* This is handy to use before display some information for enduser  */
 /* This is handy to use before display some information for enduser  */

+ 7 - 0
apt-pkg/contrib/strutl.h

@@ -33,6 +33,13 @@ using std::vector;
 using std::ostream;
 using std::ostream;
 #endif
 #endif
 
 
+namespace APT {
+   namespace String {
+      std::string Strip(const std::string &s);
+   };
+};
+
+
 bool UTF8ToCodeset(const char *codeset, const std::string &orig, std::string *dest);
 bool UTF8ToCodeset(const char *codeset, const std::string &orig, std::string *dest);
 char *_strstrip(char *String);
 char *_strstrip(char *String);
 char *_strrstrip(char *String); // right strip only
 char *_strrstrip(char *String); // right strip only

+ 28 - 5
apt-pkg/deb/dpkgpm.cc

@@ -540,6 +540,7 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line)
       'processing: trigproc: trigger'
       'processing: trigproc: trigger'
 	    
 	    
    */
    */
+
    // we need to split on ": " (note the appended space) as the ':' is
    // we need to split on ": " (note the appended space) as the ':' is
    // part of the pkgname:arch information that dpkg sends
    // 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;
 	 std::clog << "ignoring line: not enough ':'" << std::endl;
       return;
       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
    // 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 (pkgname.find(":") == std::string::npos)
    {
    {
       // find the package in the group that is in a touched by dpkg
       // 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* 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];
    std::string short_pkgname = StringSplit(pkgname, ":")[0];
 
 
    // 'processing' from dpkg looks like
    // 'processing' from dpkg looks like
    // 'processing: action: pkg'
    // 'processing: action: pkg'
-   if(strncmp(list[0].c_str(), "processing", strlen("processing")) == 0)
+   if(prefix == "processing")
    {
    {
       char s[200];
       char s[200];
       const char* const pkg_or_trigger = list[2].c_str();
       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)
       if (strncmp(action, "disappear", strlen("disappear")) == 0)
 	 handleDisappearAction(pkg_or_trigger);
 	 handleDisappearAction(pkg_or_trigger);
       return;
       return;
-   }
+   } 
+
+   // FIXME: fix indent once the progress-refactor branch is merged
+   if (prefix == "status")
+   {
 
 
    if(strncmp(action,"error",strlen("error")) == 0)
    if(strncmp(action,"error",strlen("error")) == 0)
    {
    {
@@ -670,6 +692,7 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line)
    if (Debug == true) 
    if (Debug == true) 
       std::clog << "(parsed from dpkg) pkg: " << short_pkgname
       std::clog << "(parsed from dpkg) pkg: " << short_pkgname
 		<< " action: " << action << endl;
 		<< " action: " << action << endl;
+   }
 }
 }
 									/*}}}*/
 									/*}}}*/
 // DPkgPM::handleDisappearAction					/*{{{*/
 // DPkgPM::handleDisappearAction					/*{{{*/