[Aptitude-svn-commit] r4038 - in branches/aptitude-0.3/aptitude: . src src/cmdline

Daniel Burrows dburrows at costa.debian.org
Fri Sep 2 22:34:14 UTC 2005


Author: dburrows
Date: Fri Sep  2 22:34:10 2005
New Revision: 4038

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/cmdline/cmdline_update.cc
   branches/aptitude-0.3/aptitude/src/download.cc
   branches/aptitude-0.3/aptitude/src/download.h
   branches/aptitude-0.3/aptitude/src/ui.cc
Log:
Split the package-list updating code around the download operation.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Fri Sep  2 22:34:10 2005
@@ -1,5 +1,11 @@
 2005-09-02  Daniel Burrows  <dburrows at debian.org>
 
+	* src/cmdline/cmdline_update.cc, src/download.cc, src/download.h:
+
+	  Split the package-list updating code around the download
+	  operation, so that the download itself can be pushed into a
+	  separate thread eventually.
+
 	* configure.ac, src/download_bar.cc, src/download.cc, src/download_list.cc, src/download_screen.cc, src/vscreen/Makefile.am, src/vscreen/curses++.cc, src/vscreen/vscreen.cc, src/vscreen/vscreen.h:
 
 	  Explicitly support and use threading in the vscreen core.  The

Modified: branches/aptitude-0.3/aptitude/src/cmdline/cmdline_update.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/cmdline/cmdline_update.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/cmdline/cmdline_update.cc	Fri Sep  2 22:34:10 2005
@@ -4,6 +4,8 @@
 
 #include "../download.h"
 
+#include "cmdline_progress.h"
+
 #include <aptitude.h>
 
 #include <generic/apt.h>
@@ -31,10 +33,20 @@
       return -1;
     }
 
-  int rval=do_pkglist_update(&progress, true)?0:-1;
+  download_manager *m = gen_cmdline_download_progress();
+  pkgAcquire *acq = prepare_pkglist_update(&progress, true, m);
+
+  int rval = 0;
+
+  if(acq != NULL)
+    {
+      pkgAcquire::RunResult res = acq->Run();
+      if(!finish_pkglist_update(&progress, true, m, acq, res))
+	rval = -1;
+    }
 
   if(_error->PendingError())
-    rval=-1;
+    rval = -1;
 
   _error->DumpErrors();
 

Modified: branches/aptitude-0.3/aptitude/src/download.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/download.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/download.cc	Fri Sep  2 22:34:10 2005
@@ -75,15 +75,14 @@
   bool get_aborted() {return aborted;}
 };
 
-bool do_pkglist_update(OpProgress *load_progress,
-		       bool text_download)
-  // I made heavy reference here to apt-get and console-apt's code..
-  // As a result, this routine is terribly hairy :(
+pkgAcquire * prepare_pkglist_update(OpProgress *load_progress,
+				    bool text_download,
+				    download_manager *manager)
 {
   pkgSourceList src_list;
 
   if(!(*apt_cache_file)->save_selection_list(*load_progress))
-    return false;
+    return NULL;
 
   // FIXME: should save_selection_list do this?
   load_progress->Done();
@@ -91,7 +90,7 @@
   if(src_list.ReadMainList()==false)
     {
       _error->Error(_("Couldn't read list of package sources"));
-      return false;
+      return NULL;
     }
 
   // Lock the list directory
@@ -102,59 +101,43 @@
       if(_error->PendingError()==true)
 	{
 	  _error->Error(_("Couldn't lock list directory..are you root?"));
-	  return false;
+	  return NULL;
 	}
     }
 
-  download_manager *download_progress;
-  if(!text_download)
-    download_progress=gen_download_progress(false, _("Updating package lists"),
-					    _("View the progress of the package list update"),
-					    _("List Update"),
-					    NULL);
-  else
-    download_progress=gen_cmdline_download_progress();
-  pkgAcquire fetcher(download_progress);
+  pkgAcquire *fetcher = new pkgAcquire(manager);
 
-  if(!src_list.GetIndexes(&fetcher))
+  if(!src_list.GetIndexes(fetcher))
     {
-      delete download_progress;
-      return false;
+      delete fetcher;
+      return NULL;
     }
 
-  switch(fetcher.Run(aptcfg->FindI(PACKAGE "::UI::Download-Poll-Interval", 50000)))
-    // At this point the widget should be deleted
-    {
-    case pkgAcquire::Failed:
-    case pkgAcquire::Cancelled:
-      for(pkgAcquireIterator i=fetcher.ItemsBegin(); i!=fetcher.ItemsEnd(); ++i)
-	(*i)->Finished();
-
-      download_progress->Complete();
+  return fetcher;
+}
 
