summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2004-07-14 10:44:04 +0000
committerMarc Espie <espie@cvs.openbsd.org>2004-07-14 10:44:04 +0000
commit4e1f856ff7193e68d6e8ce9bce3d382eeb9c467e (patch)
treebfecc120353c4df4f16fe4344378745a4cde14e6
parentd8cb00a3eea2e3efb7fcaca41b8f8259439dde8d (diff)
Rework @dirrm: keep them all, and remove them at the end of pkg_delete.
Add @dir, more powerful than @dirrm, so that we can get rid of those pesky @exec mkdir -p. okay naddy@
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackingElement.pm43
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackingList.pm4
-rw-r--r--usr.sbin/pkg_add/pkg_add48
-rw-r--r--usr.sbin/pkg_add/pkg_create.115
-rw-r--r--usr.sbin/pkg_add/pkg_delete93
5 files changed, 123 insertions, 80 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/PackingElement.pm b/usr.sbin/pkg_add/OpenBSD/PackingElement.pm
index 40792fec9ca..df427f770bf 100644
--- a/usr.sbin/pkg_add/OpenBSD/PackingElement.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PackingElement.pm
@@ -1,4 +1,4 @@
-# $OpenBSD: PackingElement.pm,v 1.10 2004/07/13 00:35:39 espie Exp $
+# $OpenBSD: PackingElement.pm,v 1.11 2004/07/14 10:44:03 espie Exp $
#
# Copyright (c) 2003 Marc Espie.
#
@@ -112,6 +112,20 @@ sub compute_fullname
return $fullname;
}
+sub compute_modes
+{
+ my ($self, $state) = @_;
+ if (defined $state->{mode}) {
+ $self->{mode} = $state->{mode};
+ }
+ if (defined $state->{owner}) {
+ $self->{owner} = $state->{owner};
+ }
+ if (defined $state->{group}) {
+ $self->{group} = $state->{group};
+ }
+}
+
sub expand
{
my $state = $_[2];
@@ -175,15 +189,7 @@ sub destate
{
my ($self, $state) = @_;
$self->compute_fullname($state);
- if (defined $state->{mode}) {
- $self->{mode} = $state->{mode};
- }
- if (defined $state->{owner}) {
- $self->{owner} = $state->{owner};
- }
- if (defined $state->{group}) {
- $self->{group} = $state->{group};
- }
+ $self->compute_modes($state);
if (defined $state->{nochecksum}) {
$self->{nochecksum} = 1;
undef $state->{nochecksum};
@@ -563,8 +569,10 @@ sub destate
$self->{expanded} = $self->expand($self->{name}, $state);
}
+package OpenBSD::PackingElement::Dirs;
+
package OpenBSD::PackingElement::DirRm;
-our @ISA=qw(OpenBSD::PackingElement);
+our @ISA=qw(OpenBSD::PackingElement::Dirs OpenBSD::PackingElement);
__PACKAGE__->setKeyword('dirrm');
sub keyword() { "dirrm" }
@@ -575,6 +583,19 @@ sub destate
$self->compute_fullname($state);
}
+package OpenBSD::PackingElement::Dir;
+our @ISA=qw(OpenBSD::PackingElement::Dirs OpenBSD::PackingElement);
+
+__PACKAGE__->setKeyword('dir');
+sub keyword() { "dir" }
+
+sub destate
+{
+ my ($self, $state) = @_;
+ $self->compute_fullname($state);
+ $self->compute_modes($state);
+}
+
package OpenBSD::PackingElement::Extra;
our @ISA=qw(OpenBSD::PackingElement);
diff --git a/usr.sbin/pkg_add/OpenBSD/PackingList.pm b/usr.sbin/pkg_add/OpenBSD/PackingList.pm
index 1e3420b75fc..d52b97dc449 100644
--- a/usr.sbin/pkg_add/OpenBSD/PackingList.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PackingList.pm
@@ -1,4 +1,4 @@
-# $OpenBSD: PackingList.pm,v 1.10 2004/07/13 00:35:39 espie Exp $
+# $OpenBSD: PackingList.pm,v 1.11 2004/07/14 10:44:03 espie Exp $
#
# Copyright (c) 2003 Marc Espie.
#
@@ -73,7 +73,7 @@ sub DirrmOnly
my ($fh, $cont) = @_;
local $_;
while (<$fh>) {
- next unless m/^\@cwd\b/ || m/^\@dirrm\b/ || m/^\@name\b/;
+ next unless m/^\@cwd\b/ || m/^\@dirrm\b/ || m/^\@dir\b/ || m/^\@name\b/;
&$cont($_);
}
}
diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add
index 62b577f853b..00b5ffa66b3 100644
--- a/usr.sbin/pkg_add/pkg_add
+++ b/usr.sbin/pkg_add/pkg_add
@@ -1,7 +1,7 @@
#! /usr/bin/perl
# ex:ts=8 sw=4:
-# $OpenBSD: pkg_add,v 1.33 2004/07/11 20:46:08 espie Exp $
+# $OpenBSD: pkg_add,v 1.34 2004/07/14 10:44:03 espie Exp $
#
# Copyright (c) 2003 Marc Espie.
#
@@ -56,6 +56,22 @@ sub install
{
}
+sub set_modes
+{
+ my ($self, $name) = @_;
+
+ if (defined $self->{owner} && defined $self->{group}) {
+ system('chown', $self->{owner}.':'.$self->{group}, $name);
+ } elsif (defined $self->{owner}) {
+ system('chown', $self->{owner}, $name);
+ } elsif (defined $self->{group}) {
+ system('chown', ':'.$self->{group}, $name);
+ }
+ if (defined $self->{mode}) {
+ system('chmod', $self->{mode}, $name);
+ }
+}
+
package OpenBSD::PackingElement::File;
use File::Basename;
use File::Path;
@@ -63,28 +79,32 @@ use File::Path;
sub install
{
my ($self, $archive, $destdir, $verbose, $not) = @_;
+ my $fullname = $self->fullname();
my $file=$archive->next();
if ($file->{name} ne $self->{name}) {
die "Error: archive does not match", $file->{name}, "!=",
$self->{name}, "\n";
}
- print "extracting ", $destdir, $self->fullname(), "\n" if $verbose;
- $file->{name} = $self->fullname();
+ print "extracting ", $destdir, $fullname, "\n" if $verbose;
+ return if $not;
+ $file->{name} = $fullname;
$file->{cwd} = $self->{cwd};
$file->{destdir} = $destdir;
- return if $not;
$file->create();
- if (defined $self->{owner} && defined $self->{group}) {
- system('chown', $self->{owner}.':'.$self->{group}, $destdir.$self->fullname());
- } elsif (defined $self->{owner}) {
- system('chown', $self->{owner}, $destdir.$self->fullname());
- } elsif (defined $self->{group}) {
- system('chown', ':'.$self->{group}, $destdir.$self->fullname());
- }
- if (defined $self->{mode}) {
- system('chmod', $self->{mode}, $destdir.$self->fullname());
- }
+ $self->set_modes($destdir.$fullname);
+}
+
+package OpenBSD::PackingElement::Dir;
+sub install
+{
+ my ($self, $archive, $destdir, $verbose, $not) = @_;
+ my $fullname = $self->fullname();
+
+ print "new directory ", $destdir, $fullname, "\n" if $verbose;
+ return if $not;
+ File::Path::mkpath($destdir.$fullname);
+ $self->set_modes($destdir.$fullname);
}
package OpenBSD::PackingElement::Exec;
diff --git a/usr.sbin/pkg_add/pkg_create.1 b/usr.sbin/pkg_add/pkg_create.1
index 534d70eb6ab..8d8c2fce130 100644
--- a/usr.sbin/pkg_add/pkg_create.1
+++ b/usr.sbin/pkg_add/pkg_create.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: pkg_create.1,v 1.6 2004/07/05 23:21:56 espie Exp $
+.\" $OpenBSD: pkg_create.1,v 1.7 2004/07/14 10:44:03 espie Exp $
.\"
.\" FreeBSD install - a package for the installation and maintenance
.\" of non-core utilities.
@@ -298,6 +298,11 @@ Note that
.Nm
will derive this field from the package name and add it automatically
if none is given.
+.It Cm @dir Ar name
+Create directory
+.Pa name
+at install time, taking @mode, @group, @owner into account,
+and remove it at deinstall time.
.It Cm @dirrm Ar name
Declare directory
.Pa name
@@ -305,13 +310,11 @@ to be deleted at deinstall time.
By default, directories created by a
package installation are not deleted when the package is deinstalled;
this provides an explicit directory cleanup method.
-This directive should appear at the end of the package list.
-If more than one
-.Cm @dirrm
-directive is used, the directories are removed in the order specified.
The
.Pa name
-directory will not be removed unless it is empty.
+directory will not be removed unless it is empty after the package is
+de-installed.
+Directories to remove can be shared between packages.
.It Cm @extra Ar file
Declare extra file
.Pa file
diff --git a/usr.sbin/pkg_add/pkg_delete b/usr.sbin/pkg_add/pkg_delete
index e89b4b6b3e1..4928fa4e693 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.24 2004/06/21 16:33:45 espie Exp $
+# $OpenBSD: pkg_delete,v 1.25 2004/07/14 10:44:03 espie Exp $
#
# Copyright (c) 2003 Marc Espie.
#
@@ -37,6 +37,40 @@ use OpenBSD::Vstat;
our %forced = ();
+use OpenBSD::PackageInfo;
+
+sub find_alldirrms
+{
+ my $db = {};
+ my @list = installed_packages();
+ for my $e (@list) {
+ my $plist = OpenBSD::PackingList->fromfile(installed_info($e).CONTENTS, \&OpenBSD::PackingList::DirrmOnly) or next;
+ for my $item (@{$plist->{items}}) {
+ $item->record_dirrm($e, $db);
+ }
+ }
+ return $db;
+}
+
+sub remove_dirs
+{
+ my $state = shift;
+
+ my $h = $state->{dirs_to_rm};
+ return unless defined $h;
+
+ my $remaining = find_alldirrms();
+
+ for my $d (sort {$b cmp $a} keys %$h) {
+ next if defined $remaining->{$d};
+ my $realname = $state->{destdir}.$d;
+ if (!rmdir $realname) {
+ print "Error deleting directory $realname\n";
+ }
+ }
+}
+
+
package OpenBSD::PackingElement;
sub delete
{
@@ -56,9 +90,8 @@ sub log_pkgname
}
}
-package OpenBSD::PackingElement::DirRm;
-use OpenBSD::PackageInfo;
+package OpenBSD::PackingElement::Dirs;
sub record_dirrm
{
my ($self, $pkgname, $db) = @_;
@@ -67,58 +100,21 @@ sub record_dirrm
push(@{$db->{$k}}, $pkgname);
}
-sub find_alldirrms
-{
- my $db = {};
- my @list = installed_packages();
- for my $e (@list) {
- my $plist = OpenBSD::PackingList->fromfile(installed_info($e).CONTENTS, \&OpenBSD::PackingList::DirrmOnly) or next;
- for my $item (@{$plist->{items}}) {
- $item->record_dirrm($e, $db);
- }
- }
- return $db;
-}
-
sub delete
{
my ($self, $state) = @_;
+
my $name = $self->fullname();
- my $realname = $state->{destdir}.$name;
if ($state->{verbose} or $state->{not}) {
print "dirrm: $name\n";
}
- unless (defined $state->{dirrms}) {
- $state->{dirrms} = find_alldirrms();
- }
- return if $state->{not};
- my $entry = $state->{dirrms}->{$name};
- unless (defined $entry) {
- print "Error: dirrm $name was not recorded\n";
- return;
- }
- if (@$entry == 0) {
- print "Error: no dirrm $name left\n";
- }
- elsif (@$entry == 1) {
- if ($entry->[0] eq $state->{pkgname}) {
- if (!rmdir $realname) {
- print "Error deleting directory $realname\n";
- $self->log_pkgname($state);
- OpenBSD::Logger::log "rmdir $state->{destdirname}$name\n";
- }
- $state->{dirrms}->{$name} = undef;
- } else {
- print "Error: dirrm $name recorded as ",
- $entry->[0], "\n";
- }
- }
- elsif (@$entry > 1) {
- print "Dirrm $name defined in multiple packages: ",
- join(",", @$entry), "\n" if $state->{verbose};
- @$entry = grep { $_ ne $state->{pkgname} } @$entry;
- }
+
+ $state->{dirs_to_rm} = {} unless defined $state->{dirs_to_rm};
+
+ my $h = $state->{dirs_to_rm};
+ $h->{$name} = [] unless defined $h->{$name};
+ push(@{$h->{$name}}, $state->{pkgname});
}
package OpenBSD::PackingElement::Unexec;
@@ -461,6 +457,9 @@ if ($opt_B eq '') {
last if $opt_n;
} while ($removed); }
+# delayed directory removal
+remove_dirs($state);
+
my $logname = OpenBSD::Logger::logname();
if (defined $logname) {
print "Problems logged as $logname\n";