diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2011-07-17 13:16:16 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2011-07-17 13:16:16 +0000 |
commit | d2b5eb189db4c0fe74b2fc71de9189f187e18919 (patch) | |
tree | fc6d95760623b972a022f6f39eeaeb30784c7149 /usr.sbin | |
parent | da552a4d406853717fa96a9fc756c8478734e3f8 (diff) |
unify the main loop some more: add and delete do more or less the
same processing.
start making process_set similar as well
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/AddDelete.pm | 22 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PkgAdd.pm | 40 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PkgDelete.pm | 36 |
3 files changed, 51 insertions, 47 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/AddDelete.pm b/usr.sbin/pkg_add/OpenBSD/AddDelete.pm index f8a58762ab5..3883ad6dd09 100644 --- a/usr.sbin/pkg_add/OpenBSD/AddDelete.pm +++ b/usr.sbin/pkg_add/OpenBSD/AddDelete.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: AddDelete.pm,v 1.50 2011/07/14 11:31:20 espie Exp $ +# $OpenBSD: AddDelete.pm,v 1.51 2011/07/17 13:16:15 espie Exp $ # # Copyright (c) 2007-2010 Marc Espie <espie@openbsd.org> # @@ -105,6 +105,26 @@ sub parse_and_run return $state->{bad} != 0; } +# nothing to do +sub tweak_list +{ +} + +sub process_setlist +{ + my ($self, $state) = @_; + $state->tracker->todo(@{$state->{setlist}}); + # this is the actual very small loop that processes all sets + while (my $set = shift @{$state->{setlist}}) { + $state->status->what->set($set); + $set = $set->real_set; + next if $set->{finished}; + $state->progress->set_header('Checking packages'); + unshift(@{$state->{setlist}}, $self->process_set($set, $state)); + $self->tweak_list($state); + } +} + package OpenBSD::SharedItemsRecorder; sub new { diff --git a/usr.sbin/pkg_add/OpenBSD/PkgAdd.pm b/usr.sbin/pkg_add/OpenBSD/PkgAdd.pm index 0f169bcf31d..5feb1eb57a0 100644 --- a/usr.sbin/pkg_add/OpenBSD/PkgAdd.pm +++ b/usr.sbin/pkg_add/OpenBSD/PkgAdd.pm @@ -1,7 +1,7 @@ #! /usr/bin/perl # ex:ts=8 sw=4: -# $OpenBSD: PkgAdd.pm,v 1.28 2011/07/14 11:31:20 espie Exp $ +# $OpenBSD: PkgAdd.pm,v 1.29 2011/07/17 13:16:15 espie Exp $ # # Copyright (c) 2003-2010 Marc Espie <espie@openbsd.org> # @@ -870,17 +870,9 @@ sub newer_has_errors return 0; } -sub install_set +sub process_set { - my ($set, $state) = @_; - - $set = $set->real_set; - - $state->progress->set_header('Checking packages'); - - if ($set->{finished}) { - return (); - } + my ($self, $set, $state) = @_; if (!$state->updater->process_set($set, $state)) { return (); @@ -1025,9 +1017,9 @@ sub quirk_set sub do_quirks { - my $state = shift; + my ($self, $state) = @_; - install_set(quirk_set($state), $state); + $self->process_set(quirk_set($state), $state); eval { require OpenBSD::Quirks; # interface version number. @@ -1114,25 +1106,25 @@ sub finish_display inform_user_of_problems($state); } +sub tweak_list +{ + my ($self, $state) = @_; + + eval { + $state->quirks->tweak_list($state->{setlist}, $state); + } +} + sub main { my ($self, $state) = @_; $state->progress->set_header(''); if ($state->{allow_replacing}) { - do_quirks($state); + $self->do_quirks($state); } - $state->tracker->todo(@{$state->{setlist}}); - # This is the actual very small loop that adds all packages - while (my $set = shift @{$state->{setlist}}) { - - $state->status->what->set($set); - unshift(@{$state->{setlist}}, install_set($set, $state)); - eval { - $state->quirks->tweak_list($state->{setlist}, $state); - }; - } + $self->process_setlist($state); } diff --git a/usr.sbin/pkg_add/OpenBSD/PkgDelete.pm b/usr.sbin/pkg_add/OpenBSD/PkgDelete.pm index 8bf4d6c99fc..111608e6f3b 100644 --- a/usr.sbin/pkg_add/OpenBSD/PkgDelete.pm +++ b/usr.sbin/pkg_add/OpenBSD/PkgDelete.pm @@ -1,6 +1,6 @@ #!/usr/bin/perl # ex:ts=8 sw=4: -# $OpenBSD: PkgDelete.pm,v 1.17 2011/07/14 11:31:20 espie Exp $ +# $OpenBSD: PkgDelete.pm,v 1.18 2011/07/17 13:16:15 espie Exp $ # # Copyright (c) 2003-2010 Marc Espie <espie@openbsd.org> # @@ -47,8 +47,8 @@ sub handle_set sub todo { - my ($self, $list) = @_; - for my $set (@$list) { + my ($self, @list) = @_; + for my $set (@list) { for my $pkgname ($set->older_names) { $self->{todo}{$pkgname} = $set; } @@ -67,6 +67,10 @@ sub done $self->handle_set($set); } +sub cant +{ + &done; +} sub find { my ($self, $pkgname) = @_; @@ -247,8 +251,6 @@ sub really_remove $state->log->set_context('-'.$pkgname); OpenBSD::Delete::delete_package($pkgname, $state); } - $set->cleanup; - $state->tracker->done($set); $state->progress->next($state->ntogo); } @@ -278,16 +280,12 @@ sub fix_bad_dependencies return 0; } -sub remove_set +sub process_set { - my ($set, $state) = @_; + my ($self, $set, $state) = @_; my $todo = {}; my $bad = {}; - $set = $set->real_set; - if ($set->{finished}) { - return (); - } for my $pkgname ($set->older_names) { unless (is_installed($pkgname)) { $state->errsay("#1 was not installed", $pkgname); @@ -338,7 +336,7 @@ sub remove_set $state->{bad}++; } $set->cleanup(OpenBSD::Handle::CANT_DELETE); - $state->tracker->done($set); + $state->tracker->cant($set); return (); } # XXX this si where we should detect loops @@ -364,12 +362,14 @@ sub remove_set $state->say("Won't delete manually installed #1", $set->print) if $state->verbose; $set->cleanup(OpenBSD::Handle::CANT_DELETE); - $state->tracker->done($set); + $state->tracker->cant($set); return (); } } } really_remove($set, $state); + $set->cleanup; + $state->tracker->done($set); return (); } @@ -377,15 +377,7 @@ sub main { my ($self, $state) = @_; - my %done; - my $removed; - - $state->tracker->todo($state->{setlist}); - # and finally, handle the removal - while (my $set = shift @{$state->{setlist}}) { - $state->status->what->set($set); - unshift(@{$state->{setlist}}, remove_set($set, $state)); - } + $self->process_setlist($state); } sub new_state |