summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2004-08-05 23:36:41 +0000
committerMarc Espie <espie@cvs.openbsd.org>2004-08-05 23:36:41 +0000
commitb1a99bfe922d9636aedd85d5a14aa01ce59bf207 (patch)
tree8f84039a5285934713328aecc97069e97f21368f
parentcdf1b8ae47492fc96234d3786e7d3c125c35125b (diff)
refactor classes in PackingElement to share more code.
- all files go through FileBase, all directories go through DirBase. - dirclass() is used to switch classes based on final /, so that @sample, @extra, and @file all take directories as well. - set NoDuplicateNames() more thoroughly. - make sure all no-default-conflict objects are correct. compute_fullname() checks for absolute paths, allowed for @sample and @extra. lastfile only gets set for actual files. special names like INSTALL are only checked for normal files. add a CVSTag class for @comment $OpenBSD$, so that these get sorted first. Changes for make-plist rewrite: clone() method that can create copies of all hash objects, to specialize if needed. add_object() method so that add() is now new() followed by add_object() for most objects (useful for cloned objects). Check that plist has a name in pkg_create, allowing PackingList to write unnamed plists.
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackingElement.pm201
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackingList.pm25
-rw-r--r--usr.sbin/pkg_add/TODO4
-rw-r--r--usr.sbin/pkg_add/pkg_add11
-rw-r--r--usr.sbin/pkg_add/pkg_create10
-rw-r--r--usr.sbin/pkg_add/pkg_delete36
6 files changed, 181 insertions, 106 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/PackingElement.pm b/usr.sbin/pkg_add/OpenBSD/PackingElement.pm
index 83b11517eac..3ab67150e29 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.16 2004/08/03 12:29:45 espie Exp $
+# $OpenBSD: PackingElement.pm,v 1.17 2004/08/05 23:36:40 espie Exp $
#
# Copyright (c) 2003 Marc Espie.
#
@@ -52,15 +52,12 @@ sub Factory
exit(1);
}
} else {
- if ($_ =~ m|/$|) {
- OpenBSD::PackingElement::Dir->add(@_, $`);
- } else {
OpenBSD::PackingElement::File->add(@_, $_);
- }
}
}
-sub setKeyword {
+sub setKeyword
+{
my ($class, $k) = @_;
$keyword{$k} = $class;
}
@@ -75,26 +72,45 @@ sub category() { 'items' }
sub new
{
my ($class, $args) = @_;
- bless { name => $args }, $class;
+ if ($args =~ m|/$| and defined $class->dirclass()) {
+ bless { name => $` }, $class->dirclass();
+ } else {
+ bless { name => $args }, $class;
+ }
}
-sub destate
+sub clone
{
+ my $object = shift;
+ # shallow copy
+ my %h = %$object;
+ bless \%h, ref($object);
}
+
-sub add
+sub dirclass() { undef }
+
+sub destate
{
- my ($class, $plist, @args) = @_;
+}
- my $self = $class->new(@args);
+sub add_object
+{
+ my ($self, $plist) = @_;
$self->destate($plist->{state});
$plist->add2list($self);
return $self;
}
-sub keyword() { return; }
+sub add
+{
+ my ($class, $plist, @args) = @_;
+
+ my $self = $class->new(@args);
+ return $self->add_object($plist);
+}
-sub needs_keyword() { 1; }
+sub needs_keyword() { 1 }
sub write
{
@@ -111,9 +127,9 @@ sub fullstring
{
my ($self, $fh) = @_;
if ($self->needs_keyword()) {
- return "\@".$self->keyword()." ".$self->stringize()."\n";
+ return "\@".$self->keyword()." ".$self->stringize();
} else {
- return $self->stringize()."\n";
+ return $self->stringize();
}
}
@@ -124,12 +140,19 @@ sub stringize($)
sub compute_fullname
{
- my ($self, $state) = @_;
+ my ($self, $state, $absolute_okay) = @_;
$self->{cwd} = $state->{cwd};
- my $fullname = $self->{fullname} =
- File::Spec->canonpath(File::Spec->catfile($state->{cwd}, $self->{name}));
- $state->{lastfile} = $self;
+ my $fullname = $self->{name};
+ if ($fullname =~ m|^/|) {
+ unless ($absolute_okay) {
+ die "Absolute name forbidden: $fullname";
+ }
+ } else {
+ $fullname = File::Spec->catfile($state->{cwd}, $fullname);
+ }
+ $fullname = File::Spec->canonpath($fullname);
+ $self->{fullname} = $fullname;
return $fullname;
}
@@ -178,18 +201,11 @@ sub fullname($)
return $_[0]->{fullname};
}
-package OpenBSD::PackingElement::File;
+# Abstract class for all file-like elements
+
+package OpenBSD::PackingElement::FileBase;
our @ISA=qw(OpenBSD::PackingElement);
use File::Spec;
-use OpenBSD::PackageInfo qw(is_info_name);
-__PACKAGE__->setKeyword('file');
-
-sub needs_keyword
-{
- my $self = shift;
- return $self->stringize() =~ m/\^@/;
-}
-
sub write
{
my ($self, $fh) = @_;
@@ -214,6 +230,7 @@ sub destate
{
my ($self, $state) = @_;
$self->compute_fullname($state);
+ $state->{lastfile} = $self;
$self->compute_modes($state);
if (defined $state->{nochecksum}) {
$self->{nochecksum} = 1;
@@ -225,22 +242,6 @@ sub destate
}
}
-sub add
-{
- my ($class, $plist, @args) = @_;
-
- my $self = $class->new(@args);
- $self->destate($plist->{state});
- my $j = is_info_name($self->fullname());
- if ($j) {
- bless $self, "OpenBSD::PackingElement::$j";
- $plist->addunique($self);
- } else {
- $plist->add2list($self);
- }
- return $self;
-}
-
sub add_md5
{
my ($self, $md5) = @_;
@@ -272,29 +273,69 @@ sub IsFile() { 1 }
sub NoDuplicateNames() { 1 }
+package OpenBSD::PackingElement::File;
+our @ISA=qw(OpenBSD::PackingElement::FileBase);
+use OpenBSD::PackageInfo qw(is_info_name);
+__PACKAGE__->setKeyword('file');
+sub keyword() { "file" }
+
+sub dirclass() { "OpenBSD::PackingElement::Dir" }
+
+sub needs_keyword
+{
+ my $self = shift;
+ return $self->stringize() =~ m/\^@/;
+}
+
+sub add_object
+{
+ my ($self, $plist) = @_;
+
+ $self->destate($plist->{state});
+ my $j = is_info_name($self->fullname());
+ if ($j) {
+ bless $self, "OpenBSD::PackingElement::$j";
+ $plist->addunique($self);
+ } else {
+ $plist->add2list($self);
+ }
+ return $self;
+}
+
package OpenBSD::PackingElement::Sample;
our @ISA=qw(OpenBSD::PackingElement);
+sub NoDuplicateNames() { 1 }
__PACKAGE__->setKeyword('sample');
sub keyword() { "sample" }
sub destate
{
my ($self, $state) = @_;
$self->{copyfrom} = $state->{lastfile};
+ $self->compute_fullname($state, 1);
+ $self->compute_modes($state);
+}
+
+sub dirclass() { "OpenBSD::PackingElement::Sampledir" }
+
+package OpenBSD::PackingElement::Sampledir;
+our @ISA=qw(OpenBSD::PackingElement::DirBase OpenBSD::PackingElement::Sample);
+sub destate
+{
+ my ($self, $state) = @_;
+ $self->compute_fullname($state, 1);
$self->compute_modes($state);
}
package OpenBSD::PackingElement::InfoFile;
-our @ISA=qw(OpenBSD::PackingElement::File);
+our @ISA=qw(OpenBSD::PackingElement::FileBase);
__PACKAGE__->setKeyword('info');
sub keyword() { "info" }
-sub needs_keyword { 1 }
package OpenBSD::PackingElement::Manpage;
-our @ISA=qw(OpenBSD::PackingElement::File);
+our @ISA=qw(OpenBSD::PackingElement::FileBase);
__PACKAGE__->setKeyword('man');
sub keyword() { "man" }
-sub needs_keyword { 1 }
sub destate
{
@@ -314,9 +355,9 @@ package OpenBSD::PackingElement::Ignore;
our @ISA=qw(OpenBSD::PackingElement);
__PACKAGE__->setKeyword('ignore');
-sub add
+sub add_object
{
- my ($class, $plist, @args) = @_;
+ my ($plist, $self) = @_;
$plist->{state}->{ignore} = 1;
return undef;
}
@@ -331,7 +372,9 @@ sub add
{
my ($class, $plist, @args) = @_;
- if ($args[0] =~ m/^MD5:\s*/) {
+ if ($args[0] =~ m/^\$OpenBSD(.*)\$\s*$/) {
+ OpenBSD::PackingElement::CVSTag->add($plist, @args);
+ } elsif ($args[0] =~ m/^MD5:\s*/) {
$plist->{state}->{lastfile}->add_md5($');
return undef;
} elsif ($args[0] =~ m/^subdir\=(.*?)\s+cdrom\=(.*?)\s+ftp\=(.*?)\s*$/) {
@@ -341,9 +384,7 @@ sub add
return undef;
} else {
my $self = $class->new(@args);
- $self->destate($plist->{state});
- $plist->add2list($self);
- return $self;
+ return $self->add_object($plist);
}
}
@@ -359,6 +400,10 @@ sub add
return undef;
}
+package OpenBSD::PackingElement::CVSTag;
+our @ISA=qw(OpenBSD::PackingElement OpenBSD::PackingElement::Comment);
+sub category() { 'cvstags'}
+
package OpenBSD::PackingElement::symlink;
our @ISA=qw(OpenBSD::PackingElement);
__PACKAGE__->setKeyword('symlink');
@@ -405,7 +450,7 @@ sub add
my ($class, $plist, @args) = @_;
if ($args[0] eq 'no-default-conflict') {
shift;
- return OpenBSD::PackingElement::NoDefaultConflict->add(@_);
+ return OpenBSD::PackingElement::NoDefaultConflict->add($plist);
} else {
die "Unknown option: $args[0]";
}
@@ -416,6 +461,17 @@ our @ISA=qw(OpenBSD::PackingElement::Unique);
sub category() { 'no-default-conflict' }
sub keyword() { 'option' }
+sub stringize()
+{
+ return 'no-default-conflict';
+}
+
+sub new
+{
+ my ($class, @args) = @_;
+ bless {}, $class;
+}
+
# The special elements that don't end in the right place
package OpenBSD::PackingElement::ExtraInfo;
our @ISA=qw(OpenBSD::PackingElement);
@@ -649,12 +705,8 @@ sub destate
$self->{expanded} = $self->expand($self->{name}, $state);
}
-package OpenBSD::PackingElement::Dirs;
-
-sub NoDuplicateNames() { 1 }
-
package OpenBSD::PackingElement::DirRm;
-our @ISA=qw(OpenBSD::PackingElement::Dirs OpenBSD::PackingElement);
+our @ISA=qw(OpenBSD::PackingElement);
__PACKAGE__->setKeyword('dirrm');
sub keyword() { "dirrm" }
@@ -665,10 +717,21 @@ sub destate
$self->compute_fullname($state);
}
+sub NoDuplicateNames() { 1 }
+
+package OpenBSD::PackingElement::DirBase;
+sub stringize($)
+{
+ return $_[0]->{name}."/";
+}
+
+sub NoDuplicateNames() { 1 }
+
package OpenBSD::PackingElement::Dir;
-our @ISA=qw(OpenBSD::PackingElement::Dirs OpenBSD::PackingElement);
+our @ISA=qw(OpenBSD::PackingElement::DirBase OpenBSD::PackingElement);
__PACKAGE__->setKeyword('dir');
+sub keyword() { "dir" }
sub destate
{
@@ -683,11 +746,6 @@ sub needs_keyword
return $self->stringize() =~ m/\^@/;
}
-sub stringize($)
-{
- return $_[0]->{name}."/";
-}
-
package OpenBSD::PackingElement::Fontdir;
our @ISA=qw(OpenBSD::PackingElement::Dir);
__PACKAGE__->setKeyword('fontdir');
@@ -709,9 +767,14 @@ sub keyword() { 'extra' }
sub destate
{
my ($self, $state) = @_;
- $self->compute_fullname($state);
+ $self->compute_fullname($state, 1);
}
+sub dirclass() { "OpenBSD::PackingElement::Extradir" }
+
+package OpenBSD::PackingElement::Extradir;
+our @ISA=qw(OpenBSD::PackingElement::DirBase OpenBSD::PackingElement::Extra);
+
package OpenBSD::PackingElement::SpecialFile;
our @ISA=qw(OpenBSD::PackingElement::Unique);
@@ -725,7 +788,7 @@ sub needs_keyword { 0 }
sub write
{
- &OpenBSD::PackingElement::File::write;
+ &OpenBSD::PackingElement::FileBase::write;
}
package OpenBSD::PackingElement::FCONTENTS;
diff --git a/usr.sbin/pkg_add/OpenBSD/PackingList.pm b/usr.sbin/pkg_add/OpenBSD/PackingList.pm
index f302e8539a1..37adf5682c4 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.16 2004/08/03 12:33:48 espie Exp $
+# $OpenBSD: PackingList.pm,v 1.17 2004/08/05 23:36:40 espie Exp $
#
# Copyright (c) 2003 Marc Espie.
#
@@ -73,7 +73,7 @@ sub DirrmOnly
my ($fh, $cont) = @_;
local $_;
while (<$fh>) {
- next unless m/^\@(?:cwd|dirrm|dir|fontdir|mandir|name)\b/ || m/^[^\@].*\/$/;
+ next unless m/^\@(?:cwd|dirrm|dir|fontdir|mandir|name)\b/ || m/^\@(?:sample|extra)\b.*\/$/ || m/^[^\@].*\/$/;
&$cont($_);
}
}
@@ -121,16 +121,19 @@ MAINLOOP:
sub write
{
- my ($self, $fh) = @_;
- if (!defined $self->{name}) {
- print STDERR "Can't write unnamed packing list\n";
- exit 1;
- }
- $self->{name}->write($fh);
- if (defined $self->{'no-default-conflict'}) {
- $self->{'no-default-conflict'}->write($fh);
+ my ($self, $fh, $w) = @_;
+
+ $w = sub {
+ my ($o, $fh) = @_;
+ $o->write($fh);
+ } unless defined $w;
+
+ if (defined $self->{cvstags}) {
+ for my $item (@{$self->{cvstags}}) {
+ $item->write($fh);
+ }
}
- for my $unique_item (qw(extrainfo arch)) {
+ for my $unique_item (qw(name no-default-conflict extrainfo arch)) {
$self->{$unique_item}->write($fh) if defined $self->{$unique_item};
}
for my $listname (qw(pkgcfl pkgdep newdepend libdepend items)) {
diff --git a/usr.sbin/pkg_add/TODO b/usr.sbin/pkg_add/TODO
index bea481b2e49..60804231756 100644
--- a/usr.sbin/pkg_add/TODO
+++ b/usr.sbin/pkg_add/TODO
@@ -3,8 +3,8 @@
+ handle package dependencies to the level of the old implementation
+ handle chmod/chown to the level of the old implementation
+ handle PKGPATH
++ replace symlinks with @symlink commands at pkg_create time
++ basic validation of packing list at end of reading it...
- add better error handling
- let package delete log files it cannot delete
-- replace symlinks with @symlink commands at pkg_create time
- smart package dependency handling
-- basic validation of packing list at end of reading it...
diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add
index ca4df5a06d1..b7f44d1ba0c 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.38 2004/08/03 12:29:44 espie Exp $
+# $OpenBSD: pkg_add,v 1.39 2004/08/05 23:36:39 espie Exp $
#
# Copyright (c) 2003 Marc Espie.
#
@@ -72,7 +72,7 @@ sub set_modes
}
}
-package OpenBSD::PackingElement::File;
+package OpenBSD::PackingElement::FileBase;
use File::Basename;
use File::Path;
@@ -131,6 +131,13 @@ sub install
}
}
+package OpenBSD::PackingElement::Sampledir;
+
+sub install
+{
+ &OpenBSD::PackingElement::Dir::install;
+}
+
package OpenBSD::PackingElement::InfoFile;
use File::Basename;
diff --git a/usr.sbin/pkg_add/pkg_create b/usr.sbin/pkg_add/pkg_create
index 6f11cf97b53..c19079a0282 100644
--- a/usr.sbin/pkg_add/pkg_create
+++ b/usr.sbin/pkg_add/pkg_create
@@ -1,6 +1,6 @@
#! /usr/bin/perl
# ex:ts=8 sw=4:
-# $OpenBSD: pkg_create,v 1.13 2004/07/20 18:58:41 espie Exp $
+# $OpenBSD: pkg_create,v 1.14 2004/08/05 23:36:39 espie Exp $
#
# Copyright (c) 2003 Marc Espie.
#
@@ -38,7 +38,7 @@ use File::Copy;
package OpenBSD::PackingElement;
sub archive_cmd { () }
-package OpenBSD::PackingElement::File;
+package OpenBSD::PackingElement::FileBase;
sub archive_cmd
{
my ($self, $pfh, $use_cwd) = @_;
@@ -71,7 +71,7 @@ sub compute_checksum
{
}
-package OpenBSD::PackingElement::File;
+package OpenBSD::PackingElement::FileBase;
use OpenBSD::md5;
sub compute_checksum
@@ -306,6 +306,10 @@ for my $special (info_names()) {
$f->{md5} = OpenBSD::md5::fromfile($dir.$special);
}
+if (!defined $plist->{name}) {
+ print STDERR "Can't write unnamed packing list\n";
+ exit 1;
+}
$plist->tofile($dir.CONTENTS) or die "Can't write packing list";
print "Creating gzip'd tar ball in '$ARGV[0]'\n" if $opt_v;
diff --git a/usr.sbin/pkg_add/pkg_delete b/usr.sbin/pkg_add/pkg_delete
index 463ec19f7ff..1cd62db7063 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.29 2004/08/03 12:29:45 espie Exp $
+# $OpenBSD: pkg_delete,v 1.30 2004/08/05 23:36:39 espie Exp $
#
# Copyright (c) 2003 Marc Espie.
#
@@ -91,7 +91,7 @@ sub log_pkgname
}
-package OpenBSD::PackingElement::Dirs;
+package OpenBSD::PackingElement::DirBase;
sub record_dirrm
{
my ($self, $pkgname, $db) = @_;
@@ -129,7 +129,7 @@ sub delete
system('/bin/sh', '-c', $cmd);
}
-package OpenBSD::PackingElement::File;
+package OpenBSD::PackingElement::FileBase;
use OpenBSD::md5;
sub delete
{
@@ -249,23 +249,21 @@ sub delete
return unless $state->{extra};
my $name = $self->fullname();
my $realname = $state->{destdir}.$name;
- if ($self->{name} =~ m|/$|) {
- if ($state->{verbose} or $state->{not}) {
- print "deleting extra directory: $realname\n";
- }
- return if $state->{not};
- return unless -e $realname;
- rmdir($realname) or
- print "problem deleting extra directory $realname\n";
- } else {
- if ($state->{verbose} or $state->{not}) {
- print "deleting extra file: $realname\n";
- }
- return if $state->{not};
- return unless -e $realname;
- unlink($realname) or
- print "problem deleting extra file $realname\n";
+ if ($state->{verbose} or $state->{not}) {
+ 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};
+ $self->SUPER::delete($state);
}
package OpenBSD::PackingElement::ExtraUnexec;