]> git.saurik.com Git - apt.git/commitdiff
merged from debian-sid
authorMichael Vogt <michael.vogt@ubuntu.com>
Wed, 17 Feb 2010 21:09:25 +0000 (22:09 +0100)
committerMichael Vogt <michael.vogt@ubuntu.com>
Wed, 17 Feb 2010 21:09:25 +0000 (22:09 +0100)
apt-pkg/deb/dpkgpm.cc
apt-pkg/deb/dpkgpm.h
apt-pkg/init.cc
debian/apt.logrotate
debian/changelog
doc/examples/configure-index
methods/cdrom.cc
methods/http.cc
methods/http.h

index 565f01b842656421cc8878feddab4b23b88253e4..9d144a22729423053e14b97ad748d41fcc269656 100644 (file)
@@ -550,12 +550,31 @@ 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()
 {
    string logdir = _config->FindDir("Dir::Log");
    if(not FileExists(logdir))
       return _error->Error(_("Directory '%s' missing"), logdir.c_str());
+
+   // get current time
+   char timestr[200];
+   time_t t = time(NULL);
+   struct tm *tmp = localtime(&t);
+   strftime(timestr, sizeof(timestr), "%F  %T", tmp);
+
+   // open terminal log
    string logfile_name = flCombine(logdir,
                                   _config->Find("Dir::Log::Terminal"));
    if (!logfile_name.empty())
@@ -565,31 +584,70 @@ bool pkgDPkgPM::OpenLog()
         return _error->WarningE(_("Could not open file '%s'"), logfile_name.c_str());
 
       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, "\nLog started: %s\n", outstr);
+      fprintf(term_out, "\nLog started: %s\n", timestr);
    }
+
+   // write 
+   string history_name = flCombine(logdir,
+                                  _config->Find("Dir::Log::History"));
+   if (!history_name.empty())
+   {
+      history_out = fopen(history_name.c_str(),"a");
+      chmod(history_name.c_str(), 0644);
+      fprintf(history_out, "\nStart-Date: %s\n", timestr);
+      string remove, purge, install, upgrade, downgrade;
+      for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
+      {
+        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].Delete())
+        {
+           if ((Cache[I].iFlags & pkgDepCache::Purge) == pkgDepCache::Purge)
+              purge += I.Name() + string(" (") + Cache[I].CurVersion + string("), ");      
+           else
+              remove += I.Name() + string(" (") + Cache[I].CurVersion + string("), ");     
+        }
+      }
+      WriteHistoryTag("Install", install);
+      WriteHistoryTag("Upgrade", upgrade);
+      WriteHistoryTag("Downgrade",downgrade);
+      WriteHistoryTag("Remove",remove);
+      WriteHistoryTag("Purge",purge);
+      fflush(history_out);
+   }
+   
    return true;
 }
                                                                        /*}}}*/
 // DPkg::CloseLog                                                      /*{{{*/
 bool pkgDPkgPM::CloseLog()
 {
+   char timestr[200];
+   time_t t = time(NULL);
+   struct tm *tmp = localtime(&t);
+   strftime(timestr, sizeof(timestr), "%F  %T", tmp);
+
    if(term_out)
    {
-      char outstr[200];
-      time_t t = time(NULL);
-      struct tm *tmp = localtime(&t);
-      strftime(outstr, sizeof(outstr), "%F  %T", tmp);
       fprintf(term_out, "Log ended: ");
-      fprintf(term_out, "%s", outstr);
+      fprintf(term_out, "%s", timestr);
       fprintf(term_out, "\n");
       fclose(term_out);
    }
    term_out = NULL;
+
+   if(history_out)
+   {
+      if (dpkg_error.size() > 0)
+        fprintf(history_out, "Error: %s\n", dpkg_error.c_str());
+      fprintf(history_out, "End-Date: %s\n", timestr);
+      fclose(history_out);
+   }
+
    return true;
 }
                                                                        /*}}}*/
