[Aptitude-svn-commit] r4328 - in branches/aptitude-0.3/aptitude: .
po src/generic/apt
Daniel Burrows
dburrows at costa.debian.org
Thu Sep 29 20:36:36 UTC 2005
Author: dburrows
Date: Thu Sep 29 20:36:33 2005
New Revision: 4328
Added:
branches/aptitude-0.3/aptitude/src/generic/apt/download_install_manager.cc
branches/aptitude-0.3/aptitude/src/generic/apt/download_install_manager.h
branches/aptitude-0.3/aptitude/src/generic/apt/download_manager.cc
branches/aptitude-0.3/aptitude/src/generic/apt/download_manager.h
branches/aptitude-0.3/aptitude/src/generic/apt/download_update_manager.cc
branches/aptitude-0.3/aptitude/src/generic/apt/download_update_manager.h
Modified:
branches/aptitude-0.3/aptitude/ChangeLog
branches/aptitude-0.3/aptitude/po/POTFILES.in
branches/aptitude-0.3/aptitude/src/generic/apt/Makefile.am
Log:
Lift the download code into classes and split it into different files.
Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog (original)
+++ branches/aptitude-0.3/aptitude/ChangeLog Thu Sep 29 20:36:33 2005
@@ -1,5 +1,11 @@
2005-09-29 Daniel Burrows <dburrows at debian.org>
+ * po/POTFILES.in, src/generic/apt/download_install_manager.cc, src/generic/apt/download_install_manager.h, src/generic/apt/download_manager.cc, src/generic/apt/download_manager.h, src/generic/apt/download_update_manager.cc, src/generic/apt/download_update_manager.h, src/generic/apt/Makefile.am:
+
+ Write a generic interface to manage operations that involve
+ downloading something and then doing more stuff, and transform
+ the old download code into subclasses of this interface.
+
* src/cmdline/cmdline_changelog.cc, src/cmdline/cmdline_do_action.cc, src/cmdline/cmdline_download.cc, src/cmdline/cmdline_progress.cc, src/cmdline/cmdline_progress.h, src/cmdline/cmdline_prompt.cc, src/cmdline/cmdline_update.cc, src/cmdline/cmdline_upgrade.cc, src/download.cc, src/download.h, src/download_list.cc, src/download_list.h, src/download_thread.cc, src/download_thread.h, src/generic/apt/acqprogress.cc, src/generic/apt/acqprogress.h, src/generic/apt/Makefile.am, src/Makefile.am, src/ui.cc, src/ui.h, src/view_changelog.cc:
Update include file locations and class names to refer to
Modified: branches/aptitude-0.3/aptitude/po/POTFILES.in
==============================================================================
--- branches/aptitude-0.3/aptitude/po/POTFILES.in (original)
+++ branches/aptitude-0.3/aptitude/po/POTFILES.in Thu Sep 29 20:36:33 2005
@@ -1,267 +1,277 @@
-src/apt_config_widgets.cc
-src/apt_config_widgets.h
-src/apt_info_tree.cc
-src/apt_info_tree.h
-src/aptitude.h
+src/mine/cmine.cc
+src/mine/cmine.h
+src/mine/board.cc
+src/mine/board.h
+src/ui.cc
+src/download_bar.cc
+src/download_bar.h
src/apt_options.cc
src/apt_options.h
-src/apt_undo_tree.cc
-src/apt_undo_tree.h
-src/broken_indicator.cc
-src/broken_indicator.h
+src/download_list.cc
+src/load_config.cc
+src/pkg_subtree.cc
+src/defaults.cc
+src/defaults.h
+src/ui.h
+src/download_screen.h
+src/pkg_item_with_subtree.h
+src/load_grouppolicy.cc
+src/vs_progress.cc
+src/load_grouppolicy.h
+src/apt_info_tree.h
+src/view_changelog.h
+src/main.cc
+src/menu_redirect.h
+src/dep_item.h
+src/pkg_columnizer.h
+src/edit_pkg_hier.cc
+src/pkg_tree.h
+src/download_list.h
+src/load_sortpolicy.cc
+src/download.cc
+src/cmdline_parse.h
+src/download.h
+src/pkg_sortpolicy.h
+src/desc_parse.h
+src/reason_fragment.cc
+src/pkg_ver_item.cc
+src/pkg_subtree.h
+src/pkg_ver_item.h
+src/pkg_grouppolicy.h
+src/cmdline/cmdline_show_broken.cc
+src/cmdline/cmdline_forget_new.h
+src/cmdline/cmdline_search.h
+src/cmdline/cmdline_download.h
+src/cmdline/cmdline_util.cc
src/cmdline/cmdline_action.cc
-src/cmdline/cmdline_action.h
+src/cmdline/cmdline_show_broken.h
+src/cmdline/cmdline_prompt.cc
+src/cmdline/cmdline_update.cc
+src/cmdline/cmdline_simulate.h
+src/cmdline/cmdline_update.h
+src/cmdline/cmdline_forget_new.cc
+src/cmdline/cmdline_upgrade.cc
src/cmdline/cmdline_changelog.cc
-src/cmdline/cmdline_changelog.h
-src/cmdline/cmdline_clean.cc
-src/cmdline/cmdline_clean.h
src/cmdline/cmdline_common.h
-src/cmdline/cmdline_do_action.cc
src/cmdline/cmdline_do_action.h
-src/cmdline/cmdline_download.cc
-src/cmdline/cmdline_download.h
-src/cmdline/cmdline_dump_resolver.cc
-src/cmdline/cmdline_dump_resolver.h
-src/cmdline/cmdline_forget_new.cc
-src/cmdline/cmdline_forget_new.h
-src/cmdline/cmdline_moo.cc
-src/cmdline/cmdline_moo.h
src/cmdline/cmdline_progress.cc
-src/cmdline/cmdline_progress.h
-src/cmdline/cmdline_prompt.cc
-src/cmdline/cmdline_prompt.h
-src/cmdline/cmdline_resolver.cc
-src/cmdline/cmdline_resolver.h
src/cmdline/cmdline_search.cc
-src/cmdline/cmdline_search.h
-src/cmdline/cmdline_show_broken.cc
-src/cmdline/cmdline_show_broken.h
+src/cmdline/cmdline_progress.h
+src/cmdline/cmdline_download.cc
+src/cmdline/cmdline_util.h
+src/cmdline/cmdline_action.h
src/cmdline/cmdline_show.cc
+src/cmdline/cmdline_clean.cc
src/cmdline/cmdline_show.h
src/cmdline/cmdline_simulate.cc
-src/cmdline/cmdline_simulate.h
+src/cmdline/cmdline_prompt.h
+src/cmdline/cmdline_clean.h
+src/cmdline/cmdline_changelog.h
+src/cmdline/cmdline_upgrade.h
+src/cmdline/cmdline_moo.cc
+src/cmdline/cmdline_moo.h
+src/cmdline/cmdline_do_action.cc
+src/cmdline/cmdline_dump_resolver.h
+src/cmdline/cmdline_dump_resolver.cc
+src/cmdline/cmdline_resolver.cc
+src/cmdline/cmdline_resolver.h
src/cmdline/cmdline_spinner.cc
src/cmdline/cmdline_spinner.h
-src/cmdline/cmdline_update.cc
-src/cmdline/cmdline_update.h
-src/cmdline/cmdline_upgrade.cc
-src/cmdline/cmdline_upgrade.h
-src/cmdline/cmdline_util.cc
-src/cmdline/cmdline_util.h
-src/cmdline_parse.cc
-src/cmdline_parse.h
-src/defaults.cc
-src/defaults.h
-src/dep_item.cc
-src/dep_item.h
-src/desc_parse.cc
-src/desc_parse.h
-src/download_bar.cc
-src/download_bar.h
-src/download.cc
-src/download.h
-src/download_item.cc
+src/pkg_columnizer.cc
src/download_item.h
-src/download_list.cc
-src/download_list.h
-src/download_manager.cc
-src/download_manager.h
-src/download_screen.cc
-src/download_screen.h
-src/download_thread.cc
-src/download_thread.h
-src/edit_pkg_hier.cc
-src/edit_pkg_hier.h
+src/generic/util/dense_setset.h
+src/generic/util/event_queue.h
+src/generic/util/exception.h
+src/generic/util/immset.h
+src/generic/util/mut_fun.h
+src/generic/util/setset.h
+src/generic/util/strhash.h
+src/generic/util/threads.cc
+src/generic/util/threads.h
+src/generic/util/undo.cc
+src/generic/util/undo.h
+src/generic/util/util.cc
+src/generic/util/util.h
+src/generic/util/slotarg.h
+src/generic/util/bool_accumulate.h
+src/generic/util/temp.h
+src/generic/util/temp.cc
+src/generic/util/exception.cc
+src/generic/apt/aptitudepolicy.cc
src/generic/apt/acqprogress.cc
src/generic/apt/acqprogress.h
-src/generic/apt/aptcache.cc
-src/generic/apt/aptcache.h
src/generic/apt/apt.cc
src/generic/apt/apt.h
-src/generic/apt/aptitudepolicy.cc
-src/generic/apt/aptitudepolicy.h
+src/generic/apt/aptcache.cc
+src/generic/apt/aptcache.h
src/generic/apt/aptitude_resolver.cc
+src/generic/apt/aptitudepolicy.h
src/generic/apt/aptitude_resolver.h
+src/generic/apt/apt_undo_group.cc
+src/generic/apt/tags.cc
src/generic/apt/aptitude_resolver_universe.cc
src/generic/apt/aptitude_resolver_universe.h
-src/generic/apt/apt_undo_group.cc
src/generic/apt/apt_undo_group.h
src/generic/apt/config_signal.cc
src/generic/apt/config_signal.h
src/generic/apt/infer_reason.cc
-src/generic/apt/infer_reason.h
src/generic/apt/matchers.cc
-src/generic/apt/matchers.h
src/generic/apt/pkg_acqfile.cc
-src/generic/apt/pkg_acqfile.h
src/generic/apt/pkg_changelog.cc
-src/generic/apt/pkg_changelog.h
src/generic/apt/pkg_hier.cc
src/generic/apt/pkg_hier_dump.cc
-src/generic/apt/pkg_hier.h
src/generic/apt/resolver_manager.cc
+src/generic/apt/tasks.cc
+src/generic/apt/infer_reason.h
+src/generic/apt/matchers.h
+src/generic/apt/pkg_acqfile.h
+src/generic/apt/pkg_changelog.h
+src/generic/apt/pkg_hier.h
src/generic/apt/resolver_manager.h
src/generic/apt/rev_dep_iterator.h
-src/generic/apt/tags.cc
src/generic/apt/tags.h
-src/generic/apt/tasks.cc
src/generic/apt/tasks.h
-src/generic/problemresolver/dummy_universe.cc
-src/generic/problemresolver/dummy_universe.h
-src/generic/problemresolver/dump_universe.h
-src/generic/problemresolver/exceptions.h
+src/generic/apt/download_manager.cc
+src/generic/apt/download_signal_log.cc
+src/generic/apt/download_signal_log.h
+src/generic/apt/download_manager.h
+src/generic/apt/download_install_manager.cc
+src/generic/apt/.#download_manager.h
+src/generic/apt/download_update_manager.h
+src/generic/apt/download_update_manager.cc
+src/generic/apt/download_install_manager.h
src/generic/problemresolver/problemresolver.h
-src/generic/problemresolver/resolver_undo.h
-src/generic/problemresolver/solution.h
src/generic/problemresolver/test.cc
-src/generic/util/dense_setset.h
-src/generic/util/event_queue.h
-src/generic/util/exception.h
-src/generic/util/immset.h
-src/generic/util/mut_fun.h
-src/generic/util/setset.h
-src/generic/util/strhash.h
-src/generic/util/threads.cc
-src/generic/util/threads.h
-src/generic/util/undo.cc
-src/generic/util/undo.h
-src/generic/util/util.cc
-src/generic/util/util.h
-src/load_config.cc
-src/load_config.h
-src/load_grouppolicy.cc
-src/load_grouppolicy.h
-src/load_pkgview.cc
-src/load_pkgview.h
-src/load_sortpolicy.cc
-src/load_sortpolicy.h
-src/main.cc
-src/menu_redirect.cc
-src/menu_redirect.h
-src/menu_tree.cc
-src/menu_tree.h
-src/mine/board.cc
-src/mine/board.h
-src/mine/cmine.cc
-src/mine/cmine.h
-src/pkg_columnizer.cc
-src/pkg_columnizer.h
-src/pkg_grouppolicy.cc
-src/pkg_grouppolicy.h
-src/pkg_info_screen.cc
-src/pkg_info_screen.h
-src/pkg_item.cc
-src/pkg_item.h
-src/pkg_item_with_subtree.h
-src/pkg_node.cc
-src/pkg_node.h
-src/pkg_sortpolicy.cc
-src/pkg_sortpolicy.h
-src/pkg_subtree.cc
-src/pkg_subtree.h
-src/pkg_tree.cc
-src/pkg_tree.h
-src/pkg_ver_item.cc
-src/pkg_ver_item.h
-src/pkg_view.cc
-src/pkg_view.h
-src/reason_fragment.cc
-src/reason_fragment.h
-src/solution_dialog.cc
-src/solution_dialog.h
-src/solution_fragment.cc
-src/solution_fragment.h
-src/solution_item.cc
-src/solution_item.h
-src/solution_screen.cc
-src/solution_screen.h
-src/trust.cc
-src/trust.h
-src/ui.cc
-src/ui.h
-src/view_changelog.cc
-src/view_changelog.h
-src/vscreen/bool_accumulate.h
-src/vscreen/columnify.cc
-src/vscreen/columnify.h
+src/generic/problemresolver/exceptions.h
+src/generic/problemresolver/solution.h
+src/generic/problemresolver/dump_universe.h
+src/generic/problemresolver/dummy_universe.h
+src/generic/problemresolver/dummy_universe.cc
+src/generic/problemresolver/resolver_undo.h
+src/vscreen/vs_minibuf_win.cc
+src/vscreen/vs_menubar.cc
+src/vscreen/vscreen.cc
+src/vscreen/vs_editline.cc
+src/vscreen/vs_pager.h
+src/vscreen/vs_center.cc
+src/vscreen/vs_bin.h
+src/vscreen/vs_togglebutton.h
+src/vscreen/vs_treeitem.cc
+src/vscreen/config/keybindings.cc
src/vscreen/config/colors.cc
src/vscreen/config/colors.h
src/vscreen/config/column_definition.cc
src/vscreen/config/column_definition.h
-src/vscreen/config/keybindings.cc
src/vscreen/config/keybindings.h
-src/vscreen/config/style.cc
src/vscreen/config/style.h
-src/vscreen/curses++.cc
+src/vscreen/config/style.cc
+src/vscreen/vs_text_layout.cc
+src/vscreen/vs_size_box.cc
+src/vscreen/vs_container.h
src/vscreen/curses++.h
-src/vscreen/fragment_cache.cc
-src/vscreen/fragment_cache.h
-src/vscreen/fragment.cc
-src/vscreen/fragment_contents.h
-src/vscreen/fragment.h
-src/vscreen/ref_ptr.h
-src/vscreen/slotarg.h
-src/vscreen/testvscreen.cc
-src/vscreen/transcode.cc
-src/vscreen/transcode.h
+src/vscreen/vs_layout_item.cc
+src/vscreen/vs_layout_item.h
+src/vscreen/vs_statuschoice.cc
+src/vscreen/columnify.h
+src/vscreen/vscreen_widget.h
+src/vscreen/vs_staticitem.cc
+src/vscreen/vs_passthrough.cc
+src/vscreen/vs_minibuf_win.h
src/vscreen/vs_bin.cc
-src/vscreen/vs_bin.h
+src/vscreen/vs_passthrough.h
+src/vscreen/vs_statuschoice.h
+src/vscreen/vs_radiogroup.cc
src/vscreen/vs_button.cc
src/vscreen/vs_button.h
-src/vscreen/vs_center.cc
-src/vscreen/vs_center.h
-src/vscreen/vs_container.cc
-src/vscreen/vs_container.h
-src/vscreen/vscreen.cc
-src/vscreen/vscreen.h
-src/vscreen/vscreen_widget.cc
-src/vscreen/vscreen_widget.h
-src/vscreen/vs_editline.cc
-src/vscreen/vs_editline.h
+src/vscreen/vs_radiogroup.h
+src/vscreen/vs_stacked.cc
+src/vscreen/vs_util.h
+src/vscreen/vs_treeitem.h
+src/vscreen/vs_size_box.h
src/vscreen/vs_frame.cc
-src/vscreen/vs_frame.h
-src/vscreen/vs_label.cc
-src/vscreen/vs_label.h
-src/vscreen/vs_layout_item.cc
-src/vscreen/vs_layout_item.h
-src/vscreen/vs_menubar.cc
src/vscreen/vs_menubar.h
-src/vscreen/vs_menu.cc
+src/vscreen/vscreen.h
+src/vscreen/vs_tree.cc
+src/vscreen/vs_editline.h
+src/vscreen/vscreen_widget.cc
+src/vscreen/vs_tree.h
src/vscreen/vs_menu.h
-src/vscreen/vs_minibuf_win.cc
-src/vscreen/vs_minibuf_win.h
+src/vscreen/vs_staticitem.h
+src/vscreen/vs_togglebutton.cc
+src/vscreen/vs_stacked.h
+src/vscreen/vs_text_layout.h
src/vscreen/vs_multiplex.cc
-src/vscreen/vs_multiplex.h
-src/vscreen/vs_pager.cc
-src/vscreen/vs_pager.h
-src/vscreen/vs_passthrough.cc
-src/vscreen/vs_passthrough.h
-src/vscreen/vs_radiogroup.cc
-src/vscreen/vs_radiogroup.h
src/vscreen/vs_scrollbar.cc
src/vscreen/vs_scrollbar.h
-src/vscreen/vs_size_box.cc
-src/vscreen/vs_size_box.h
-src/vscreen/vs_stacked.cc
-src/vscreen/vs_stacked.h
-src/vscreen/vs_staticitem.cc
-src/vscreen/vs_staticitem.h
-src/vscreen/vs_statuschoice.cc
-src/vscreen/vs_statuschoice.h
-src/vscreen/vs_subtree.h
+src/vscreen/vs_multiplex.h
src/vscreen/vs_table.cc
src/vscreen/vs_table.h
-src/vscreen/vs_text_layout.cc
-src/vscreen/vs_text_layout.h
-src/vscreen/vs_togglebutton.cc
-src/vscreen/vs_togglebutton.h
-src/vscreen/vs_transient.cc
-src/vscreen/vs_transient.h
-src/vscreen/vs_tree.cc
-src/vscreen/vs_tree.h
-src/vscreen/vs_treeitem.cc
-src/vscreen/vs_treeitem.h
+src/vscreen/fragment.cc
+src/vscreen/vs_frame.h
+src/vscreen/columnify.cc
+src/vscreen/testvscreen.cc
+src/vscreen/fragment.h
+src/vscreen/vs_pager.cc
+src/vscreen/vs_menu.cc
+src/vscreen/fragment_contents.h
+src/vscreen/vs_subtree.h
src/vscreen/vs_util.cc
-src/vscreen/vs_util.h
-src/vs_progress.cc
+src/vscreen/vs_label.cc
+src/vscreen/vs_label.h
+src/vscreen/vs_center.h
+src/vscreen/curses++.cc
+src/vscreen/vs_container.cc
+src/vscreen/vs_transient.h
+src/vscreen/vs_transient.cc
+src/vscreen/transcode.cc
+src/vscreen/fragment_cache.h
+src/vscreen/fragment_cache.cc
+src/vscreen/transcode.h
+src/vscreen/ref_ptr.h
+src/apt_config_widgets.cc
+src/pkg_item.cc
+src/pkg_tree.cc
+src/pkg_item.h
+src/apt_config_widgets.h
+src/desc_parse.cc
+src/load_sortpolicy.h
+src/pkg_sortpolicy.cc
+src/load_pkgview.cc
+src/reason_fragment.h
+src/load_pkgview.h
+src/view_changelog.cc
+src/aptitude.h
+src/pkg_node.cc
+src/pkg_info_screen.cc
+src/pkg_info_screen.h
+src/edit_pkg_hier.h
+src/download_thread.cc
+src/cmdline_parse.cc
+src/download_screen.cc
+src/load_config.h
+src/pkg_view.cc
+src/pkg_view.h
+src/pkg_grouppolicy.cc
src/vs_progress.h
+src/apt_info_tree.cc
+src/download_item.cc
+src/dep_item.cc
+src/pkg_node.h
+src/trust.h
+src/trust.cc
+src/download_thread.h
+src/broken_indicator.h
+src/broken_indicator.cc
+src/solution_fragment.h
+src/solution_fragment.cc
+src/solution_dialog.h
+src/solution_dialog.cc
+src/apt_undo_tree.cc
+src/solution_screen.cc
+src/solution_item.h
+src/solution_screen.h
+src/apt_undo_tree.h
+src/solution_item.cc
+src/menu_tree.h
+src/menu_redirect.cc
+src/menu_tree.cc
Modified: branches/aptitude-0.3/aptitude/src/generic/apt/Makefile.am
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/apt/Makefile.am (original)
+++ branches/aptitude-0.3/aptitude/src/generic/apt/Makefile.am Thu Sep 29 20:36:33 2005
@@ -29,6 +29,12 @@
apt_undo_group.h \
config_signal.cc \
config_signal.h \
+ download_manager.cc \
+ download_manager.h \
+ download_install_manager.cc \
+ download_install_manager.h \
+ download_update_manager.cc \
+ download_update_manager.h \
download_signal_log.cc \
download_signal_log.h \
infer_reason.cc \
Added: branches/aptitude-0.3/aptitude/src/generic/apt/download_install_manager.cc
==============================================================================
--- (empty file)
+++ branches/aptitude-0.3/aptitude/src/generic/apt/download_install_manager.cc Thu Sep 29 20:36:33 2005
@@ -0,0 +1,390 @@
+// download_install_manager.cc
+//
+// Copyright (C) 2005 Daniel Burrows
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of
+// the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; see the file COPYING. If not, write to
+// the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+
+#include "download_install_manager.h"
+
+#include "download_signal_log.h"
+
+#include <aptitude.h>
+
+#include <apt-pkg/acquire-item.h>
+#include <apt-pkg/dpkgpm.h>
+#include <apt-pkg/error.h>
+#include <apt-pkg/sourcelist.h>
+#include <apt-pkg/strutl.h>
+
+#include <generic/apt/config_signal.h>
+
+#include <generic/util/util.h>
+
+#include <errno.h>
+
+using namespace std;
+
+download_install_manager::download_install_manager()
+ : log(NULL), download_only(false), pm(new pkgDPkgPM(*apt_cache_file))
+{
+}
+
+download_install_manager::~download_install_manager()
+{
+ delete pm;
+}
+
+bool download_install_manager::do_log(const string &log,
+ const loglist &changed_packages)
+{
+ FILE *f = NULL;
+
+ if(log[0] == '|')
+ f = popen(log.c_str()+1, "w");
+ else
+ f = fopen(log.c_str(), "a");
+
+ if(!f)
+ {
+ _error->Errno(_("Unable to open %s to log actions"), log.c_str());
+
+ return false;
+ }
+
+ time_t curtime = time(NULL);
+ tm ltime;
+ string timestr;
+
+ if(localtime_r(&curtime, <ime) != NULL)
+ timestr = sstrftime("%a, %b %e %Y %T %z", <ime);
+ else
+ timestr = ssprintf(_("Error generating local time (%s)"),
+ sstrerror(errno).c_str());
+
+ fprintf(f, "Aptitude " VERSION ": %s\n%s\n\n",
+ _("log report"), timestr.c_str());
+ fprintf(f, _("IMPORTANT: this log only lists intended actions; actions which fail due to\ndpkg problems may not be completed.\n\n"));
+ fprintf(f, _("Will install %li packages, and remove %li packages.\n"),
+ (*apt_cache_file)->InstCount(), (*apt_cache_file)->DelCount());
+
+ if((*apt_cache_file)->UsrSize() > 0)
+ fprintf(f, _("%sB of disk space will be used\n"),
+ SizeToStr((*apt_cache_file)->UsrSize()).c_str());
+ else if((*apt_cache_file)->UsrSize() < 0)
+ fprintf(f, _("%sB of disk space will be freed\n"),
+ SizeToStr((*apt_cache_file)->UsrSize()).c_str());
+
+ fprintf(f, "===============================================================================\n");
+
+
+ for(loglist::const_iterator i = changed_packages.begin();
+ i != changed_packages.end(); ++i)
+ {
+ if(i->second == pkg_upgrade)
+ fprintf(f, _("[UPGRADE] %s %s -> %s\n"), i->first.Name(),
+ i->first.CurrentVer().VerStr(),
+ (*apt_cache_file)[i->first].CandidateVerIter(*apt_cache_file).VerStr());
+ else if(i->second == pkg_downgrade)
+ fprintf(f, _("[DOWNGRADE] %s %s -> %s\n"), i->first.Name(),
+ i->first.CurrentVer().VerStr(),
+ (*apt_cache_file)[i->first].CandidateVerIter(*apt_cache_file).VerStr());
+ else
+ if(i->second != pkg_unchanged)
+ {
+ const char *tag = NULL;
+ switch(i->second)
+ {
+ case pkg_remove:
+ tag = _("REMOVE");
+ break;
+ //case pkg_upgrade:
+ //tag=_("UPGRADE");
+ //break;
+ case pkg_install:
+ tag = _("INSTALL");
+ break;
+ case pkg_reinstall:
+ tag = _("REINSTALL");
+ break;
+ case pkg_hold:
+ tag = _("HOLD");
+ break;
+ case pkg_broken:
+ tag = _("BROKEN");
+ break;
+ case pkg_unused_remove:
+ tag = _("REMOVE, NOT USED");
+ break;
+ case pkg_auto_remove:
+ tag = _("REMOVE, DEPENDENCIES");
+ break;
+ case pkg_auto_install:
+ tag = _("INSTALL, DEPENDENCIES");
+ break;
+ case pkg_auto_hold:
+ tag = _("HOLD, DEPENDENCIES");
+ default:
+ tag = _("????????");
+ break;
+ }
+
+ fprintf(f, _("[%s] %s\n"), tag, i->first.Name());
+ }
+ }
+ fprintf(f, _("===============================================================================\n\nLog complete.\n"));
+
+ if(log[0] == '|')
+ pclose(f);
+ else
+ fclose(f);
+
+ return true;
+}
+struct download_install_manager::log_sorter
+{
+public:
+ inline bool operator()(const download_install_manager::logitem &a, const download_install_manager::logitem &b)
+ {
+ if(a.second<b.second)
+ return true;
+ else if(a.second>b.second)
+ return false;
+ else return strcmp(a.first.Name(), b.first.Name())<0;
+ }
+};
+
+void download_install_manager::log_changes()
+{
+ vector<string> logs;
+
+ string main_log = aptcfg->Find(PACKAGE "::Log", "/var/log/" PACKAGE);
+
+ if(!main_log.empty())
+ logs.push_back(main_log);
+
+ const Configuration::Item *parent = aptcfg->Tree(PACKAGE "::Log");
+
+ if(parent != NULL)
+ for(const Configuration::Item *curr = parent->Child;
+ curr != NULL; curr = curr->Next)
+ {
+ if(!curr->Value.empty())
+ logs.push_back(curr->Value);
+ }
+
+ if(!logs.empty())
+ {
+ loglist changed_packages;
+ for(pkgCache::PkgIterator i
+ = (*apt_cache_file)->PkgBegin(); !i.end(); i++)
+ {
+ pkg_action_state s = find_pkg_state(i);
+ if(s != pkg_unchanged)
+ changed_packages.push_back(logitem(i, s));
+ }
+
+ sort(changed_packages.begin(), changed_packages.end(), log_sorter());
+
+ for(vector<string>::iterator i
+ = logs.begin(); i != logs.end(); ++i)
+ do_log(*i, changed_packages);
+ }
+}
+
+bool download_install_manager::prepare(OpProgress &progress,
+ bool download_only,
+ pkgAcquireStatus *acqlog,
+ download_signal_log *signallog)
+{
+ log = signallog;
+
+ if(apt_cache_file == NULL)
+ {
+ _error->Error(_("The package cache is not available; unable to download and install packages."));
+ return false;
+ }
+
+ if(!(*apt_cache_file)->save_selection_list(progress))
+ return false;
+
+ progress.Done();
+
+ // Lock the archive directory..
+ FileFd lock;
+ if(aptcfg->FindB("Debug::NoLocking", false) == false)
+ {
+ lock.Fd(GetLock(aptcfg->FindDir("Dir::State::Lists")+"lock"));
+ if(_error->PendingError() == true)
+ {
+ _error->Error(_("Couldn't lock list directory..are you root?"));
+ return false;
+ }
+ }
+
+ // Get source lists.
+ pkgSourceList src_list;
+ if(!src_list.ReadMainList())
+ {
+ _error->Error(_("Couldn't read source list"));
+
+ return false;
+ }
+
+ fetcher = new pkgAcquire(acqlog);
+
+ if(!pm->GetArchives(fetcher, &src_list, apt_package_records) ||
+ _error->PendingError())
+ {
+ _error->Error(_("Internal error: couldn't generate list of packages to download"));
+
+ delete fetcher;
+ fetcher = NULL;
+ return false;
+ }
+
+ return true;
+}
+
+download_manager::result download_install_manager::execute_install_run(pkgAcquire::RunResult res,
+ OpProgress &progress)
+{
+ if(res != pkgAcquire::Continue)
+ return failure;
+ else if(download_only)
+ return success;
+
+ bool failed=false;
+ for(pkgAcquire::ItemIterator i = fetcher->ItemsBegin();
+ i != fetcher->ItemsEnd(); ++i)
+ {
+ if((*i)->Status == pkgAcquire::Item::StatDone &&
+ (*i)->Complete)
+ continue;
+
+ if((*i)->Status == pkgAcquire::Item::StatIdle)
+ continue;
+
+ failed=true;
+ break;
+ }
+
+ if(failed && !pm->FixMissing())
+ {
+ _error->Error(_("Unable to correct for unavailable packages"));
+ return failure;
+ }
+
+ log_changes();
+
+ pre_install_hook();
+#if 0
+ if(!text_download)
+ vscreen_suspend();
+#endif
+
+ // Note that someone could grab the lock before dpkg takes it;
+ // without a more complicated synchronization protocol (and I don't
+ // control the code at dpkg's end), them's the breaks.
+ apt_cache_file->ReleaseLock();
+
+ result rval = success;
+
+ pkgPackageManager::OrderResult pmres = pm->DoInstall(aptcfg->FindI("APT::Status-Fd", -1));
+ switch(pmres)
+ {
+ case pkgPackageManager::Failed:
+ _error->DumpErrors();
+ cerr << _("A package failed to install. Trying to recover:") << endl;
+ system("dpkg --configure -a");
+ _error->Discard();
+
+ rval = failure;
+ break;
+ case pkgPackageManager::Completed:
+#if 0
+ if(!text_download)
+ {
+ cerr << _("Press return to continue.\n");
+ int c = getchar();
+
+ while(c != '\n' && c != EOF)
+ c = getchar();
+ }
+#endif
+
+ break;
+
+ case pkgPackageManager::Incomplete:
+ rval = do_again;
+ break;
+ }
+
+ post_install_hook(pmres);
+
+#if 0
+ // libapt-pkg likes to stomp on SIGINT and SIGQUIT. Restore them
+ // here in the simplest possible way.
+ vscreen_install_sighandlers();
+
+ if(!text_download)
+ vscreen_resume();
+#endif
+
+ fetcher->Shutdown();
+
+ // Get source lists.
+ pkgSourceList src_list;
+ if(!src_list.ReadMainList())
+ {
+ _error->Error(_("Couldn't read source list"));
+
+ return failure;
+ }
+
+ if(!pm->GetArchives(fetcher, &src_list, apt_package_records))
+ return failure;
+
+ if(!apt_cache_file->GainLock())
+ // This really shouldn't happen.
+ {
+ _error->Error(_("Could not regain the system lock! (Perhaps another apt or dpkg is running?)"));
+ return failure;
+ }
+
+ return rval;
+}
+
+download_manager::result download_install_manager::finish(pkgAcquire::RunResult res,
+ OpProgress &progress)
+{
+ result run_res = execute_install_run(res, progress);
+
+ 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))
+ {
+ (*apt_cache_file)->forget_new(NULL);
+ post_forget_new_hook();
+ }
+ }
+
+ return run_res;
+}
Added: branches/aptitude-0.3/aptitude/src/generic/apt/download_install_manager.h
==============================================================================
--- (empty file)
+++ branches/aptitude-0.3/aptitude/src/generic/apt/download_install_manager.h Thu Sep 29 20:36:33 2005
@@ -0,0 +1,109 @@
+// download_install_manager.h -*-c++-*-
+//
+// Copyright (C) 2005 Daniel Burrows
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of
+// the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; see the file COPYING. If not, write to
+// the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+
+#ifndef DOWNLOAD_INSTALL_MANAGER_H
+#define DOWNLOAD_INSTALL_MANAGER_H
+
+#include "download_manager.h"
+
+#include "apt.h"
+
+#include <apt-pkg/packagemanager.h> // For OrderResult
+#include <apt-pkg/pkgcache.h> // For logging
+
+#include <sigc++/signal.h>
+
+#include <utility>
+#include <vector>
+
+class download_signal_log;
+
+/** Manages downloading and installing packages. */
+class download_install_manager : public download_manager
+{
+ /** A signal log upon which Complete() should be called. */
+ download_signal_log *log;
+
+ /** If \b true, don't actually invoke the package manager. */
+ bool download_only;
+
+ /** The package manager object used when installing packages */
+ pkgPackageManager *pm;
+
+ // Stuff for logging; should split out of this class and file:
+ struct log_sorter;
+ friend struct log_sorter;
+ typedef std::pair<pkgCache::PkgIterator, pkg_action_state> logitem;
+ typedef std::vector<logitem> loglist;
+
+ /** Perform the actual logging. */
+ static bool do_log(const std::string &log,
+ const loglist &changed_packages);
+
+ /** Write out any changes to the log file. */
+ static void log_changes();
+
+ /** Actually perform the installation/removal of packages and tell
+ * the caller what happened.
+ */
+ result execute_install_run(pkgAcquire::RunResult res,
+ OpProgress &load_progress);
+public:
+ download_install_manager();
+ ~download_install_manager();
+
+ /** Set up an install run. Does not take ownership of any of the
+ * arguments to the method.
+ *
+ * \param progress the progress object to use when
+ * saving the current cache state.
+ *
+ * \param _download_only if \b true, don't actually install packages.
+ *
+ * \param acqlog the status object to receive direct messages as
+ * the download proceeds.
+ *
+ * \param signallog an object upon which Complete() should be
+ * called once the entire install process is finished.
+ *
+ * \return \b true iff the preparation was successful.
+ */
+ bool prepare(OpProgress &progress,
+ bool _download_only,
+ pkgAcquireStatus *acqlog,
+ download_signal_log *signallog);
+
+ /** If download_only is false, call the package manager to install
+ * or remove packages. */
+ result finish(pkgAcquire::RunResult result,
+ OpProgress &progress);
+
+ /** Invoked prior to actually performing the install run. */
+ sigc::signal0<void> pre_install_hook;
+
+ /** Invoked right after performing the install run. Takes the
+ * result of the run as an argument.
+ */
+ sigc::signal1<void, pkgPackageManager::OrderResult> post_install_hook;
+
+ /** Invoked after an automatic 'forget new' operation. */
+ sigc::signal0<void> post_forget_new_hook;
+};
+
+#endif
Added: branches/aptitude-0.3/aptitude/src/generic/apt/download_manager.cc
==============================================================================
--- (empty file)
+++ branches/aptitude-0.3/aptitude/src/generic/apt/download_manager.cc Thu Sep 29 20:36:33 2005
@@ -0,0 +1,40 @@
+// download_manager.cc
+//
+// Copyright (C) 2005 Daniel Burrows
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of
+// the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; see the file COPYING. If not, write to
+// the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+
+#include "download_manager.h"
+
+download_manager::download_manager()
+ : fetcher(NULL)
+{
+}
+
+download_manager::~download_manager()
+{
+ delete fetcher;
+}
+
+pkgAcquire::RunResult download_manager::do_download()
+{
+ return fetcher->Run();
+}
+
+pkgAcquire::RunResult download_manager::do_download(int PulseInterval)
+{
+ return fetcher->Run(PulseInterval);
+}
Added: branches/aptitude-0.3/aptitude/src/generic/apt/download_manager.h
==============================================================================
--- (empty file)
+++ branches/aptitude-0.3/aptitude/src/generic/apt/download_manager.h Thu Sep 29 20:36:33 2005
@@ -0,0 +1,79 @@
+// download_manager.h -*-c++-*-
+//
+// Copyright (C) 2005 Daniel Burrows
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of
+// the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; see the file COPYING. If not, write to
+// the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+//
+// An abstract interface for download processes, and two
+// implementations.
+
+#ifndef DOWNLOAD_MANAGER_H
+#define DOWNLOAD_MANAGER_H
+
+// For RunResult
+#include <apt-pkg/acquire.h>
+
+class OpProgress;
+
+/** The generic interface for a task involving a download and possibly
+ * some post-download operations. (for instance, downloading and
+ * installing packages)
+ */
+class download_manager
+{
+public:
+ /** Used to determine what the client should do after a download
+ * completes.
+ */
+ enum result {success, failure, do_again};
+
+protected:
+ /** The object doing the actual download. Initialized to \b NULL
+ * and deleted in the destructor; it is expected that subclasses
+ * will provide a prepare() routine that sets this to an actual
+ * value.
+ */
+ pkgAcquire *fetcher;
+
+public:
+ download_manager();
+ virtual ~download_manager();
+
+ /** Perform the actual download. This may execute in a background
+ * thread.
+ */
+ virtual pkgAcquire::RunResult do_download();
+
+ /** Similar, but with a particular pulse interval. */
+ virtual pkgAcquire::RunResult do_download(int PulseInterval);
+
+ /** Perform any post-download tasks that need to be handled. This
+ * should be called from the main thread.
+ *
+ * \param result the result of do_download().
+ *
+ * \param progress a progress bar that may be used by the
+ * finishing process.
+ *
+ * \return the result of the post-download operations; if this is
+ * do_again, then the frontend code is expected to repeat the
+ * download and post-download tasks (as many times as needed).
+ */
+ virtual result finish(pkgAcquire::RunResult result,
+ OpProgress &progress) = 0;
+};
+
+#endif
Added: branches/aptitude-0.3/aptitude/src/generic/apt/download_update_manager.cc
==============================================================================
--- (empty file)
+++ branches/aptitude-0.3/aptitude/src/generic/apt/download_update_manager.cc Thu Sep 29 20:36:33 2005
@@ -0,0 +1,157 @@
+// download_update_manager.cc
+//
+// Copyright (C) 2005 Daniel Burrows
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of
+// the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; see the file COPYING. If not, write to
+// the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+
+#include "download_update_manager.h"
+
+#include "apt.h"
+#include "config_signal.h"
+#include "download_signal_log.h"
+
+#include <apt-pkg/clean.h>
+#include <apt-pkg/error.h>
+#include <apt-pkg/sourcelist.h>
+
+class my_cleaner:public pkgArchiveCleaner
+{
+protected:
+ virtual void Erase(const char *file,
+ string pkg,
+ string ver,
+ struct stat &stat)
+ {
+ unlink(file);
+ }
+};
+
+download_update_manager::download_update_manager()
+ : log(NULL)
+{
+}
+
+download_update_manager::~download_update_manager()
+{
+}
+
+bool download_update_manager::prepare(OpProgress &progress,
+ pkgAcquireStatus &acqlog,
+ download_signal_log *signallog)
+{
+ pkgSourceList src_list;
+
+ if(apt_cache_file != NULL &&
+ !(*apt_cache_file)->save_selection_list(progress))
+ return false;
+
+ // FIXME: should save_selection_list do this?
+ progress.Done();
+
+ if(src_list.ReadMainList() == false)
+ {
+ _error->Error(_("Couldn't read list of package sources"));
+ return false;
+ }
+
+ // Lock the list directory
+ FileFd lock;
+ if(aptcfg->FindB("Debug::NoLocking", false) == false)
+ {
+ lock.Fd(GetLock(aptcfg->FindDir("Dir::State::Lists")+"lock"));
+ if(_error->PendingError() == true)
+ {
+ _error->Error(_("Couldn't lock list directory..are you root?"));
+ return false;
+ }
+ }
+
+ fetcher = new pkgAcquire(log);
+
+ if(!src_list.GetIndexes(fetcher))
+ {
+ delete fetcher;
+ fetcher = NULL;
+ return false;
+ }
+ else
+ return true;
+}
+
+download_manager::result
+download_update_manager::finish(pkgAcquire::RunResult res,
+ OpProgress &progress)
+{
+ if(log != NULL)
+ log->Complete();
+
+ if(res != pkgAcquire::Continue)
+ {
+ apt_reload_cache(&progress, true);
+ return failure;
+ }
+
+ // 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"));
+ return failure;
+ }
+
+ apt_reload_cache(&progress, true);
+
+ if(apt_cache_file != NULL &&
+ aptcfg->FindB(PACKAGE "::Forget-New-On-Update", false))
+ {
+ (*apt_cache_file)->forget_new(NULL);
+ post_forget_new_hook();
+ }
+
+ if(apt_cache_file != NULL &&
+ aptcfg->FindB(PACKAGE "::AutoClean-After-Update", false))
+ {
+ pre_autoclean_hook();
+
+#if 0
+ // TODO: move this code to the appropriate frontends
+ vs_widget_ref msg = NULL;
+ if(!text_download)
+ {
+ msg=vs_center::create(vs_frame::create(vs_label::create(_("Deleting obsolete downloaded files"))));
+ popup_widget(msg);
+ vscreen_tryupdate();
+ }
+ else
+ printf(_("Deleting obsolete downloaded files\n"));
+#endif
+
+ my_cleaner cleaner;
+ cleaner.Go(aptcfg->FindDir("Dir::Cache::archives"), *apt_cache_file);
+ cleaner.Go(aptcfg->FindDir("Dir::Cache::archives")+"partial/",
+ *apt_cache_file);
+
+ post_autoclean_hook();
+
+#if 0
+ if(msg.valid())
+ msg->destroy();
+#endif
+ }
+
+ return success;
+}
+
Added: branches/aptitude-0.3/aptitude/src/generic/apt/download_update_manager.h
==============================================================================
--- (empty file)
+++ branches/aptitude-0.3/aptitude/src/generic/apt/download_update_manager.h Thu Sep 29 20:36:33 2005
@@ -0,0 +1,86 @@
+// download_update_manager.h -*-c++-*-
+//
+// Copyright (C) 2005 Daniel Burrows
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of
+// the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; see the file COPYING. If not, write to
+// the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+
+#ifndef DOWNLOAD_UPDATE_MANAGER_H
+#define DOWNLOAD_UPDATE_MANAGER_H
+
+#include "download_manager.h"
+
+#include <sigc++/signal.h>
+
+class download_signal_log;
+
+/** A class that handles updating the package lists. */
+class download_update_manager : public download_manager
+{
+ /** A signal log object upon which Complete() should be called. */
+ download_signal_log *log;
+
+public:
+ /** Create a new manager. Note that acqlog and signallog may or may
+ * not be the same object (for instance, acqlog may be a log object
+ * that runs in a background thread and forwards messages to
+ * signallog in the foreground thread).
+ *
+ * \param _cache_progress the progress bar which should monitor the
+ * cache save/reload. This is /not/ owned by the manager object;
+ * it will not be deleted in the destructor.
+ *
+ */
+ download_update_manager();
+ ~download_update_manager();
+
+ /** Set up the update run. The class does not take ownership of any
+ * of the pointers passed to this method.
+ *
+ * \param progress a progress bar used to display the progress in
+ * saving the cache
+ *
+ * \param acqlog a pkgAcqStatus that should be directly invoked by
+ * the download process.
+ *
+ * \param signallog a signal log object upon which Complete()
+ * should be called.
+ *
+ * \return \b true iff the preparation succeeded.
+ */
+ bool prepare(OpProgress &progress,
+ pkgAcquireStatus &acqlog,
+ download_signal_log *signallog);
+
+ result finish(pkgAcquire::RunResult result,
+ OpProgress &progress);
+
+ /** A signal that is invoked after an automatic 'forget new'
+ * operation.
+ */
+ sigc::signal0<void> post_forget_new_hook;
+
+ /** A signal that is invoked prior to performing an autoclean.
+ */
+ sigc::signal0<void> pre_autoclean_hook;
+
+ /** A signal that is invoked after performing an autoclean (it is
+ * always invoked once per invocation of pre_autoclean_signal).
+ */
+ sigc::signal0<void> post_autoclean_hook;
+};
+
+
+#endif
More information about the Aptitude-svn-commit
mailing list