diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2010-06-18 09:05:04 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2010-06-18 09:05:04 +0000 |
commit | 231697c6e9520d5c6a7470483f7147cd5568bfda (patch) | |
tree | dcfc23e55c62b304aa7b9ff7082303510d4f39c2 /usr.sbin/pkg_add | |
parent | a5e0688e8922001a21e5024bda77f7cd3cc03a83 (diff) |
reuse for_list
Diffstat (limited to 'usr.sbin/pkg_add')
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/SharedItems.pm | 98 |
1 files changed, 44 insertions, 54 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/SharedItems.pm b/usr.sbin/pkg_add/OpenBSD/SharedItems.pm index 36cee345ed7..278088b1154 100644 --- a/usr.sbin/pkg_add/OpenBSD/SharedItems.pm +++ b/usr.sbin/pkg_add/OpenBSD/SharedItems.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: SharedItems.pm,v 1.23 2010/06/09 07:26:01 espie Exp $ +# $OpenBSD: SharedItems.pm,v 1.24 2010/06/18 09:05:03 espie Exp $ # # Copyright (c) 2004-2006 Marc Espie <espie@openbsd.org> # @@ -29,19 +29,15 @@ sub find_items_in_installed_packages { my $state = shift; my $db = OpenBSD::SharedItemsRecorder->new; - my @list = installed_packages(); - my $total = @list; $state->status->what("Read")->object("shared items"); - $state->progress->set_header("Read shared items"); - my $done = 0; - for my $e (@list) { - $state->progress->show($done, $total); + $state->progress->for_list("Read shared items", [installed_packages()], + sub { + my $e = shift; my $plist = OpenBSD::PackingList->from_installation($e, \&OpenBSD::PackingList::SharedItemsOnly) or next; - next if !defined $plist; + return if !defined $plist; $plist->record_shared($db, $e); - $done++; - } + }); return $db; } @@ -63,56 +59,50 @@ sub cleanup $total += keys %$g if defined $g; my $done = 0; - if (defined $h) { - for my $d (sort {$b cmp $a} keys %$h) { - $state->progress->show($done, $total); - my $realname = $state->{destdir}.$d; - if ($remaining->{dirs}->{$realname}) { - for my $i (@{$h->{$d}}) { - $state->log->set_context($i->{pkgname}); - $i->reload($state); - } - } else { - for my $i (@{$h->{$d}}) { - $state->log->set_context($i->{pkgname}); - $i->cleanup($state); - } - if (!rmdir $realname) { - $state->log("Error deleting directory #1: #2", - $realname, $!) - unless $state->{dirs_okay}->{$d}; - } + for my $d (sort {$b cmp $a} keys %$h) { + $state->progress->show($done, $total); + my $realname = $state->{destdir}.$d; + if ($remaining->{dirs}->{$realname}) { + for my $i (@{$h->{$d}}) { + $state->log->set_context($i->{pkgname}); + $i->reload($state); + } + } else { + for my $i (@{$h->{$d}}) { + $state->log->set_context($i->{pkgname}); + $i->cleanup($state); + } + if (!rmdir $realname) { + $state->log("Error deleting directory #1: #2", + $realname, $!) + unless $state->{dirs_okay}->{$d}; } - $done++; } + $done++; } - if (defined $u) { - while (my ($user, $pkgname) = each %$u) { - $state->progress->show($done, $total); - next if $remaining->{users}->{$user}; - if ($state->{extra}) { - $state->system(OpenBSD::Paths->userdel, '--', - $user); - } else { - $state->log->set_context($pkgname); - $state->log("You should also run /usr/sbin/userdel #1", $user); - } - $done++; + while (my ($user, $pkgname) = each %$u) { + $state->progress->show($done, $total); + next if $remaining->{users}->{$user}; + if ($state->{extra}) { + $state->system(OpenBSD::Paths->userdel, '--', + $user); + } else { + $state->log->set_context($pkgname); + $state->log("You should also run /usr/sbin/userdel #1", $user); } + $done++; } - if (defined $g) { - while (my ($group, $pkgname) = each %$g) { - $state->progress->show($done, $total); - next if $remaining->{groups}->{$group}; - if ($state->{extra}) { - $state->system(OpenBSD::Paths->groupdel, '--', - $group); - } else { - $state->log->set_context($pkgname); - $state->log("You should also run /usr/sbin/groupdel #1", $group); - } - $done++; + while (my ($group, $pkgname) = each %$g) { + $state->progress->show($done, $total); + next if $remaining->{groups}->{$group}; + if ($state->{extra}) { + $state->system(OpenBSD::Paths->groupdel, '--', + $group); + } else { + $state->log->set_context($pkgname); + $state->log("You should also run /usr/sbin/groupdel #1", $group); } + $done++; } if ($state->verbose >= 2) { $state->progress->next; |