@@ -1059,11 +1117,14 @@ bool pkgDPkgPM::Go(int OutStatusFd)
            RunScripts("DPkg::Post-Invoke");
 
         if (WIFSIGNALED(Status) != 0 && WTERMSIG(Status) == SIGSEGV) 
-           _error->Error("Sub-process %s received a segmentation fault.",Args[0]);
+           strprintf(dpkg_error, "Sub-process %s received a segmentation fault.",Args[0]);
         else if (WIFEXITED(Status) != 0)
-           _error->Error("Sub-process %s returned an error code (%u)",Args[0],WEXITSTATUS(Status));
+           strprintf(dpkg_error, "Sub-process %s returned an error code (%u)",Args[0],WEXITSTATUS(Status));
         else 
-           _error->Error("Sub-process %s exited unexpectedly",Args[0]);
+           strprintf(dpkg_error, "Sub-process %s exited unexpectedly",Args[0]);
+
+        if(dpkg_error.size() > 0)
+           _error->Error(dpkg_error.c_str());
 
         if(stopOnError) 
         {
index 43e5c7d45df21d251923233c2e02e0e68f66d865..330c788a25319fc74e5cea393946bebfe49b893f 100644 (file)
@@ -29,7 +29,9 @@ class pkgDPkgPM : public pkgPackageManager
    char dpkgbuf[1024];
    int dpkgbuf_pos;
    FILE *term_out;
-   
+   FILE *history_out;
+   string dpkg_error;
+
    protected:
 
    // progress reporting
@@ -66,6 +68,7 @@ class pkgDPkgPM : public pkgPackageManager
    // Helpers
    bool RunScriptsWithPkgs(const char *Cnf);
    bool SendV2Pkgs(FILE *F);
+   void WriteHistoryTag(string tag, string value);
 
    // dpkg log
    bool OpenLog();
index d8c201b9de02c22e887d9148572474171632a327..6310aff112a1ae94ecd4e587e1fed27ecf47dc49 100644 (file)
@@ -75,6 +75,7 @@ bool pkgInitConfig(Configuration &Cnf)
    // State   
    Cnf.Set("Dir::Log","var/log/apt");
    Cnf.Set("Dir::Log::Terminal","term.log");
+   Cnf.Set("Dir::Log::History","history.log");
 
    // Translation
    Cnf.Set("APT::Acquire::Translation", "environment");
index 3e924d3832df311a5077886456a1dcb8121351b0..9a6e5d1555be6f005ca52fdb61d36e9603be3bf2 100644 (file)
@@ -1,5 +1,13 @@
 /var/log/apt/term.log {
-  rotate 6
+  rotate 12
+  monthly
+  compress
+  missingok
+  notifempty
+}
+
+/var/log/apt/history.log {
+  rotate 12
   monthly
   compress
   missingok
index f14e3fe525bbb26acebac854f5743a04a58b47e6..c2c3524a6906a67c5485f9b4a6f9b22cc41bff3f 100644 (file)
@@ -2,8 +2,20 @@ apt (0.7.25.4) UNRELEASED; urgency=low
 
   [ Ivan Masár ]
   * Slovak translation update. Closes: #568294
+  
+  [ Michael Vogt ]
+  * merged lp:~mvo/apt/history
+    - this writes a /var/log/apt/history tagfile that contains details
+      from the transaction (complements term.log)
+  * methods/http.cc:
+    - add cache-control headers even if no cache is given to allow
+      adding options for intercepting proxies
+    - add Acquire::http::ProxyAutoDetect configuration that 
+      can be used to call a external helper to figure out the 
+      proxy configuration and return it to apt via stdout
+      (this is a step towards WPAD and zeroconf/avahi support)
 
- -- Christian Perrier <bubulle@debian.org>  Wed, 03 Feb 2010 20:08:19 +0100
+ -- Michael Vogt <michael.vogt@ubuntu.com>  Fri, 18 Dec 2009 16:54:18 +0100
 
 apt (0.7.25.3) unstable; urgency=low
 
@@ -12,7 +24,7 @@ apt (0.7.25.3) unstable; urgency=low
 
   [ David Kalnischkies ]
   * apt-pkg/contrib/macros.h:
-    - install the header system.h with a new name to be able to use 
+    - install the header system.h with a new name to be able to use
       it in other headers (Closes: #567662)
   * cmdline/acqprogress.cc:
     - Set Mode to Medium so that the correct prefix is used.
@@ -21,7 +33,7 @@ apt (0.7.25.3) unstable; urgency=low
     - generate sha1 and sha256 checksums for dsc (Closes: #567343)
   * cmdline/apt-get.cc:
     - don't mark as manually if in download only (Closes: #468180)
-  
+
  -- Michael Vogt <mvo@debian.org>  Mon, 01 Feb 2010 18:41:15 +0100
 
 apt (0.7.25.2) unstable; urgency=low
@@ -45,7 +57,7 @@ apt (0.7.25.2) unstable; urgency=low
       packages that are not in the extended_states file yet
       (closes: #534920)
   * ftparchive/writer.{cc,h}:
-    - merge crash fix for apt-ftparchive on hurd, thanks to 
+    - merge crash fix for apt-ftparchive on hurd, thanks to
       Samuel Thibault for the patch (closes: #566664)
 
   [ David Kalnischkies ]
@@ -84,7 +96,7 @@ apt (0.7.25.1) unstable; urgency=low
   * French manpage translation update
   * Russian translation update by Yuri Kozlov
     Closes: #564171
-  
+
   [Chris Leick]
   * spot & fix various typos in all manpages
   * German manpage translation update
index ddee863883eb6c0965d0fc6402c5c7f6fb61a79a..233fa2b7d7b0ac69d4cc25b21066bfb4fcce95cf 100644 (file)
@@ -329,6 +329,14 @@ Dir "/"
   // Location of the logfile
   Log "var/log/apt" {
        Terminal "term.log";
+       History "history.log";
+  };
+
+  // Media 
+  Media 
+  {
+       // Media AutoDetect mount path
+       MountPath "/media/apt";
   };
 
   // Media 
index 6d694e7c97bafc384c815360635973c0b32c058b..bf4281e403586a9ef73838d49e780ac49de34df6 100644 (file)
@@ -219,7 +219,7 @@ bool CDROMMethod::Fetch(FetchItem *Itm)
       return true;
    }
 
-   bool AutoDetect = _config->FindB("Acquire::cdrom::AutoDetect", false);
+   bool AutoDetect = _config->FindB("Acquire::cdrom::AutoDetect", true);
    CDROM = _config->FindDir("Acquire::cdrom::mount","/cdrom/");
    if (Debug)
       clog << "Looking for CDROM at " << CDROM << endl;
index 2dae87a02be878cb3da87c0c18336a8633b2c743..b054446910ae8004cbd85bdd3e1306f5f40621d5 100644 (file)
@@ -682,23 +682,25 @@ void HttpMethod::SendReq(FetchItem *Itm,CircleBuf &Out)
                 and a no-store directive for archives. */
       sprintf(Buf,"GET %s HTTP/1.1\r\nHost: %s\r\n",
              Itm->Uri.c_str(),ProperHost.c_str());
-      // only generate a cache control header if we actually want to 
-      // use a cache
-      if (_config->FindB("Acquire::http::No-Cache",false) == false)
+   }
+   // generate a cache control header (if needed)
+   if (_config->FindB("Acquire::http::No-Cache",false) == true) 
+   {
+      strcat(Buf,"Cache-Control: no-cache\r\nPragma: no-cache\r\n");
+   }
+   else
+   {
+      if (Itm->IndexFile == true) 
       {
-        if (Itm->IndexFile == true)
-           sprintf(Buf+strlen(Buf),"Cache-Control: max-age=%u\r\n",
-                   _config->FindI("Acquire::http::Max-Age",0));
-        else
-        {
-           if (_config->FindB("Acquire::http::No-Store",false) == true)
-              strcat(Buf,"Cache-Control: no-store\r\n");
-        }       
+        sprintf(Buf+strlen(Buf),"Cache-Control: max-age=%u\r\n",
+                _config->FindI("Acquire::http::Max-Age",0));
+      }
+      else
+      {
+        if (_config->FindB("Acquire::http::No-Store",false) == true)
+           strcat(Buf,"Cache-Control: no-store\r\n");
       }
    }
-   // generate a no-cache header if needed
-   if (_config->FindB("Acquire::http::No-Cache",false) == true)
-      strcat(Buf,"Cache-Control: no-cache\r\nPragma: no-cache\r\n");
 
    
    string Req = Buf;
@@ -1071,7 +1073,11 @@ bool HttpMethod::Configuration(string Message)
    PipelineDepth = _config->FindI("Acquire::http::Pipeline-Depth",
                                  PipelineDepth);
    Debug = _config->FindB("Debug::Acquire::http",false);
-   
+   AutoDetectProxyCmd = _config->Find("Acquire::http::ProxyAutoDetect");
+
+   // Get the proxy to use
+   AutoDetectProxy();
+
    return true;
 }
                                                                        /*}}}*/
@@ -1321,6 +1327,49 @@ int HttpMethod::Loop()
    return 0;
 }
                                                                        /*}}}*/
+// HttpMethod::AutoDetectProxy - auto detect proxy                     /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool HttpMethod::AutoDetectProxy()
+{
+   if (AutoDetectProxyCmd.empty())
+      return true;
+
+   if (Debug)
+      clog << "Using auto proxy detect command: " << AutoDetectProxyCmd << endl;
+
+   int Pipes[2] = {-1,-1};
+   if (pipe(Pipes) != 0)
+      return _error->Errno("pipe", "Failed to create Pipe");
+
+   pid_t Process = ExecFork();
+   if (Process == 0)
+   {
+      dup2(Pipes[1],STDOUT_FILENO);
+      SetCloseExec(STDOUT_FILENO,false);
+      
+      const char *Args[2];
+      Args[0] = AutoDetectProxyCmd.c_str();
+      Args[1] = 0;
+      execv(Args[0],(char **)Args);
+      cerr << "Failed to exec method " << Args[0] << endl;
+      _exit(100);
+   }
+   char buf[512];
+   int InFd = Pipes[0];
+   if (read(InFd, buf, sizeof(buf)) < 0)
+      return _error->Errno("read", "Failed to read");
+   ExecWait(Process, "ProxyAutoDetect");
+   
+   if (Debug)
+      clog << "auto detect command returned: '" << buf << "'" << endl;
+
+   if (strstr(buf, "http://") == buf)
+      _config->Set("Acquire::http::proxy", _strstrip(buf));
+
+   return true;
+}
+                                                                       /*}}}*/
 
 int main()
 {
index 13f02ec77b0b0c3d7560128ed07bd7c938c2ff50..ceee36cbeb9814ae3380a4637f912e334d1e4921 100644 (file)
@@ -134,6 +134,7 @@ class HttpMethod : public pkgAcqMethod
    bool Flush(ServerState *Srv);
    bool ServerDie(ServerState *Srv);
    int DealWithHeaders(FetchResult &Res,ServerState *Srv);
+   bool AutoDetectProxy();
 
    virtual bool Fetch(FetchItem *);
    virtual bool Configuration(string Message);
@@ -145,6 +146,7 @@ class HttpMethod : public pkgAcqMethod
    static void SigTerm(int);
    
    string NextURI;
+   string AutoDetectProxyCmd;
    
    public:
    friend class ServerState;