On Fri, Oct 07, 2005 at 06:52:51PM -0700, Daniel Burrows <[EMAIL PROTECTED]> 
was heard to say:
> On Sat, Oct 08, 2005 at 03:25:17AM +0200, "Steinar H. Gunderson" <[EMAIL 
> PROTECTED]> was heard to say:
> > aptitude has a bit of an odd tendency to do its initialization twice:
> > 
> >   baby:~> LANG=C sudo aptitude install nonexistant-package
> >   Reading package lists... Done
> >   Building dependency tree... Done
> >   Reading extended state information       
> >   Initializing package states... Done
> >   Reading task descriptions... Done  
> >   Building tag database... Done    
> >   Couldn't find any package whose name or description matched 
> > "nonexistant-package"
> >   The following packages have been kept back:
> >     abiword-common abiword-gnome ndiswrapper-utils 
> >   0 packages upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
> >   Need to get 0B of archives. After unpacking 0B will be used.
> > 
> >   [and here the second initialization:]
> >   Reading package lists... Done
> >   Building dependency tree... Done
> >   Reading extended state information       
> >   Initializing package states... Done
> >   Reading task descriptions... Done  
> >   Building tag database... Done    
> >   
> > This is rather slow and a bit annoying -- I have no idea why it insists
> > on doing the last part, and can see no bad effects if I Ctrl-C it.
> 
>   The attached patch should fix this bug.

  While I have the right patch in my repository, I was in a hurry on my
way to eat dinner before and I didn't extract enough context, so as
anyone who tries to apply what I posted will notice...it doesn't compile.
This patch should.

  Daniel
Fri Oct  7 18:50:39 PDT 2005  Daniel Burrows <[EMAIL PROTECTED]>
  * Don't reload the cache more than is absolutely necessary after an install 
