From e1a97262226ada8cc458bcb6ef66443fe593135d Mon Sep 17 00:00:00 2001 From: Marc Espie Date: Tue, 26 Oct 2004 17:23:16 +0000 Subject: move the code that handles shared items into a separate Module. - It will be used after deletion/adding during updates. - We might avoid loading it if a package contains no new directories. Actually a lot of packages don't use it. --- usr.sbin/pkg_add/pkg_delete | 157 +++----------------------------------------- 1 file changed, 8 insertions(+), 149 deletions(-) (limited to 'usr.sbin/pkg_add/pkg_delete') diff --git a/usr.sbin/pkg_add/pkg_delete b/usr.sbin/pkg_add/pkg_delete index bce4d0a827e..00fa30321ce 100644 --- a/usr.sbin/pkg_add/pkg_delete +++ b/usr.sbin/pkg_add/pkg_delete @@ -1,6 +1,6 @@ #!/usr/bin/perl # ex:ts=8 sw=4: -# $OpenBSD: pkg_delete,v 1.62 2004/10/23 09:27:48 espie Exp $ +# $OpenBSD: pkg_delete,v 1.63 2004/10/26 17:23:15 espie Exp $ # # Copyright (c) 2003-2004 Marc Espie # @@ -42,104 +42,11 @@ sub ensure_ldconfig undef $OpenBSD::PackingElement::Lib::todo; } -sub record_all_shared_items -{ - my $db = {dirs=>{}, users=>{}, groups=>{}}; - my @list = installed_packages(); - my $total = @list; - OpenBSD::ProgressMeter::set_header("Read shared items"); - my $done = 0; - for my $e (@list) { - OpenBSD::ProgressMeter::show($done, $total); - my $plist = OpenBSD::PackingList->fromfile(installed_info($e).CONTENTS, \&OpenBSD::PackingList::DirrmOnly) or next; - for my $item (@{$plist->{users}}, @{$plist->{groups}}, @{$plist->{items}}) { - $item->record_shared_item($e, $db); - } - $done++; - } - return $db; -} - -sub cleanup_shared_items -{ - my $state = shift; - - my $h = $state->{dirs_to_rm}; - my $u = $state->{users_to_rm}; - my $g = $state->{groups_to_rm}; - return unless defined $h or defined $u or defined $g; - my $remaining = record_all_shared_items(); - - OpenBSD::ProgressMeter::clear(); - OpenBSD::ProgressMeter::set_header("Clean shared items"); - my $total = 0; - $total += keys %$h if defined $h; - if ($state->{extra}) { - $total += keys %$u if defined $u; - $total += keys %$g if defined $g; - } - my $done = 0; - - if (defined $h) { - for my $d (sort {$b cmp $a} keys %$h) { - OpenBSD::ProgressMeter::show($done, $total); - my $realname = $state->{destdir}.$d; - if ($remaining->{dirs}->{$realname}) { - for my $i (@{$h->{$d}}) { - $state->set_pkgname($i->{pkgname}); - $i->reload($state); - } - } else { - for my $i (@{$h->{$d}}) { - $state->set_pkgname($i->{pkgname}); - $i->cleanup($state); - } - if (!rmdir $realname) { - $state->print("Error deleting directory $realname: $!\n"); - } - } - $done++; - } - } - if ($state->{extra}) { - if (defined $u) { - for my $user (keys %$u) { - OpenBSD::ProgressMeter::show($done, $total); - next if $remaining->{users}->{$user}; - System("/usr/sbin/userdel", $user); - $done++; - } - } - if (defined $g) { - for my $group (keys %$g) { - OpenBSD::ProgressMeter::show($done, $total); - next if $remaining->{groups}->{$group}; - System("/usr/sbin/groupdel", $group); - $done++; - } - } - } - OpenBSD::ProgressMeter::next(); -} - - package OpenBSD::PackingElement; sub delete { } -sub record_shared_item -{ -} - -sub cleanup -{ -} - -sub reload -{ -} - sub log_pkgname { my ($self, $state) = @_; @@ -151,13 +58,6 @@ sub log_pkgname } package OpenBSD::PackingElement::NewUser; -sub record_shared_item -{ - my ($self, $pkgname, $db) = @_; - my $k = $self->{name}; - $db->{users}->{$k} = $pkgname; -} - sub delete { my ($self, $state) = @_; @@ -175,13 +75,6 @@ sub delete } package OpenBSD::PackingElement::NewGroup; -sub record_shared_item -{ - my ($self, $pkgname, $db) = @_; - my $k = $self->{name}; - $db->{groups}->{$k} = $pkgname; -} - sub delete { my ($self, $state) = @_; @@ -199,13 +92,6 @@ sub delete } package OpenBSD::PackingElement::DirBase; -sub record_shared_item -{ - my ($self, $pkgname, $db) = @_; - my $k = $self->fullname(); - $db->{dirs}->{$k} = 1; -} - sub delete { my ($self, $state) = @_; @@ -225,11 +111,6 @@ sub delete } package OpenBSD::PackingElement::DirRm; -sub record_shared_item -{ - &OpenBSD::PackingElement::DirBase::record_shared_item; -} - sub delete { &OpenBSD::PackingElement::DirBase::delete; @@ -413,34 +294,6 @@ sub delete $self->SUPER::delete($state); } -package OpenBSD::PackingElement::Mandir; -sub cleanup -{ - my ($self, $state) = @_; - my $fullname = $state->{destdir}.$self->fullname(); - $state->print("You may wish to remove ", $fullname, " from man.conf\n"); - unlink("$fullname/whatis.db"); -} - -package OpenBSD::PackingElement::Fontdir; -sub cleanup -{ - my ($self, $state) = @_; - my $fullname = $state->{destdir}.$self->fullname(); - $state->print("You may wish to remove ", $fullname, " from your font path\n"); - unlink("$fullname/fonts.alias"); - unlink("$fullname/fonts.dir"); - unlink("$fullname/fonts.cache-1"); -} - -package OpenBSD::PackingElement::Infodir; -sub cleanup -{ - my ($self, $state) = @_; - my $fullname = $state->{destdir}.$self->fullname(); - unlink("$fullname/dir"); -} - package OpenBSD::PackingElement::ExtraUnexec; use OpenBSD::Error; @@ -761,7 +614,13 @@ my $dielater = $@; ensure_ldconfig($state); # delayed directory/user/group removal -cleanup_shared_items($state); +if (defined $state->{dirs_to_rm} or defined $state->{users_to_rm} or + defined $state->{groups_to_rm}) { + require OpenBSD::SharedItems; + + OpenBSD::SharedItems::cleanup($state); +} + OpenBSD::PackingElement::Fontdir::finish_fontdirs(); if (defined $state->{display}) { -- cgit v1.2.3