summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2004-10-26 17:23:16 +0000
committerMarc Espie <espie@cvs.openbsd.org>2004-10-26 17:23:16 +0000
commite1a97262226ada8cc458bcb6ef66443fe593135d (patch)
tree643cdb84b50d22b6ed3e8f0b54098e6b4d4b4dea /usr.sbin
parent1a7d1a7aeebe87f70475ea9d8ea060d89a8078bd (diff)
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.
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/pkg_add/Makefile4
-rw-r--r--usr.sbin/pkg_add/OpenBSD/SharedItems.pm176
-rw-r--r--usr.sbin/pkg_add/pkg_delete157
3 files changed, 187 insertions, 150 deletions
diff --git a/usr.sbin/pkg_add/Makefile b/usr.sbin/pkg_add/Makefile
index 93a2d794ea0..9ac7490613e 100644
--- a/usr.sbin/pkg_add/Makefile
+++ b/usr.sbin/pkg_add/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.12 2004/10/18 12:03:19 espie Exp $
+# $OpenBSD: Makefile,v 1.13 2004/10/26 17:23:15 espie Exp $
MAN=pkg_add.1 pkg_info.1 pkg_create.1 pkg_delete.1 pkg.1
@@ -18,7 +18,9 @@ PACKAGES= \
OpenBSD/PkgSpec.pm \
OpenBSD/ProgressMeter.pm \
OpenBSD/RequiredBy.pm \
+ OpenBSD/SharedItems.pm \
OpenBSD/Temp.pm \
+ OpenBSD/Update.pm \
OpenBSD/Ustar.pm \
OpenBSD/md5.pm \
OpenBSD/Vstat.pm
diff --git a/usr.sbin/pkg_add/OpenBSD/SharedItems.pm b/usr.sbin/pkg_add/OpenBSD/SharedItems.pm
new file mode 100644
index 00000000000..b33d5d469ed
--- /dev/null
+++ b/usr.sbin/pkg_add/OpenBSD/SharedItems.pm
@@ -0,0 +1,176 @@
+# ex:ts=8 sw=4:
+# $OpenBSD: SharedItems.pm,v 1.1 2004/10/26 17:23:15 espie Exp $
+#
+# Copyright (c) 2004 Marc Espie <espie@openbsd.org>
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+use strict;
+use warnings;
+package OpenBSD::SharedItems;
+
+use OpenBSD::ProgressMeter;
+use OpenBSD::Error;
+use OpenBSD::PackageInfo;
+use OpenBSD::PackingList;
+
+sub record_all
+{
+ 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;
+ $plist->visit('record_shared_item', $e, $db);
+ $done++;
+ }
+ return $db;
+}
+
+sub cleanup
+{
+ 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();
+
+ 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 record_shared_item
+{
+}
+
+sub cleanup
+{
+}
+
+sub reload
+{
+}
+
+package OpenBSD::PackingElement::NewUser;
+sub record_shared_item
+{
+ my ($self, $pkgname, $db) = @_;
+ my $k = $self->{name};
+ $db->{users}->{$k} = $pkgname;
+}
+
+package OpenBSD::PackingElement::NewGroup;
+sub record_shared_item
+{
+ my ($self, $pkgname, $db) = @_;
+ my $k = $self->{name};
+ $db->{groups}->{$k} = $pkgname;
+}
+
+package OpenBSD::PackingElement::DirBase;
+sub record_shared_item
+{
+ my ($self, $pkgname, $db) = @_;
+ my $k = $self->fullname();
+ $db->{dirs}->{$k} = 1;
+}
+
+package OpenBSD::PackingElement::DirRm;
+sub record_shared_item
+{
+ &OpenBSD::PackingElement::DirBase::record_shared_item;
+}
+
+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");
+}
+
+1;
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 <espie@openbsd.org>
#
@@ -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}) {