operation. (Closes: #332708)
Fri Oct  7 18:48:14 PDT 2005  Daniel Burrows <[EMAIL PROTECTED]>
  * Also don't reload the cache after an update except to the extent that it's 
required.
Fri Oct  7 18:44:17 PDT 2005  Daniel Burrows <[EMAIL PROTECTED]>
  * Always ensure that the cache gets loaded after a download process if the 
process closed it.
  This is the first stage of the fix for #332708; it will allow download 
processes to not
  reopen the cache themselves (instead depending on their caller to do it).
Fri Oct  7 18:34:41 PDT 2005  Daniel Burrows <[EMAIL PROTECTED]>
  * Expose an apt_load_cache function that only loads the cache if it's 
currently closed.
Fri Oct  7 18:11:49 PDT 2005  Daniel Burrows <[EMAIL PROTECTED]>
  * Extract the cache-closing code from apt_reload_cache and expose it as a new 
routine apt_close_cache.
diff -rN -udp old-head/src/generic/apt/apt.cc new-head/src/generic/apt/apt.cc
--- old-head/src/generic/apt/apt.cc     2005-10-07 21:12:52.975398176 -0700
+++ new-head/src/generic/apt/apt.cc     2005-10-07 18:34:37.000000000 -0700
@@ -210,8 +210,7 @@ void apt_init(OpProgress *progress_bar, 
     apt_reload_cache(progress_bar, do_initselections, status_fname);
 }
 
-void apt_reload_cache(OpProgress *progress_bar, bool do_initselections,
-                     const char * status_fname)
+void apt_close_cache()
 {
   cache_closed();
 
@@ -240,6 +239,13 @@ void apt_reload_cache(OpProgress *progre
       delete resman;
       resman = NULL;
     }
+}
+
+void apt_load_cache(OpProgress *progress_bar, bool do_initselections,
+                   const char * status_fname)
+{
+  if(apt_cache_file != NULL)
+    return;
 
   aptitudeCacheFile *new_file=new aptitudeCacheFile;
 
@@ -300,6 +306,13 @@ void apt_reload_cache(OpProgress *progre
   cache_reloaded();
 }
 
+void apt_reload_cache(OpProgress *progress_bar, bool do_initselections,
+                     const char * status_fname)
+{
+  apt_close_cache();
+  apt_load_cache(progress_bar, do_initselections, status_fname);
+}
+
 pkg_hier *get_user_pkg_hier()
 {
   if(!user_pkg_hier)
diff -rN -udp old-head/src/generic/apt/apt.h new-head/src/generic/apt/apt.h
--- old-head/src/generic/apt/apt.h      2005-10-07 21:12:52.976398024 -0700
+++ new-head/src/generic/apt/apt.h      2005-10-07 18:34:07.000000000 -0700
@@ -68,6 +68,23 @@ void apt_init(OpProgress *progess_bar,
 // from that (eg, config data) may be needed before apt_init itself is called.
 // This routine loads in the cache, source lists, etc.
 
+
+/** Close the cache file and destroy the associated data structures. */
+void apt_close_cache();
+
+/** If the cache is closed, open it; otherwise do nothing.
+ *
+ *  \param progress_bar a progress bar with which to display the
+ *                      status of loading the cache.
+ *  \param do_initselections if \b true, the selection status
+ *                           of packages will be set from aptitude's
+ *                           sticky database.
+ *  \param status_fname if not \b NULL, a filename to use in lieu
+ *                      of /var/lib/aptitude/pkgstates.
+ */
+void apt_load_cache(OpProgress *progress_bar,
+                   bool do_initselections, const char *status_fname = NULL);
+
 void apt_reload_cache(OpProgress *progress_bar,
                      bool do_initselections, const char * status_fname=NULL);
 //  Forces the cache to be reloaded.
diff -rN -udp old-head/src/generic/apt/download_install_manager.cc 
new-head/src/generic/apt/download_install_manager.cc
--- old-head/src/generic/apt/download_install_manager.cc        2005-10-07 
21:12:52.955401216 -0700
+++ new-head/src/generic/apt/download_install_manager.cc        2005-10-07 
18:49:36.000000000 -0700
@@ -185,17 +185,21 @@ download_manager::result download_instal
 {
   result run_res = execute_install_run(res, progress);
 
+  apt_close_cache();
+
   if(run_res != do_again)
     {
       if(log != NULL)
        log->Complete();
-      apt_reload_cache(&progress, true);
 
-      if(apt_cache_file != NULL &&
-        aptcfg->FindB(PACKAGE "::Forget-New-On-Install", false))
+      if(aptcfg->FindB(PACKAGE "::Forget-New-On-Install", false))
        {
-         (*apt_cache_file)->forget_new(NULL);
-         post_forget_new_hook();
+         apt_load_cache(&progress, true);
+         if(apt_cache_file != NULL)
+           {
+             (*apt_cache_file)->forget_new(NULL);
+             post_forget_new_hook();
+           }
        }
     }
 
diff -rN -udp old-head/src/generic/apt/download_update_manager.cc 
new-head/src/generic/apt/download_update_manager.cc
--- old-head/src/generic/apt/download_update_manager.cc 2005-10-07 
21:12:52.964399848 -0700
+++ new-head/src/generic/apt/download_update_manager.cc 2005-10-07 
18:36:42.000000000 -0700
@@ -23,6 +23,7 @@
 #include "config_signal.h"
 #include "download_signal_log.h"
 
+#include <apt-pkg/cachefile.h>
 #include <apt-pkg/clean.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/sourcelist.h>
@@ -100,11 +101,10 @@ download_update_manager::finish(pkgAcqui
   if(log != NULL)
     log->Complete();
 
+  apt_close_cache();
+
   if(res != pkgAcquire::Continue)
-    {
-      apt_reload_cache(&progress, true);
-      return failure;
-    }
+    return failure;
 
   // Clean old stuff out
   if(fetcher->Clean(aptcfg->FindDir("Dir::State::lists")) == false ||
@@ -114,17 +114,35 @@ download_update_manager::finish(pkgAcqui
       return failure;
     }
 
-  apt_reload_cache(&progress, true);
+  // Rebuild the apt caches as done in apt-get.  cachefile is scoped
+  // so it dies before we possibly-reload the cache.  This will do a
+  // little redundant work in visual mode, but avoids lots of
+  // redundant work at the command-line.
+  {
+    pkgCacheFile cachefile;
+    if(!cachefile.BuildCaches(progress, true))
+      {
+       _error->Error(_("Couldn't rebuild package cache"));
+       return failure;
+      }
+  }
 
-  if(apt_cache_file != NULL &&
-     aptcfg->FindB(PACKAGE "::Forget-New-On-Update", false))
+  bool need_forget_new = 
+    aptcfg->FindB(PACKAGE "::Forget-New-On-Update", false);
+
+  bool need_autoclean =
+    aptcfg->FindB(PACKAGE "::AutoClean-After-Update", false);
+
+  if(need_forget_new || need_autoclean)
+    apt_load_cache(&progress, true);
+
+  if(apt_cache_file != NULL && need_forget_new)
     {
       (*apt_cache_file)->forget_new(NULL);
       post_forget_new_hook();
     }
 
-  if(apt_cache_file != NULL &&
-     aptcfg->FindB(PACKAGE "::AutoClean-After-Update", false))
+  if(apt_cache_file != NULL && need_autoclean)
     {
       pre_autoclean_hook();
 
diff -rN -udp old-head/src/ui_download_manager.cc 
new-head/src/ui_download_manager.cc
--- old-head/src/ui_download_manager.cc 2005-10-07 21:12:52.966399544 -0700
+++ new-head/src/ui_download_manager.cc 2005-10-07 18:31:39.000000000 -0700
@@ -73,6 +73,8 @@ void ui_download_manager::done(download_
 
   download_manager::result run_res = manager->finish(res, *p.unsafe_get_ref());
 
+  apt_load_cache(p.unsafe_get_ref(), true);
+
   p->destroy();
 
   delete t;

Attachment: signature.asc
Description: Digital signature

Reply via email to