]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/deb/dpkgpm.cc
merge from the lp:~donkult/apt/sid branch
[apt.git] / apt-pkg / deb / dpkgpm.cc
index 8162405c77dee8e88ba07792b1a38b7724623dec..fb6054f79446ce0db1359821fb557dcf3997b13e 100644 (file)
@@ -550,6 +550,17 @@ void pkgDPkgPM::DoDpkgStatusFd(int statusfd, int OutStatusFd)
    dpkgbuf_pos = dpkgbuf+dpkgbuf_pos-p;
 }
                                                                        /*}}}*/
+// DPkgPM::WriteHistoryTag                                             /*{{{*/
+void pkgDPkgPM::WriteHistoryTag(string tag, string value)
+{
+   if (value.size() > 0)
+   {
+      // poor mans rstrip(", ")
+      if (value[value.size()-2] == ',' && value[value.size()-1] == ' ')
+        value.erase(value.size() - 2, 2);
+      fprintf(history_out, "%s: %s\n", tag.c_str(), value.c_str());
+   }
+}                                                                      /*}}}*/
 // DPkgPM::OpenLog                                                     /*{{{*/
 bool pkgDPkgPM::OpenLog()
 {
@@ -569,10 +580,11 @@ bool pkgDPkgPM::OpenLog()
    if (!logfile_name.empty())
    {
       term_out = fopen(logfile_name.c_str(),"a");
+      if (term_out == NULL)
+        return _error->WarningE(_("Could not open file '%s'"), logfile_name.c_str());
+
       chmod(logfile_name.c_str(), 0600);
-      fprintf(term_out, "\n\nLog started: ");
-      fprintf(term_out, "%s", timestr);
-      fprintf(term_out, "\n");
+      fprintf(term_out, "\nLog started: %s\n", timestr);
    }
 
    // write 
@@ -586,30 +598,25 @@ bool pkgDPkgPM::OpenLog()
       string remove, purge, install, upgrade, downgrade;
       for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
       {
-        if (Cache[I].Upgrade())
-           upgrade += I.Name() + string(" (") + Cache[I].CurVersion + string(", ") + Cache[I].CandVersion + string(") ");
+        if (Cache[I].NewInstall())
+           install += I.Name() + string(" (") + Cache[I].CandVersion + string("), ");
+        else if (Cache[I].Upgrade())
+           upgrade += I.Name() + string(" (") + Cache[I].CurVersion + string(", ") + Cache[I].CandVersion + string("), ");
         else if (Cache[I].Downgrade())
-           downgrade += I.Name() + string(" (") + Cache[I].CurVersion + string(", ") + Cache[I].CandVersion + string(") ");
-        else if (Cache[I].Install())
-           install += I.Name() + string(" (") + Cache[I].CandVersion + string(") ");
+           downgrade += I.Name() + string(" (") + Cache[I].CurVersion + string(", ") + Cache[I].CandVersion + string("), ");
         else if (Cache[I].Delete())
         {
            if ((Cache[I].iFlags & pkgDepCache::Purge) == pkgDepCache::Purge)
-              purge += I.Name() + string(" (") + Cache[I].CurVersion + string(") ");       
+              purge += I.Name() + string(" (") + Cache[I].CurVersion + string("), ");      
            else
-              remove += I.Name() + string(" (") + Cache[I].CurVersion + string(") ");      
+              remove += I.Name() + string(" (") + Cache[I].CurVersion + string("), ");     
         }
       }
-      if (install.size() > 0)
-        fprintf(history_out, "Install: %s\n", install.c_str());
-      if (upgrade.size() > 0)
-        fprintf(history_out, "Upgrade: %s\n", upgrade.c_str());
-      if (downgrade.size() > 0)
-        fprintf(history_out, "Downgrade: %s\n", downgrade.c_str());
-      if (remove.size() > 0)
-        fprintf(history_out, "Remove: %s\n", remove.c_str());
-      if (purge.size() > 0)
-        fprintf(history_out, "Purge: %s\n", purge.c_str());
+      WriteHistoryTag("Install", install);
+      WriteHistoryTag("Upgrade", upgrade);
+      WriteHistoryTag("Downgrade",downgrade);
+      WriteHistoryTag("Remove",remove);
+      WriteHistoryTag("Purge",purge);
       fflush(history_out);
    }
    
@@ -931,7 +938,8 @@ bool pkgDPkgPM::Go(int OutStatusFd)
            const char *s = _("Can not write log, openpty() "
                              "failed (/dev/pts not mounted?)\n");
            fprintf(stderr, "%s",s);
-           fprintf(term_out, "%s",s);
+            if(term_out)
+              fprintf(term_out, "%s",s);
            master = slave = -1;
         }  else {
            struct termios rtt;
@@ -1055,7 +1063,7 @@ bool pkgDPkgPM::Go(int OutStatusFd)
 
         // wait for input or output here
         FD_ZERO(&rfds);
-        if (!stdin_is_dev_null)
+        if (master >= 0 && !stdin_is_dev_null)
            FD_SET(0, &rfds); 
         FD_SET(_dpkgin, &rfds);
         if(master >= 0)