apt-pkg/deb/dpkgpm.{cc,h}
authorMichael Vogt <michael.vogt@ubuntu.com>
Thu, 19 Jul 2007 09:37:05 +0000 (10:37 +0100)
committerMichael Vogt <michael.vogt@ubuntu.com>
Thu, 19 Jul 2007 09:37:05 +0000 (10:37 +0100)
- a bit cleanup
- move the log date to the right place
- write log to dir::log::name
apt-pkg/init.cc:
- init dir::log::name "/var/log/apt/term.log"
debian/apt.dirs:
- create /var/log/apt/
doc/examples/configure-index:
- add new dir::log::name to the index

apt-pkg/deb/dpkgpm.cc
apt-pkg/deb/dpkgpm.h
apt-pkg/init.cc
debian/apt.dirs
doc/examples/configure-index

index bef35ab..8cb076e 100644 (file)
@@ -43,7 +43,7 @@ using namespace std;
 // ---------------------------------------------------------------------
 /* */
 pkgDPkgPM::pkgDPkgPM(pkgDepCache *Cache) 
-   : pkgPackageManager(Cache), dpkgbuf_pos(0), Total(0), Done(0)
+   : pkgPackageManager(Cache), dpkgbuf_pos(0), PackagesTotal(0), PackagesDone(0)
 {
 }
                                                                        /*}}}*/
@@ -401,7 +401,7 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line)
    if(strncmp(action,"error",strlen("error")) == 0)
    {
       status << "pmerror:" << list[1]
-            << ":"  << (Done/float(Total)*100.0) 
+            << ":"  << (PackagesDone/float(PackagesTotal)*100.0) 
             << ":" << list[3]
             << endl;
       if(OutStatusFd > 0)
@@ -413,7 +413,7 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line)
    if(strncmp(action,"conffile",strlen("conffile")) == 0)
    {
       status << "pmconffile:" << list[1]
-            << ":"  << (Done/float(Total)*100.0) 
+            << ":"  << (PackagesDone/float(PackagesTotal)*100.0) 
             << ":" << list[3]
             << endl;
       if(OutStatusFd > 0)
@@ -438,10 +438,10 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line)
 
       // we moved from one dpkg state to a new one, report that
       PackageOpsDone[pkg]++;
-      Done++;
+      PackagesDone++;
       // build the status str
       status << "pmstatus:" << pkg 
-            << ":"  << (Done/float(Total)*100.0) 
+            << ":"  << (PackagesDone/float(PackagesTotal)*100.0) 
             << ":" << s
             << endl;
       if(OutStatusFd > 0)
@@ -555,10 +555,27 @@ bool pkgDPkgPM::Go(int OutStatusFd)
       for(int i=0; (DpkgStatesOpMap[(*I).Op][i]).state != NULL;  i++) 
       {
         PackageOps[name].push_back(DpkgStatesOpMap[(*I).Op][i]);
-        Total++;
+        PackagesTotal++;
       }
    }   
 
+   // create log
+   string logdir = _config->FindDir("Dir::Log");
+   if(not FileExists(logdir))
+      return _error->Error(_("Directory '%s' missing"), logdir.c_str());
+   string logfile_name = flCombine(logdir,
+                                  _config->Find("Dir::Log::Name"));
+   FILE *term_out = fopen(logfile_name.c_str(),"a");
+   chmod(logfile_name.c_str(), 0600);
+   // output current time
+   char outstr[200];
+   time_t t = time(NULL);
+   struct tm *tmp = localtime(&t);
+   strftime(outstr, sizeof(outstr), "%F  %T", tmp);
+   fprintf(term_out, "Log started: ");
+   fprintf(term_out, outstr);
+   fprintf(term_out, "\n");
+
    // this loop is runs once per operation
    for (vector<Item>::iterator I = List.begin(); I != List.end();)
    {
@@ -755,18 +772,6 @@ bool pkgDPkgPM::Go(int OutStatusFd)
       int res;
       close(slave);
 
-      // FIXME: make this a apt config option and add a logrotate file
-      FILE *term_out = fopen("/var/log/dpkg-out.log","a");
-      chmod("/var/log/dpkg-out.log", 0600);
-      // output current time
-      char outstr[200];
-      time_t t = time(NULL);
-      struct tm *tmp = localtime(&t);
-      strftime(outstr, sizeof(outstr), "%F  %T", tmp);
-      fprintf(term_out, "Log started: ");
-      fprintf(term_out, outstr);
-      fprintf(term_out, "\n");
-
       // setups fds
       fd_set rfds;
       struct timeval tv;
@@ -806,7 +811,6 @@ bool pkgDPkgPM::Go(int OutStatusFd)
            DoDpkgStatusFd(_dpkgin, OutStatusFd);
       }
       close(_dpkgin);
-      fclose(term_out);
 
       // Restore sig int/quit
       signal(SIGQUIT,old_SIGQUIT);
@@ -832,10 +836,14 @@ bool pkgDPkgPM::Go(int OutStatusFd)
         else 
            _error->Error("Sub-process %s exited unexpectedly",Args[0]);
 
-        if(stopOnError)
+        if(stopOnError) 
+        {
+           fclose(term_out);
            return false;
+        }
       }      
    }
+   fclose(term_out);
 
    if (RunScripts("DPkg::Post-Invoke") == false)
       return false;
index c7792ab..c552b20 100644 (file)
@@ -27,6 +27,8 @@ class pkgDPkgPM : public pkgPackageManager
    char dpkgbuf[1024];
    int dpkgbuf_pos;
 
+   protected:
+
    // progress reporting
    struct DpkgState 
    {
@@ -43,10 +45,8 @@ class pkgDPkgPM : public pkgPackageManager
    // going to be install is already in state "half-installed")
    map<string,int> PackageOpsDone;
    // progress reporting
-   int Done;
-   int Total;
-
-   protected:
+   int PackagesDone;
+   int PackagesTotal;
   
    struct Item
    {
@@ -71,7 +71,6 @@ class pkgDPkgPM : public pkgPackageManager
    void DoDpkgStatusFd(int statusfd, int OutStatusFd);
    void ProcessDpkgStatusLine(int OutStatusFd, char *line);
 
-
    // The Actuall installation implementation
    virtual bool Install(PkgIterator Pkg,string File);
    virtual bool Configure(PkgIterator Pkg);
index 2f15486..2617603 100644 (file)
@@ -74,6 +74,10 @@ bool pkgInitConfig(Configuration &Cnf)
    Cnf.Set("Dir::Etc::parts","apt.conf.d");
    Cnf.Set("Dir::Etc::preferences","preferences");
    Cnf.Set("Dir::Bin::methods","/usr/lib/apt/methods");
+
+   // State   
+   Cnf.Set("Dir::Log","var/log/apt");
+   Cnf.Set("Dir::Log::Name","term.log");
    
    bool Res = true;
    
index 1543e8b..26bb068 100644 (file)
@@ -7,4 +7,5 @@ etc/apt/sources.list.d
 var/cache/apt/archives/partial
 var/lib/apt/lists/partial
 var/lib/apt/periodic
+var/log/apt
 usr/share/bug/apt
index d0aad1e..0bf407a 100644 (file)
@@ -227,6 +227,11 @@ Dir "/"
      apt-get "/usr/bin/apt-get";
      apt-cache "/usr/bin/apt-cache";
   };
+
+  // Location of the logfile
+  Log "var/log/apt" {
+       Name "term.log";
+  };
 };
 
 // Things that effect the APT dselect method