-      delete download_progress;
+bool finish_pkglist_update(OpProgress *load_progress,
+			   bool text_download,
+			   download_manager *manager,
+			   pkgAcquire *fetcher,
+			   pkgAcquire::RunResult res)
+{
+  manager->Complete();
 
+  if(res != pkgAcquire::Continue)
+    {
       apt_reload_cache(load_progress, true);
-      return false;  // Should I return true for cancelled?
-    case pkgAcquire::Continue:
-      for(pkgAcquireIterator i=fetcher.ItemsBegin(); i!=fetcher.ItemsEnd(); ++i)
-	if((*i)->Status!=pkgAcquire::Item::StatDone)
-	  (*i)->Finished();
-
-      break;
+      return false;
     }
 
-  // Clean old stuff out (?)
-  if(fetcher.Clean(aptcfg->FindDir("Dir::State::lists"))==false ||
-     fetcher.Clean(aptcfg->FindDir("Dir::State::lists")+"partial/")==false)
+  // Clean old stuff out
+  if(fetcher->Clean(aptcfg->FindDir("Dir::State::lists"))==false ||
+     fetcher->Clean(aptcfg->FindDir("Dir::State::lists")+"partial/")==false)
     {
       _error->Error(_("Couldn't clean out list directories"));
-      delete download_progress;
       return false;
     }
 
-  download_progress->Complete();
-
   apt_reload_cache(load_progress, true);
 
   if(aptcfg->FindB(PACKAGE "::Forget-New-On-Update", false))

Modified: branches/aptitude-0.3/aptitude/src/download.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/download.h	(original)
+++ branches/aptitude-0.3/aptitude/src/download.h	Fri Sep  2 22:34:10 2005
@@ -9,14 +9,36 @@
 
 #include "vscreen/vs_minibuf_win.h"
 
+#include <apt-pkg/acquire.h>
+
 class OpProgress;
+class pkgAcquire;
+class download_manager;
 
-bool do_pkglist_update(OpProgress *load_progress,
-		       bool text_download);
-// Performs a package-list update.  load_progress is a progress object which
-// should be used to display the progress when the package cache is reloaded.
-//
-// Returns true if everything completed successfully, false otherwise.
+/** Do the work to prepare an Acquire object for a package-list update
+ *  operation.  Should be performed in the main UI thread.  The object
+ *  returned is ready for Run() to be called; the manager is NOT owned
+ *  by it and should be deallocated separately by the caller.
+ *
+ *  \return the new Acquire object, or \b NULL if an error was encountered.
+ */
+pkgAcquire *prepare_pkglist_update(OpProgress *load_progress,
+				   bool text_download,
+				   download_manager *manager);
+
+/** Finish updating the package lists given that the download returned
+ *  res.
+ *
+ *  \param load_progress a progress indicator for the cache reload
+ *  \param text_download if \b true, the download is in text mode
+ *  \param manager the manager of the download
+ *  \param res the outcome of the download (return value of Run)
+ */
+bool finish_pkglist_update(OpProgress *load_progress,
+			   bool text_download,
+			   download_manager *manager,
+			   pkgAcquire *fetcher,
+			   pkgAcquire::RunResult res);
 
 bool do_install_run(OpProgress *load_progress,
 		    bool text_download, bool download_only);

Modified: branches/aptitude-0.3/aptitude/src/ui.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/ui.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/ui.cc	Fri Sep  2 22:34:10 2005
@@ -1,8 +1,6 @@
 // ui.cc
 //
-//  Copyright 2000-2005 Daniel Burrows <dburrows at debian.org>
-//
-//   Copyright (C) 2005 Daniel Burrows
+//   Copyright 2000-2005 Daniel Burrows <dburrows at debian.org>
 //
 //   This program is free software; you can redistribute it and/or
 //   modify it under the terms of the GNU General Public License as
@@ -1127,15 +1125,29 @@
 
 static void really_do_update_lists()
 {
-  active_download=true;
+  active_download = true;
 
-  vs_progress_ref p=gen_progress_bar();
+  vs_progress_ref p = gen_progress_bar();
+
+  download_manager *m = gen_download_progress(false, _("Updating package lists"),
+					      _("View the progress of the package list update"),
+					      _("List Update"),
+					      NULL);
 
-  do_pkglist_update(p.unsafe_get_ref(), false);
+  pkgAcquire *acq = prepare_pkglist_update(p.unsafe_get_ref(), false, m);
+
+  if(acq != NULL)
+    {
+      pkgAcquire::RunResult res = acq->Run(aptcfg->FindI(PACKAGE "::UI::Download-Poll-Interval", 50000));
+      finish_pkglist_update(p.unsafe_get_ref(), false, m, acq, res);
+    }
+
+  delete acq;
+  delete m;
 
   p->destroy();
 
-  active_download=false;
+  active_download = false;
 }
 
 void do_update_lists()



More information about the Aptitude-svn-commit mailing list