summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2004-10-31 10:26:18 +0000
committerMarc Espie <espie@cvs.openbsd.org>2004-10-31 10:26:18 +0000
commit4091318827d0d2d680379d74947bf5ae73c24821 (patch)
tree99b7b7fc5d838f68ec4eb8b495349686fa5fead5
parenta6df7707be5ac1b1cd89b8324fe24e25dcbb2216 (diff)
Move most of the code of pkg_delete into a separate module so that it will
be usable by pkg_add -r.
-rw-r--r--usr.sbin/pkg_add/Makefile6
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Delete.pm423
-rw-r--r--usr.sbin/pkg_add/pkg_delete416
3 files changed, 432 insertions, 413 deletions
diff --git a/usr.sbin/pkg_add/Makefile b/usr.sbin/pkg_add/Makefile
index 9ac7490613e..195612ada59 100644
--- a/usr.sbin/pkg_add/Makefile
+++ b/usr.sbin/pkg_add/Makefile
@@ -1,8 +1,9 @@
-# $OpenBSD: Makefile,v 1.13 2004/10/26 17:23:15 espie Exp $
+# $OpenBSD: Makefile,v 1.14 2004/10/31 10:26:17 espie Exp $
MAN=pkg_add.1 pkg_info.1 pkg_create.1 pkg_delete.1 pkg.1
PACKAGES= \
+ OpenBSD/Delete.pm \
OpenBSD/Error.pm \
OpenBSD/Getopt.pm \
OpenBSD/IdCache.pm \
@@ -22,8 +23,9 @@ PACKAGES= \
OpenBSD/Temp.pm \
OpenBSD/Update.pm \
OpenBSD/Ustar.pm \
+ OpenBSD/Vstat.pm \
OpenBSD/md5.pm \
- OpenBSD/Vstat.pm
+
SCRIPTS= \
pkg_add \
diff --git a/usr.sbin/pkg_add/OpenBSD/Delete.pm b/usr.sbin/pkg_add/OpenBSD/Delete.pm
new file mode 100644
index 00000000000..31a76267a7a
--- /dev/null
+++ b/usr.sbin/pkg_add/OpenBSD/Delete.pm
@@ -0,0 +1,423 @@
+# ex:ts=8 sw=4:
+# $OpenBSD: Delete.pm,v 1.1 2004/10/31 10:26:17 espie Exp $
+#
+# Copyright (c) 2003-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::Delete;
+use OpenBSD::Error;
+use OpenBSD::Vstat;
+use OpenBSD::PackageInfo;
+
+sub ensure_ldconfig
+{
+ my $state = shift;
+ return if $state->{not};
+ return unless defined $OpenBSD::PackingElement::Lib::todo;
+ VSystem($state->{very_verbose},
+ @OpenBSD::PackingElement::Lib::ldconfig, "-R");
+ undef $OpenBSD::PackingElement::Lib::todo;
+}
+
+sub manpages_unindex
+{
+ my ($state) = @_;
+ return unless defined $state->{mandirs};
+ my $destdir = $state->{destdir};
+ require OpenBSD::Makewhatis;
+
+ while (my ($k, $v) = each %{$state->{mandirs}}) {
+ my @l = map { $destdir.$_ } @$v;
+ eval { OpenBSD::Makewhatis::remove($destdir.$k, \@l); };
+ if ($@) {
+ print STDERR "Error in makewhatis: $@\n";
+ }
+ }
+ undef $state->{mandirs};
+}
+
+sub validate_plist($$)
+{
+ my ($plist, $destdir) = @_;
+
+ my $problems = 0;
+ my $totsize = 0;
+ for my $item (@{$plist->{items}}) {
+ next unless $item->IsFile();
+ my $fname = $destdir.$item->fullname();
+ $totsize += $item->{size} if defined $item->{size};
+ my $s = OpenBSD::Vstat::remove($fname, $item->{size});
+ next unless defined $s;
+ if ($s->{ro}) {
+ Warn "Error: ", $s->{mnt}, " is read-only ($fname)\n";
+ $problems++;
+ }
+ }
+ Fatal "fatal issues" if $problems;
+ return $totsize;
+}
+
+sub remove_packing_info
+{
+ my $dir = shift;
+
+ for my $fname (info_names()) {
+ unlink($dir.$fname);
+ }
+ rmdir($dir) or Fatal "Can't finish removing directory $dir: $!";
+}
+
+sub delete_package
+{
+ my ($pkgname, $state) = @_;
+ $state->{pkgname} = $pkgname;
+ my $dir = installed_info($pkgname);
+ $state->{dir} = $dir;
+ my $plist = OpenBSD::PackingList->fromfile($dir.CONTENTS) or
+ Fatal "Bad package";
+ if (!defined $plist->pkgname()) {
+ Fatal "Package $pkgname has no name";
+ }
+ if ($plist->pkgname() ne $pkgname) {
+ Fatal "Package $pkgname real name does not match";
+ }
+
+ my $totsize = validate_plist($plist, $state->{destdir});
+
+ $ENV{'PKG_PREFIX'} = $plist->pkgbase();
+ if ($plist->has(REQUIRE)) {
+ $plist->get(REQUIRE)->delete($state);
+ }
+ if ($plist->has(DEINSTALL)) {
+ $plist->get(DEINSTALL)->delete($state);
+ }
+ $plist->visit('register_manpage', $state);
+ manpages_unindex($state);
+ my $donesize = 0;
+ for my $item (@{$plist->{groups}}, @{$plist->{users}}, @{$plist->{items}}) {
+ $item->delete($state);
+ if (defined $item->{size}) {
+ $donesize += $item->{size};
+ OpenBSD::ProgressMeter::show($donesize, $totsize);
+ }
+ }
+
+ OpenBSD::ProgressMeter::next();
+ if ($plist->has(UNDISPLAY)) {
+ $plist->get(UNDISPLAY)->prepare($state);
+ }
+
+ # guard against duplicate pkgdep
+ my $removed = {};
+ for my $item (@{$plist->{pkgdep}}) {
+ my $name = $item->{name};
+ next if defined $removed->{$name};
+ print "remove dependency in $name\n"
+ if $state->{very_verbose} or $state->{not};
+ local $@;
+ eval { OpenBSD::RequiredBy->new($name)->delete($pkgname) unless $state->{not}; };
+ if ($@) {
+ print STDERR "$@\n";
+ }
+ $removed->{$name} = 1;
+ }
+ remove_packing_info($dir) unless $state->{not};
+}
+
+package OpenBSD::PackingElement;
+sub delete
+{
+}
+
+sub log_pkgname
+{
+ my ($self, $state) = @_;
+ if (defined $state->{pkgname_tolog}) {
+ OpenBSD::Logger::log
+ "# package ", $state->{pkgname_tolog}, "\n";
+ $state->{pkgname_tolog} = undef;
+ }
+}
+
+package OpenBSD::PackingElement::NewUser;
+sub delete
+{
+ my ($self, $state) = @_;
+
+ my $name = $self->{name};
+
+ if ($state->{beverbose}) {
+ print "rmuser: $name\n";
+ }
+
+ $state->{users_to_rm} = {} unless defined $state->{users_to_rm};
+
+ my $h = $state->{users_to_rm};
+ $h->{$name} = $state->{pkgname};
+}
+
+package OpenBSD::PackingElement::NewGroup;
+sub delete
+{
+ my ($self, $state) = @_;
+
+ my $name = $self->{name};
+
+ if ($state->{beverbose}) {
+ print "rmgroup: $name\n";
+ }
+
+ $state->{groups_to_rm} = {} unless defined $state->{groups_to_rm};
+
+ my $h = $state->{groups_to_rm};
+ $h->{$name} = 1;
+}
+
+package OpenBSD::PackingElement::DirBase;
+sub delete
+{
+ my ($self, $state) = @_;
+
+ my $name = $self->fullname();
+
+ if ($state->{beverbose}) {
+ print "dirrm: $name\n";
+ }
+
+ $state->{dirs_to_rm} = {} unless defined $state->{dirs_to_rm};
+
+ my $h = $state->{dirs_to_rm};
+ $h->{$name} = [] unless defined $h->{$name};
+ $self->{pkgname} = $state->{pkgname};
+ push(@{$h->{$name}}, $self);
+}
+
+package OpenBSD::PackingElement::DirRm;
+sub delete
+{
+ &OpenBSD::PackingElement::DirBase::delete;
+}
+
+package OpenBSD::PackingElement::Unexec;
+sub delete
+{
+ my ($self, $state) = @_;
+ $self->run($state);
+}
+
+package OpenBSD::PackingElement::FileBase;
+use OpenBSD::md5;
+sub delete
+{
+ my ($self, $state) = @_;
+ my $name = $self->fullname();
+ my $realname = $state->{destdir}.$name;
+ if (-l $realname) {
+ if ($state->{beverbose}) {
+ print "deleting symlink: $realname\n";
+ }
+ } else {
+ if (! -f $realname) {
+ print "File $realname does not exist\n";
+ return;
+ }
+ unless (defined($self->{link}) or $self->{nochecksum} or $state->{quick}) {
+ if (!defined $self->{md5}) {
+ print "Problem: $name does not have an md5 checksum\n";
+ print "NOT deleting: $realname\n";
+ $self->log_pkgname($state);
+ OpenBSD::Logger::log "rm $state->{destdirname}$name\n";
+ return;
+ }
+ my $md5 = OpenBSD::md5::fromfile($realname);
+ if ($md5 ne $self->{md5}) {
+ print "Problem: md5 doesn't match for $name\n";
+ print "NOT deleting: $realname\n";
+ $self->log_pkgname($state);
+ OpenBSD::Logger::log "rm $state->{destdirname}$name #MD5\n";
+ return;
+ }
+ }
+ if ($state->{beverbose}) {
+ print "deleting: $realname\n";
+ }
+ }
+ return if $state->{not};
+ if (!unlink $realname) {
+ print "Problem deleting $realname\n";
+ $self->log_pkgname($state);
+ OpenBSD::Logger::log "rm $state->{destdirname}$name\n";
+ }
+}
+
+package OpenBSD::PackingElement::Sample;
+use OpenBSD::md5;
+use OpenBSD::Error;
+sub delete
+{
+ my ($self, $state) = @_;
+ my $name = $self->fullname();
+ my $realname = $state->{destdir}.$name;
+
+ my $orig = $self->{copyfrom};
+ if (!defined $orig) {
+ Fatal "\@sample element does not reference a valid file\n";
+ }
+ my $origname = $state->{destdir}.$orig->fullname();
+ if (! -e $realname) {
+ print "File $realname does not exist\n";
+ return;
+ }
+ if (! -f $realname) {
+ print "File $realname is not a file\n";
+ return;
+ }
+ if (!defined $orig->{md5}) {
+ print "Problem: file $name does not have an md5 checksum\n";
+ print "NOT deleting: $realname\n";
+ $self->log_pkgname($state);
+ OpenBSD::Logger::log "rm $state->{destdirname}$name\n";
+ return;
+ }
+
+ if ($state->{quick}) {
+ unless ($state->{extra}) {
+ print "NOT deleting file $realname\n";
+ return;
+ }
+ } else {
+ my $md5 = OpenBSD::md5::fromfile($realname);
+ if ($md5 eq $orig->{md5}) {
+ print "File $realname identical to sample\n" if $state->{not} or $state->{verbose};
+ } else {
+ print "File $realname NOT identical to sample\n";
+ unless ($state->{extra}) {
+ print "NOT deleting $realname\n";
+ return;
+ }
+ }
+ }
+ return if $state->{not};
+ print "deleting $realname\n" if $state->{verbose};
+ if (!unlink $realname) {
+ print "Problem deleting $realname\n";
+ $self->log_pkgname($state);
+ OpenBSD::Logger::log "rm $state->{destdirname}$name\n";
+ }
+}
+
+
+package OpenBSD::PackingElement::InfoFile;
+use File::Basename;
+use OpenBSD::Error;
+sub delete
+{
+ my ($self, $state) = @_;
+ unless ($state->{not}) {
+ my $fullname = $state->{destdir}.$self->fullname();
+ VSystem($state->{very_verbose},
+ "install-info", "--delete", "--info-dir=".dirname($fullname), $fullname);
+ }
+ $self->SUPER::delete($state);
+}
+
+package OpenBSD::PackingElement::Shell;
+sub delete
+{
+ my ($self, $state) = @_;
+ unless ($state->{not}) {
+ my $destdir = $state->{destdir};
+ my $fullname = $self->fullname();
+ my @l=();
+ if (open(my $shells, '<', $destdir.'/etc/shells')) {
+ local $_;
+ while(<$shells>) {
+ push(@l, $_);
+ s/^\#.*//;
+ if ($_ =~ m/^\Q$fullname\E\s*$/) {
+ pop(@l);
+ }
+ }
+ close($shells);
+ open(my $shells2, '>', $destdir.'/etc/shells');
+ print $shells2 @l;
+ close $shells2;
+ print "Shell $fullname removed from $destdir/etc/shells\n";
+ }
+ }
+ $self->SUPER::delete($state);
+}
+
+package OpenBSD::PackingElement::Extra;
+sub delete
+{
+ my ($self, $state) = @_;
+ return unless $state->{extra};
+ my $name = $self->fullname();
+ my $realname = $state->{destdir}.$name;
+ if ($state->{beverbose}) {
+ print "deleting extra file: $realname\n";
+ }
+ return if $state->{not};
+ return unless -e $realname;
+ unlink($realname) or
+ print "problem deleting extra file $realname\n";
+}
+
+package OpenBSD::PackingElement::Extradir;
+sub delete
+{
+ my ($self, $state) = @_;
+ return unless $state->{extra};
+ return unless -e $state->{destdir}.$self->fullname();
+ $self->SUPER::delete($state);
+}
+
+package OpenBSD::PackingElement::ExtraUnexec;
+
+sub delete
+{
+ my ($self, $state) = @_;
+ return unless $state->{extra};
+
+ $self->run($state);
+}
+
+package OpenBSD::PackingElement::Lib;
+sub delete
+{
+ my ($self, $state) = @_;
+ $self->SUPER::delete($state);
+ $self->mark_ldconfig_directory($state->{destdir});
+}
+
+package OpenBSD::PackingElement::FREQUIRE;
+sub delete
+{
+ my ($self, $state) = @_;
+
+ $self->run($state, "DEINSTALL");
+}
+
+package OpenBSD::PackingElement::FDEINSTALL;
+sub delete
+{
+ my ($self, $state) = @_;
+
+ $self->run($state, "DEINSTALL");
+}
+
+1;
diff --git a/usr.sbin/pkg_add/pkg_delete b/usr.sbin/pkg_add/pkg_delete
index 4cbb369c28a..1379c81cb43 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.65 2004/10/31 09:06:04 espie Exp $
+# $OpenBSD: pkg_delete,v 1.66 2004/10/31 10:26:17 espie Exp $
#
# Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org>
#
@@ -21,429 +21,23 @@ use warnings;
use OpenBSD::Getopt;
use OpenBSD::PackingList;
use OpenBSD::PackingOld;
-use OpenBSD::PackageInfo;
use OpenBSD::RequiredBy;
use OpenBSD::Logger;
-use OpenBSD::Vstat;
-use OpenBSD::PackageInfo;
use OpenBSD::Error;
use OpenBSD::ProgressMeter;
+use OpenBSD::Delete;
+use OpenBSD::PackageInfo;
our %forced = ();
-
sub ensure_ldconfig
{
- my $state = shift;
- return if $state->{not};
- return unless defined $OpenBSD::PackingElement::Lib::todo;
- VSystem($state->{very_verbose},
- @OpenBSD::PackingElement::Lib::ldconfig, "-R");
- undef $OpenBSD::PackingElement::Lib::todo;
-}
-
-package OpenBSD::PackingElement;
-sub delete
-{
-}
-
-sub log_pkgname
-{
- my ($self, $state) = @_;
- if (defined $state->{pkgname_tolog}) {
- OpenBSD::Logger::log
- "# package ", $state->{pkgname_tolog}, "\n";
- $state->{pkgname_tolog} = undef;
- }
-}
-
-package OpenBSD::PackingElement::NewUser;
-sub delete
-{
- my ($self, $state) = @_;
-
- my $name = $self->{name};
-
- if ($state->{beverbose}) {
- print "rmuser: $name\n";
- }
-
- $state->{users_to_rm} = {} unless defined $state->{users_to_rm};
-
- my $h = $state->{users_to_rm};
- $h->{$name} = $state->{pkgname};
-}
-
-package OpenBSD::PackingElement::NewGroup;
-sub delete
-{
- my ($self, $state) = @_;
-
- my $name = $self->{name};
-
- if ($state->{beverbose}) {
- print "rmgroup: $name\n";
- }
-
- $state->{groups_to_rm} = {} unless defined $state->{groups_to_rm};
-
- my $h = $state->{groups_to_rm};
- $h->{$name} = 1;
-}
-
-package OpenBSD::PackingElement::DirBase;
-sub delete
-{
- my ($self, $state) = @_;
-
- my $name = $self->fullname();
-
- if ($state->{beverbose}) {
- print "dirrm: $name\n";
- }
-
- $state->{dirs_to_rm} = {} unless defined $state->{dirs_to_rm};
-
- my $h = $state->{dirs_to_rm};
- $h->{$name} = [] unless defined $h->{$name};
- $self->{pkgname} = $state->{pkgname};
- push(@{$h->{$name}}, $self);
-}
-
-package OpenBSD::PackingElement::DirRm;
-sub delete
-{
- &OpenBSD::PackingElement::DirBase::delete;
-}
-
-package OpenBSD::PackingElement::Unexec;
-
-sub delete
-{
- my ($self, $state) = @_;
- $self->run($state);
-}
-
-package OpenBSD::PackingElement::FileBase;
-use OpenBSD::md5;
-sub delete
-{
- my ($self, $state) = @_;
- my $name = $self->fullname();
- my $realname = $state->{destdir}.$name;
- if (-l $realname) {
- if ($state->{beverbose}) {
- print "deleting symlink: $realname\n";
- }
- } else {
- if (! -f $realname) {
- print "File $realname does not exist\n";
- return;
- }
- unless (defined($self->{link}) or $self->{nochecksum} or $state->{quick}) {
- if (!defined $self->{md5}) {
- print "Problem: $name does not have an md5 checksum\n";
- print "NOT deleting: $realname\n";
- $self->log_pkgname($state);
- OpenBSD::Logger::log "rm $state->{destdirname}$name\n";
- return;
- }
- my $md5 = OpenBSD::md5::fromfile($realname);
- if ($md5 ne $self->{md5}) {
- print "Problem: md5 doesn't match for $name\n";
- print "NOT deleting: $realname\n";
- $self->log_pkgname($state);
- OpenBSD::Logger::log "rm $state->{destdirname}$name #MD5\n";
- return;
- }
- }
- if ($state->{beverbose}) {
- print "deleting: $realname\n";
- }
- }
- return if $state->{not};
- if (!unlink $realname) {
- print "Problem deleting $realname\n";
- $self->log_pkgname($state);
- OpenBSD::Logger::log "rm $state->{destdirname}$name\n";
- }
-}
-
-package OpenBSD::PackingElement::Sample;
-use OpenBSD::md5;
-use OpenBSD::Error;
-
-sub delete
-{
- my ($self, $state) = @_;
- my $name = $self->fullname();
- my $realname = $state->{destdir}.$name;
-
- my $orig = $self->{copyfrom};
- if (!defined $orig) {
- Fatal "\@sample element does not reference a valid file\n";
- }
- my $origname = $state->{destdir}.$orig->fullname();
- if (! -e $realname) {
- print "File $realname does not exist\n";
- return;
- }
- if (! -f $realname) {
- print "File $realname is not a file\n";
- return;
- }
- if (!defined $orig->{md5}) {
- print "Problem: file $name does not have an md5 checksum\n";
- print "NOT deleting: $realname\n";
- $self->log_pkgname($state);
- OpenBSD::Logger::log "rm $state->{destdirname}$name\n";
- return;
- }
-
- if ($state->{quick}) {
- unless ($state->{extra}) {
- print "NOT deleting file $realname\n";
- return;
- }
- } else {
- my $md5 = OpenBSD::md5::fromfile($realname);
- if ($md5 eq $orig->{md5}) {
- print "File $realname identical to sample\n" if $state->{not} or $state->{verbose};
- } else {
- print "File $realname NOT identical to sample\n";
- unless ($state->{extra}) {
- print "NOT deleting $realname\n";
- return;
- }
- }
- }
- return if $state->{not};
- print "deleting $realname\n" if $state->{verbose};
- if (!unlink $realname) {
- print "Problem deleting $realname\n";
- $self->log_pkgname($state);
- OpenBSD::Logger::log "rm $state->{destdirname}$name\n";
- }
-}
-
-
-package OpenBSD::PackingElement::InfoFile;
-use File::Basename;
-use OpenBSD::Error;
-
-sub delete
-{
- my ($self, $state) = @_;
- unless ($state->{not}) {
- my $fullname = $state->{destdir}.$self->fullname();
- VSystem($state->{very_verbose},
- "install-info", "--delete", "--info-dir=".dirname($fullname), $fullname);
- }
- $self->SUPER::delete($state);
-}
-
-package OpenBSD::PackingElement::Shell;
-sub delete
-{
- my ($self, $state) = @_;
- unless ($state->{not}) {
- my $destdir = $state->{destdir};
- my $fullname = $self->fullname();
- my @l=();
- if (open(my $shells, '<', $destdir.'/etc/shells')) {
- local $_;
- while(<$shells>) {
- push(@l, $_);
- s/^\#.*//;
- if ($_ =~ m/^\Q$fullname\E\s*$/) {
- pop(@l);
- }
- }
- close($shells);
- open(my $shells2, '>', $destdir.'/etc/shells');
- print $shells2 @l;
- close $shells2;
- print "Shell $fullname removed from $destdir/etc/shells\n";
- }
- }
- $self->SUPER::delete($state);
-}
-
-package OpenBSD::PackingElement::Extra;
-sub delete
-{
- my ($self, $state) = @_;
- return unless $state->{extra};
- my $name = $self->fullname();
- my $realname = $state->{destdir}.$name;
- if ($state->{beverbose}) {
- print "deleting extra file: $realname\n";
- }
- return if $state->{not};
- return unless -e $realname;
- unlink($realname) or
- print "problem deleting extra file $realname\n";
-}
-
-package OpenBSD::PackingElement::Extradir;
-sub delete
-{
- my ($self, $state) = @_;
- return unless $state->{extra};
- return unless -e $state->{destdir}.$self->fullname();
- $self->SUPER::delete($state);
-}
-
-package OpenBSD::PackingElement::ExtraUnexec;
-use OpenBSD::Error;
-
-sub delete
-{
- my ($self, $state) = @_;
- return unless $state->{extra};
-
- $self->run($state);
-}
-
-package OpenBSD::PackingElement::Lib;
-
-sub delete
-{
- my ($self, $state) = @_;
- $self->SUPER::delete($state);
- $self->mark_ldconfig_directory($state->{destdir});
-}
-
-package OpenBSD::PackingElement::FREQUIRE;
-use OpenBSD::PackageInfo;
-use OpenBSD::Error;
-
-sub delete
-{
- my ($self, $state) = @_;
-
- $self->run($state, "DEINSTALL");
+ &OpenBSD::Delete::ensure_ldconfig;
}
-package OpenBSD::PackingElement::FDEINSTALL;
-use OpenBSD::PackageInfo;
-use OpenBSD::Error;
-
-sub delete
-{
- my ($self, $state) = @_;
-
- $self->run($state, "DEINSTALL");
-}
-
-package main;
-
our ($opt_v, $opt_D, $opt_d, $opt_n, $opt_f, $opt_q, $opt_p, $opt_c, $opt_L, $opt_B, $opt_I, $opt_x);
$opt_v = 0;
-sub remove_packing_info
-{
- my $dir = shift;
-
- for my $fname (info_names()) {
- unlink($dir.$fname);
- }
- rmdir($dir) or Fatal "Can't finish removing directory $dir: $!";
-}
-
-sub manpages_unindex
-{
- my ($state) = @_;
- return unless defined $state->{mandirs};
- my $destdir = $state->{destdir};
- require OpenBSD::Makewhatis;
-
- while (my ($k, $v) = each %{$state->{mandirs}}) {
- my @l = map { $destdir.$_ } @$v;
- eval { OpenBSD::Makewhatis::remove($destdir.$k, \@l); };
- if ($@) {
- print STDERR "Error in makewhatis: $@\n";
- }
- }
- undef $state->{mandirs};
-}
-
-sub validate_plist($$)
-{
- my ($plist, $destdir) = @_;
-
- my $problems = 0;
- my $totsize = 0;
- for my $item (@{$plist->{items}}) {
- next unless $item->IsFile();
- my $fname = $destdir.$item->fullname();
- $totsize += $item->{size} if defined $item->{size};
- my $s = OpenBSD::Vstat::remove($fname, $item->{size});
- next unless defined $s;
- if ($s->{ro}) {
- Warn "Error: ", $s->{mnt}, " is read-only ($fname)\n";
- $problems++;
- }
- }
- Fatal "fatal issues" if $problems;
- return $totsize;
-}
-
-sub delete_package
-{
- my ($pkgname, $state) = @_;
- $state->{pkgname} = $pkgname;
- my $dir = installed_info($pkgname);
- $state->{dir} = $dir;
- my $plist = OpenBSD::PackingList->fromfile($dir.CONTENTS) or
- Fatal "Bad package";
- if (!defined $plist->pkgname()) {
- Fatal "Package $pkgname has no name";
- }
- if ($plist->pkgname() ne $pkgname) {
- Fatal "Package $pkgname real name does not match";
- }
-
- my $totsize = validate_plist($plist, $state->{destdir});
-
- $ENV{'PKG_PREFIX'} = $plist->pkgbase();
- if ($plist->has(REQUIRE)) {
- $plist->get(REQUIRE)->delete($state);
- }
- if ($plist->has(DEINSTALL)) {
- $plist->get(DEINSTALL)->delete($state);
- }
- $plist->visit('register_manpage', $state);
- manpages_unindex($state);
- my $donesize = 0;
- for my $item (@{$plist->{groups}}, @{$plist->{users}}, @{$plist->{items}}) {
- $item->delete($state);
- if (defined $item->{size}) {
- $donesize += $item->{size};
- OpenBSD::ProgressMeter::show($donesize, $totsize);
- }
- }
-
- OpenBSD::ProgressMeter::next();
- if ($plist->has(UNDISPLAY)) {
- $plist->get(UNDISPLAY)->prepare($state);
- }
-
- # guard against duplicate pkgdep
- my $removed = {};
- for my $item (@{$plist->{pkgdep}}) {
- my $name = $item->{name};
- next if defined $removed->{$name};
- print "remove dependency in $name\n" if $opt_v or $opt_n;
- local $@;
- eval { OpenBSD::RequiredBy->new($name)->delete($pkgname) unless $opt_n; };
- if ($@) {
- print STDERR "$@\n";
- }
- $removed->{$name} = 1;
- }
- remove_packing_info($dir) unless $opt_n;
-}
getopts('vcxDdnf:qpS:L:B:I',
{'v' => sub {++$opt_v;} });
@@ -587,7 +181,7 @@ eval {
}
$state->set_pkgname($pkgname);
$state->{pkgname_tolog} = $pkgname;
- delete_package($pkgname, $state);
+ OpenBSD::Delete::delete_package($pkgname, $state);
delete_installed($pkgname);
$done{$pkgname} = 1;
$removed++;