[Aptitude-devel] r3103 - in branches/aptitude-0.3/aptitude: . src

Daniel Burrows dburrows@costa.debian.org
Wed, 27 Apr 2005 00:19:54 +0000


Author: dburrows
Date: Wed Apr 27 00:19:51 2005
New Revision: 3103

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/ui.cc
Log:
Switch the pre-install broken fixing to use the new solution mechanism.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Wed Apr 27 00:19:51 2005
@@ -1,5 +1,11 @@
 2005-04-26  Daniel Burrows  <dburrows@debian.org>
 
+	* src/ui.cc:
+
+	  Eliminate all uses of try_fix_broken() in the pre-installation
+	  phase; in the process, factored out a bunch of common code from
+	  some of the preview setup functions.
+
 	* src/generic/aptcache.h:
 
 	  Pack the extended state information more tightly using field

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	Wed Apr 27 00:19:51 2005
@@ -763,7 +763,6 @@
 }
 
 static void actually_do_package_run();
-static void fix_pkgs_and_do_package_run();
 
 static void reset_preview()
 {
@@ -821,10 +820,60 @@
     active_preview_tree->show();
 }
 
-// Note that there's currently not a nice way to revert changes made by the
-// fixer (or indeed even see them)  This should be fixed at the same time that
-// the issue with alerting the user to dependencies is fixed (same problem)
-//
+static void fixer_dialog_done()
+{
+  if(active_preview_tree)
+    active_preview_tree->build_tree();
+  do_package_run_or_show_preview();
+}
+
+static void install_fixer_dialog()
+{
+  vscreen_widget *w=make_solution_dialog();
+  w->destroyed.connect(sigc::ptr_fun(fixer_dialog_done));
+  popup_widget(w, true);
+}
+
+static void auto_fix_broken()
+{
+  undo_group *undo=new apt_undo_group;
+
+  try
+    {
+      assert((*apt_cache_file)->resolver_exists());
+
+      aptitude_resolver::solution sol=(*apt_cache_file)->get_current_solution();
+
+      (*apt_cache_file)->apply_current_solution(undo);
+      show_message(fragf("%s%n%n%F",
+			 _("Some packages were broken and have been fixed:"),
+			 solution_fragment(sol)),
+		   NULL);
+    }
+  catch(NoMoreSolutions)
+    {
+      show_message(_("No solution to these dependency problems exists!"),
+		   NULL,
+		   get_color("Error"));
+    }
+  catch(NoMoreTime)
+    {
+      show_message(attr_fragment(fragf(_("Ran out of time while trying to resolver dependencies (press \"%s\" to try harder)"),
+				       global_bindings.keyname("NextSolution").c_str()),
+				 get_color("Error")),
+		   NULL);
+    }
+
+  if(!undo->empty())
+    apt_undos->add_item(undo);
+  else
+    delete undo;
+
+  if(active_preview_tree)
+    active_preview_tree->build_tree();
+}
+
+
 //  Huge FIXME: the preview interacts badly with the menu.  This can be solved
 // in a couple ways, including having the preview be a popup dialog -- the best
 // thing IMO, though, would be to somehow allow particular widgets to override
@@ -836,56 +885,33 @@
     {
       if(!active_download)
 	{
+	  // whatever we call will chain to the next appropriate
+	  // routine.
 	  if((*apt_cache_file)->BrokenCount()>0)
 	    {
 	      if(_config->FindB(PACKAGE "::Auto-Fix-Broken", true))
 		{
-		  undo_group *undo=new apt_undo_group;
-		  (*apt_cache_file)->try_fix_broken(undo);
-		  if(!undo->empty())
-		    apt_undos->add_item(undo);
-		  else
-		    delete undo;
-
-		  // Ok, we (hopefully) modified stuff; be nice and tell
-		  // the user.
-
-		  if(active_preview_tree)
-		    active_preview_tree->build_tree();
+		  auto_fix_broken();
 		  do_show_preview();
-
-		  if((*apt_cache_file)->BrokenCount()==0)
-		    show_message(_("Some packages were broken and have been fixed"));
-		  else
-		    show_message(_("Some broken packages could not be fixed!"),
-						NULL,
-				 get_color("Error"));
-
-		  return;
 		}
 	      else
-		{
-		  prompt_yesno(_("Some packages are broken.  Try to fix them?"),
-			       true,
-			       arg(sigc::ptr_fun(fix_pkgs_and_do_package_run)),
-			       NULL);
-		  return;
-		  // Wait to see what the user says
-		}
+		install_fixer_dialog();
+
+	      return;
 	    }
 
 	  if(getuid()==0  || !aptcfg->FindB(PACKAGE "::Warn-Not-Root", true))
 	    check_package_trust();
 	  else
-	{
-	  popup_widget(vs_dialog_yesno(_("Installing/removing packages requires administrative privileges, which\nyou currently do not have.  Would you like to change to the root account?\n"),
-				       arg(sigc::bind(sigc::ptr_fun(&do_su_to_root),
+	    {
+	      popup_widget(vs_dialog_yesno(_("Installing/removing packages requires administrative privileges, which\nyou currently do not have.  Would you like to change to the root account?\n"),
+					   arg(sigc::bind(sigc::ptr_fun(&do_su_to_root),
 						      "-i")),
-				       _("Become root"),
-				       arg(sigc::ptr_fun(&check_package_trust)),
-				       _("Don't become root"),
-				       get_color("Error")));
-	}
+					   _("Become root"),
+					   arg(sigc::ptr_fun(&check_package_trust)),
+					   _("Don't become root"),
+					   get_color("Error")));
+	    }
 	}
       else
 	show_message(_("A package-list update or install run is already taking place."), NULL, get_color("Error"));
@@ -946,21 +972,6 @@
     }
 }
 
-static void fix_pkgs_and_do_package_run()
-{
-  if(apt_cache_file)
-    {
-      undo_group *undo=new apt_undo_group;
-      (*apt_cache_file)->try_fix_broken(undo);
-      if(!undo->empty())
-	apt_undos->add_item(undo);
-      else
-	delete undo;
-
-      do_package_run_or_show_preview();
-    }
-}
-
 static bool can_start_download()
 {
   return !active_download;
@@ -975,12 +986,13 @@
       else if((*apt_cache_file)->BrokenCount()>0)
 	{
 	  if(aptcfg->FindB(PACKAGE "::Auto-Fix-Broken", true))
-	    fix_pkgs_and_do_package_run();
+	    {
+	      auto_fix_broken();
+	      if(active_preview_tree)
+		active_preview_tree->build_tree();
+	    }
 	  else
-	    prompt_yesno(_("Some packages are broken.  Try to fix them?"),
-			 true,
-			 arg(sigc::ptr_fun(fix_pkgs_and_do_package_run)),
-			 arg(sigc::ptr_fun(do_package_run_or_show_preview)));
+	    install_fixer_dialog();
 	}
       else
 	do_package_run_or_show_preview();