summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Add.pm20
-rw-r--r--usr.sbin/pkg_add/OpenBSD/ArcCheck.pm24
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Delete.pm14
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Dependencies.pm20
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackageLocation.pm230
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackageName.pm53
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackageRepository.pm13
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackageRepository/Installed.pm50
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackageRepositoryList.pm35
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackingElement.pm53
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackingList.pm44
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PkgCfl.pm4
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PkgSpec.pm250
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Replace.pm8
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Search.pm139
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Temp.pm6
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Update.pm69
-rw-r--r--usr.sbin/pkg_add/OpenBSD/UpdateSet.pm4
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Ustar.pm66
-rw-r--r--usr.sbin/pkg_add/pkg8
-rw-r--r--usr.sbin/pkg_add/pkg_add86
-rw-r--r--usr.sbin/pkg_add/pkg_audit5
-rw-r--r--usr.sbin/pkg_add/pkg_create18
-rw-r--r--usr.sbin/pkg_add/pkg_info13
24 files changed, 758 insertions, 474 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Add.pm b/usr.sbin/pkg_add/OpenBSD/Add.pm
index d3135a1379a..3b9d3cec6ca 100644
--- a/usr.sbin/pkg_add/OpenBSD/Add.pm
+++ b/usr.sbin/pkg_add/OpenBSD/Add.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: Add.pm,v 1.86 2009/03/05 10:44:59 espie Exp $
+# $OpenBSD: Add.pm,v 1.87 2009/04/19 14:58:32 espie Exp $
#
# Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org>
#
@@ -262,7 +262,7 @@ sub prepare_for_addition
my $ok = $self->check;
if (defined $ok) {
if ($ok == 0) {
- Warn $self->type, " ", $self->{name},
+ Warn $self->type, " ", $self->name,
" does not match\n";
$state->{problems}++;
}
@@ -274,7 +274,7 @@ sub install
{
my ($self, $state) = @_;
$self->SUPER::install($state);
- my $auth = $self->{name};
+ my $auth = $self->name;
print "adding ", $self->type, " $auth\n" if $state->{verbose};
return if $state->{not};
return if defined $self->{okay};
@@ -319,7 +319,7 @@ sub install
{
my ($self, $state) = @_;
- my $name = $self->{name};
+ my $name = $self->name;
$self->SUPER::install($state);
open(my $pipe, '-|', OpenBSD::Paths->sysctl, '-n', $name);
my $actual = <$pipe>;
@@ -427,12 +427,12 @@ sub prepare_to_extract
}
$file->{cwd} = $self->cwd;
if (!$file->check_name($self)) {
- Fatal "Error: archive does not match ", $file->{name}, "!=",
- $self->{name}, "\n";
+ Fatal "Error: archive does not match ", $file->name, "!=",
+ $self->name, "\n";
}
if (defined $self->{symlink} || $file->isSymLink) {
unless (defined $self->{symlink} && $file->isSymLink) {
- Fatal "Error: bogus symlink ", $self->{name}, "\n";
+ Fatal "Error: bogus symlink ", $self->name, "\n";
}
if (!$file->check_linkname($self->{symlink})) {
Fatal "Error: archive sl does not match ", $file->{linkname}, "!=",
@@ -440,7 +440,7 @@ sub prepare_to_extract
}
} elsif (defined $self->{link} || $file->isHardLink) {
unless (defined $self->{link} && $file->isHardLink) {
- Fatal "Error: bogus hardlink ", $self->{name}, "\n";
+ Fatal "Error: bogus hardlink ", $self->name, "\n";
}
if (!$file->check_linkname($self->{link})) {
Fatal "Error: archive hl does not match ", $file->{linkname}, "!=",
@@ -451,7 +451,7 @@ sub prepare_to_extract
Fatal "Can't continue\n";
}
- $file->{name} = $fullname;
+ $file->set_name($fullname);
$file->{destdir} = $destdir;
# faked installation are VERY weird
if (defined $self->{symlink} && $state->{do_faked}) {
@@ -661,7 +661,7 @@ sub prepare_for_addition
{
my ($self, $state, $pkgname) = @_;
- my $fname = installed_info($pkgname).$self->{name};
+ my $fname = installed_info($pkgname).$self->name;
my $cname = $self->fullname;
my $size = $self->{size};
if (!defined $size) {
diff --git a/usr.sbin/pkg_add/OpenBSD/ArcCheck.pm b/usr.sbin/pkg_add/OpenBSD/ArcCheck.pm
index cf73f6dca00..7086123a98d 100644
--- a/usr.sbin/pkg_add/OpenBSD/ArcCheck.pm
+++ b/usr.sbin/pkg_add/OpenBSD/ArcCheck.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: ArcCheck.pm,v 1.10 2007/06/12 09:53:36 espie Exp $
+# $OpenBSD: ArcCheck.pm,v 1.11 2009/04/19 14:58:32 espie Exp $
#
# Copyright (c) 2005-2006 Marc Espie <espie@openbsd.org>
#
@@ -28,9 +28,9 @@ package OpenBSD::Ustar::Object;
sub check_name
{
my ($self, $item) = @_;
- return 1 if $self->{name} eq $item->{name};
- if ($self->{name} =~ m/^LongName\d+$/o) {
- $self->{name} = $item->{name};
+ return 1 if $self->name eq $item->name;
+ if ($self->name =~ m/^LongName\d+$/o) {
+ $self->set_name($item->name);
return 1;
}
return 0;
@@ -98,12 +98,12 @@ sub verify_modes
sub copy_long
{
my ($self, $wrarc) = @_;
- if ($self->{name} =~ m/^LongName(\d+)$/o) {
+ if ($self->name =~ m/^LongName(\d+)$/o) {
$wrarc->{name_index} = $1 + 1;
}
- if (length($self->{name}) > MAXFILENAME+MAXPREFIX+1) {
+ if (length($self->name) > MAXFILENAME+MAXPREFIX+1) {
$wrarc->{name_index} = 0 if !defined $wrarc->{name_index};
- $entry->{name} = 'LongName'.$wrarc->{name_index}++;
+ $self->set_name('LongName'.$wrarc->{name_index}++);
}
$self->copy($wrarc);
}
@@ -114,18 +114,18 @@ package OpenBSD::Ustar;
sub prepare_long
{
my ($self, $item) = @_;
- my $filename = $item->{name};
+ my $filename = $item->name;
my $entry = $self->prepare($filename);
if (!defined $entry->{uname}) {
- die "No user name for ", $entry->{name}, " (uid ", $entry->{uid}, ")";
+ die "No user name for ", $entry->name, " (uid ", $entry->{uid}, ")";
}
if (!defined $entry->{gname}) {
- die "No group name for ", $entry->{name}, " (gid ", $entry->{gid}. ")";
+ die "No group name for ", $entry->name, " (gid ", $entry->{gid}. ")";
}
- my ($prefix, $name) = split_name($entry->{name});
+ my ($prefix, $name) = split_name($entry->name);
if (length($name) > MAXFILENAME || length($prefix) > MAXPREFIX) {
$self->{name_index} = 0 if !defined $self->{name_index};
- $entry->{name} = 'LongName'.$self->{name_index}++;
+ $entry->name = 'LongName'.$self->{name_index}++;
}
if (length($entry->{linkname}) > MAXLINKNAME) {
$self->{linkname_index} = 0 if !defined $self->{linkname_index};
diff --git a/usr.sbin/pkg_add/OpenBSD/Delete.pm b/usr.sbin/pkg_add/OpenBSD/Delete.pm
index f7a686377ca..1d87fe078a3 100644
--- a/usr.sbin/pkg_add/OpenBSD/Delete.pm
+++ b/usr.sbin/pkg_add/OpenBSD/Delete.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: Delete.pm,v 1.80 2009/04/18 08:30:02 espie Exp $
+# $OpenBSD: Delete.pm,v 1.81 2009/04/19 14:58:32 espie Exp $
#
# Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org>
#
@@ -179,11 +179,11 @@ sub rename_file_to_temp
close $fh;
if (rename($n, $j)) {
print "Renaming old file $n to $j\n";
- if ($self->{name} !~ m/^\//o && $self->cwd ne '.') {
+ if ($self->name !~ m/^\//o && $self->cwd ne '.') {
my $c = $self->cwd;
$j =~ s|^\Q$c\E/||;
}
- $self->{name} = $j;
+ $self->set_name($j);
} else {
print "Bad rename $n to $j: $!\n";
}
@@ -277,7 +277,7 @@ sub delete
my ($self, $state) = @_;
if ($state->{beverbose}) {
- print "rmuser: $self->{name}\n";
+ print "rmuser: ", $self->name, "\n";
}
$self->record_shared($state->{recorder}, $state->{pkgname});
@@ -286,7 +286,7 @@ sub delete
sub record_shared
{
my ($self, $recorder, $pkgname) = @_;
- $recorder->{users}->{$self->{name}} = $pkgname;
+ $recorder->{users}->{$self->name} = $pkgname;
}
package OpenBSD::PackingElement::NewGroup;
@@ -295,7 +295,7 @@ sub delete
my ($self, $state) = @_;
if ($state->{beverbose}) {
- print "rmgroup: $self->{name}\n";
+ print "rmgroup: ", $self->name, "\n";
}
$self->record_shared($state->{recorder}, $state->{pkgname});
@@ -304,7 +304,7 @@ sub delete
sub record_shared
{
my ($self, $recorder, $pkgname) = @_;
- $recorder->{groups}->{$self->{name}} = $pkgname;
+ $recorder->{groups}->{$self->name} = $pkgname;
}
package OpenBSD::PackingElement::DirBase;
diff --git a/usr.sbin/pkg_add/OpenBSD/Dependencies.pm b/usr.sbin/pkg_add/OpenBSD/Dependencies.pm
index 70affdc1493..fc2d0d87293 100644
--- a/usr.sbin/pkg_add/OpenBSD/Dependencies.pm
+++ b/usr.sbin/pkg_add/OpenBSD/Dependencies.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: Dependencies.pm,v 1.64 2008/06/21 14:01:10 espie Exp $
+# $OpenBSD: Dependencies.pm,v 1.65 2009/04/19 14:58:32 espie Exp $
#
# Copyright (c) 2005-2007 Marc Espie <espie@openbsd.org>
#
@@ -162,7 +162,7 @@ sub find_in_plist
my ($self, $plist, $dep) = @_;
if ($plist->has('define-tag')) {
for my $t (@{$plist->{'define-tag'}}) {
- $self->{known_tags}->{$t->{name}} = $dep;
+ $self->{known_tags}->{$t->name} = $dep;
}
}
}
@@ -241,15 +241,17 @@ sub find_dep_in_repositories
my ($self, $state, $dep) = @_;
require OpenBSD::PackageLocator;
- my @candidates = OpenBSD::PackageLocator->match_locations($dep->spec);
- # XXX not really efficient, but hey
- my %c = map {($_->{name}, $_)} @candidates;
- my @pkgs = keys %c;
+ my $candidates = OpenBSD::PackageLocator->match_locations($dep->spec);
if (!$state->{defines}->{allversions}) {
- @pkgs = OpenBSD::PackageName::keep_most_recent(@pkgs);
+ require OpenBSD::Search;
+ $candidates = OpenBSD::Search::FilterLocation->
+ keep_most_recent->filter_locations($candidates);
}
+ # XXX not really efficient, but hey
+ my %c = map {($_->name, $_)} @$candidates;
+ my @pkgs = keys %c;
if (@pkgs == 1) {
- return $c{$pkgs[0]};
+ return $candidates->[0];
} elsif (@pkgs > 1) {
require OpenBSD::Interactive;
@@ -301,7 +303,7 @@ sub solve_dependency
$v = $self->find_dep_in_repositories($state, $dep);
if ($v) {
push(@{$self->{deplist}},
- OpenBSD::UpdateSet->from_location($v->openPackage));
+ OpenBSD::UpdateSet->from_location($v));
return $v->{name};
}
diff --git a/usr.sbin/pkg_add/OpenBSD/PackageLocation.pm b/usr.sbin/pkg_add/OpenBSD/PackageLocation.pm
index 1fc05ceab6e..f58c05cf844 100644
--- a/usr.sbin/pkg_add/OpenBSD/PackageLocation.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PackageLocation.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: PackageLocation.pm,v 1.15 2007/06/10 17:13:48 espie Exp $
+# $OpenBSD: PackageLocation.pm,v 1.16 2009/04/19 14:58:32 espie Exp $
#
# Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org>
#
@@ -27,9 +27,11 @@ sub new
{
my ($class, $repository, $name, $arch) = @_;
- my $self = { repository => $repository, name => $repository->canonicalize($name), arch => $arch};
+ my $self = { repository => $repository, name => $repository->canonicalize($name)};
+ if (defined $arch) {
+ $self->{arch} = $arch;
+ }
bless $self, $class;
-# print STDERR "Built location ", $self->url, "\n";
return $self;
}
@@ -54,10 +56,35 @@ sub name
return $self->{name};
}
-sub openArchive
+sub pkgname
+{
+ my $self = shift;
+ if (!defined $self->{pkgname}) {
+ require OpenBSD::PackageName;
+
+ $self->{pkgname} = OpenBSD::PackageName->from_string($self->name);
+ }
+ return $self->{pkgname};
+}
+
+sub update_info
+{
+ my $self = shift;
+ if (!defined $self->{update_info}) {
+ $self->{update_info} = $self->grabPlist(\&OpenBSD::PackingList::UpdateInfoOnly);
+ }
+ return $self->{update_info};
+}
+
+
+# make sure self is opened and move to the right location if need be.
+sub _opened
{
my $self = shift;
+ if (defined $self->{fh}) {
+ return $self;
+ }
my $fh = $self->{repository}->open($self);
if (!defined $fh) {
$self->{repository}->parse_problems($self->{errors})
@@ -66,53 +93,96 @@ sub openArchive
return;
}
require OpenBSD::Ustar;
-
my $archive = new OpenBSD::Ustar $fh;
$self->{_archive} = $archive;
+
+ if (defined $self->{_current}) {
+ while (my $e = $self->{_archive}->next) {
+ if ($e->{name} eq $self->{_current}->{name}) {
+ $self->{_current} = $e;
+ return $self;
+ }
+ }
+ }
+ return $self;
}
-sub grabInfoFiles
+sub find_contents
{
my $self = shift;
- my $dir = $self->{dir} = OpenBSD::Temp::dir();
- if (defined $self->{contents} && ! -f $dir.CONTENTS) {
- open my $fh, '>', $dir.CONTENTS or die "Permission denied";
- print $fh $self->{contents};
- close $fh;
- }
-
- while (my $e = $self->intNext) {
+ while (my $e = $self->_next) {
if ($e->isFile && is_info_name($e->{name})) {
- $e->{name}=$dir.$e->{name};
- eval { $e->create; };
- if ($@) {
- unlink($e->{name});
- $@ =~ s/\s+at.*//o;
- print STDERR $@;
- return 0;
+ if ($e->{name} eq CONTENTS ) {
+ return $e->contents;
}
} else {
$self->unput;
last;
}
}
- return 1;
}
-sub scanPackage
+sub find_fat_contents
{
my $self = shift;
- while (my $e = $self->intNext) {
- if ($e->isFile && is_info_name($e->{name})) {
- if ($e->{name} eq CONTENTS && !defined $self->{dir}) {
- $self->{contents} = $e->contents;
- last;
- }
- if (!defined $self->{dir}) {
- $self->{dir} = OpenBSD::Temp::dir();
+
+ while (my $e = $self->_next) {
+ unless ($e->{name} =~ m/^(.*)\/\+CONTENTS$/o) {
+ last;
+ }
+ my $prefix = $1;
+ my $contents = $e->contents;
+ require OpenBSD::PackingList;
+
+ my $plist = OpenBSD::PackingList->fromfile(\$contents,
+ \&OpenBSD::PackingList::FatOnly);
+ if (defined $self->name) {
+ next if $plist->pkgname ne $self->name;
+ }
+ if ($plist->has('arch')) {
+ if ($plist->{arch}->check($self->{arch})) {
+ $self->{filter} = $prefix;
+ bless $self, "OpenBSD::FatPackageLocation";
+ return $contents;
}
- $e->{name}=$self->{dir}.$e->{name};
+ }
+ }
+}
+
+sub contents
+{
+ my $self = shift;
+ if (!defined $self->{contents}) {
+ if (!$self->_opened) {
+ return;
+ }
+ $self->{contents} = $self->find_contents ||
+ $self->find_fat_contents;
+ }
+
+ return $self->{contents};
+}
+
+sub grabInfoFiles
+{
+ my $self = shift;
+ my $dir = $self->{dir} = OpenBSD::Temp->dir;
+
+ my $c = $self->contents;
+ if (!defined $c) {
+ return 0;
+ }
+
+ if (! -f $dir.CONTENTS) {
+ open my $fh, '>', $dir.CONTENTS or die "Permission denied";
+ print $fh $self->contents;
+ close $fh;
+ }
+
+ while (my $e = $self->_next) {
+ if ($e->isFile && is_info_name($e->{name})) {
+ $e->{name} = $dir.$e->{name};
eval { $e->create; };
if ($@) {
unlink($e->{name});
@@ -132,59 +202,16 @@ sub grabPlist
{
my ($self, $code) = @_;
- my $pkg = $self->openPackage;
- if (defined $pkg) {
- my $plist = $self->plist($code);
- $pkg->wipe_info;
- $pkg->close_now;
+ my $plist = $self->plist($code);
+ if (defined $plist) {
+ $self->wipe_info;
+ $self->close_now;
return $plist;
} else {
return;
}
}
-sub openPackage
-{
- my $self = shift;
- my $arch = $self->{arch};
- if (!$self->openArchive) {
- return;
- }
- $self->scanPackage;
-
- if (defined $self->{contents}) {
- return $self;
- }
-
- # maybe it's a fat package.
- while (my $e = $self->intNext) {
- unless ($e->{name} =~ m/^(.*)\/\+CONTENTS$/o) {
- last;
- }
- my $prefix = $1;
- my $contents = $e->contents;
- require OpenBSD::PackingList;
-
- my $plist = OpenBSD::PackingList->fromfile(\$contents,
- \&OpenBSD::PackingList::FatOnly);
- if (defined $self->{name}) {
- next if $plist->pkgname ne $self->{name};
- }
- if ($plist->has('arch')) {
- if ($plist->{arch}->check($arch)) {
- $self->{filter} = $prefix;
- bless $self, "OpenBSD::FatPackageLocation";
- $self->{contents} = $contents;
- return $self;
- }
- }
- }
- # hopeless
- $self->close_with_client_error;
- $self->wipe_info;
- return;
-}
-
sub wipe_info
{
my $self = shift;
@@ -194,8 +221,9 @@ sub wipe_info
sub info
{
my $self = shift;
+
if (!defined $self->{dir}) {
- $self->grabInfoFiles;
+ $self->{repository}->grab_info($self);
}
return $self->{dir};
}
@@ -203,19 +231,25 @@ sub info
sub plist
{
my ($self, $code) = @_;
+ $self->{repository}->get_plist($self, $code);
+}
+
+sub _plist
+{
+ my ($self, $code) = @_;
require OpenBSD::PackingList;
- if (defined $self->{contents}) {
- my $value = $self->{contents};
- return OpenBSD::PackingList->fromfile(\$value, $code);
- } elsif (defined $self->{dir} && -f $self->{dir}.CONTENTS) {
+ if (defined $self->{dir} && -f $self->{dir}.CONTENTS) {
my $plist =
OpenBSD::PackingList->fromfile($self->{dir}.CONTENTS,
$code);
$plist->set_infodir($self->{dir});
return $plist;
}
+ if (my $value = $self->contents) {
+ return OpenBSD::PackingList->fromfile(\$value, $code);
+ }
# hopeless
$self->close_with_client_error;
@@ -261,21 +295,6 @@ sub deref
$self->{_archive} = undef;
}
-sub reopen
-{
- my $self = shift;
- if (!$self->openArchive) {
- return;
- }
- while (my $e = $self->{_archive}->next) {
- if ($e->{name} eq $self->{_current}->{name}) {
- $self->{_current} = $e;
- return $self;
- }
- }
- return;
-}
-
# proxy for archive operations
sub next
{
@@ -284,22 +303,21 @@ sub next
if (!defined $self->{dir}) {
$self->grabInfoFiles;
}
- return $self->intNext;
+ return $self->_next;
}
-sub intNext
+sub _next
{
my $self = shift;
- if (!defined $self->{fh}) {
- if (!$self->reopen) {
- return;
- }
+ if (!$self->_opened) {
+ return;
}
if (!$self->{_unput}) {
$self->{_current} = $self->getNext;
+ } else {
+ $self->{_unput} = 0;
}
- $self->{_unput} = 0;
return $self->{_current};
}
diff --git a/usr.sbin/pkg_add/OpenBSD/PackageName.pm b/usr.sbin/pkg_add/OpenBSD/PackageName.pm
index c42bd216169..a40f3e7db5b 100644
--- a/usr.sbin/pkg_add/OpenBSD/PackageName.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PackageName.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: PackageName.pm,v 1.33 2009/03/07 12:04:13 espie Exp $
+# $OpenBSD: PackageName.pm,v 1.34 2009/04/19 14:58:32 espie Exp $
#
# Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org>
#
@@ -83,46 +83,6 @@ sub is_stem
}
}
-sub splitp
-{
- my $_ = shift;
-
- if (/^(.*\-\d[^-]*)p(\d+)(.*)$/o) {
- return ($1.$3, $2);
- } else {
- return ($_,-1);
- }
-}
-
-sub rebuildp
-{
- my ($pkg, $p) = @_;
- if ($p == -1) {
- return $pkg;
- }
- if ($pkg =~ m/^(.*?)(\-\d[^-v]*)(.*)$/o) {
- return "$1$2p$p$3";
- } else {
- return $pkg."p".$p;
- }
-}
-
-sub keep_most_recent
-{
- my $h = {};
- for my $pkgname (@_) {
- my ($p, $v) = splitp($pkgname);
- if (!defined $h->{$p} || $h->{$p} < $v) {
- $h->{$p} = $v;
- }
- }
- my @list = ();
- while (my ($p, $v) = each %$h) {
- push(@list, rebuildp($p, $v));
- }
- return @list;
-}
-
sub compile_stemlist
{
my $hash = {};
@@ -355,16 +315,23 @@ sub to_pattern
}
package OpenBSD::PackageName::Name;
+sub flavor_string
+{
+ my $o = shift;
+ return join('-', sort keys %{$o->{flavors}});
+}
+
sub to_string
{
my $o = shift;
- return join('-', $o->{stem}, $o->{version}->to_string, sort keys %{$o->{flavors}});
+ return join('-', $o->{stem}, $o->{version}->to_string,
+ $o->flavor_string);
}
sub to_pattern
{
my $o = shift;
- return join('-', $o->{stem}, '*', sort keys %{$o->{flavors}});
+ return join('-', $o->{stem}, '*', $o->flavor_string);
}
1;
diff --git a/usr.sbin/pkg_add/OpenBSD/PackageRepository.pm b/usr.sbin/pkg_add/OpenBSD/PackageRepository.pm
index 1e8d2fe7bc1..796e6260861 100644
--- a/usr.sbin/pkg_add/OpenBSD/PackageRepository.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PackageRepository.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: PackageRepository.pm,v 1.62 2009/02/02 20:41:47 espie Exp $
+# $OpenBSD: PackageRepository.pm,v 1.63 2009/04/19 14:58:32 espie Exp $
#
# Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org>
#
@@ -231,7 +231,9 @@ sub find
my ($repository, $name, $arch) = @_;
my $self = OpenBSD::PackageLocation->new($repository, $name, $arch);
- return $self->openPackage;
+ if ($self->contents) {
+ return $self;
+ }
}
sub grabPlist
@@ -482,7 +484,7 @@ sub open_pipe
require OpenBSD::Temp;
my ($self, $object) = @_;
- $object->{errors} = OpenBSD::Temp::file();
+ $object->{errors} = OpenBSD::Temp->file;
$object->{cache_dir} = $ENV{'PKG_CACHE'};
$object->{parent} = $$;
@@ -560,9 +562,6 @@ sub grab_object
{
my ($self, $object) = @_;
my ($ftp, @extra) = split(/\s+/, OpenBSD::Paths->ftp);
- if (defined $ENV{'FTP_KEEPALIVE'}) {
- push(@extra, "-k", $ENV{'FTP_KEEPALIVE'});
- }
exec {$ftp}
$ftp,
@extra,
@@ -691,7 +690,7 @@ sub list
my ($self) = @_;
if (!defined $self->{list}) {
$self->make_room;
- my $error = OpenBSD::Temp::file();
+ my $error = OpenBSD::Temp->file;
$self->{list} = $self->obtain_list($error);
$self->parse_problems($error);
}
diff --git a/usr.sbin/pkg_add/OpenBSD/PackageRepository/Installed.pm b/usr.sbin/pkg_add/OpenBSD/PackageRepository/Installed.pm
index 57463fd14d3..ff926d516a8 100644
--- a/usr.sbin/pkg_add/OpenBSD/PackageRepository/Installed.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PackageRepository/Installed.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: Installed.pm,v 1.12 2007/06/10 17:13:48 espie Exp $
+# $OpenBSD: Installed.pm,v 1.13 2009/04/19 14:58:32 espie Exp $
#
# Copyright (c) 2007 Marc Espie <espie@openbsd.org>
#
@@ -40,12 +40,12 @@ sub match
sub match_locations
{
my ($self, $search, @filters) = @_;
- my @l = $search->match_locations($self);
+ my $l = $search->match_locations($self);
while (my $filter = (shift @filters)) {
- last if @l == 0; # don't bother filtering empty list
- @l = $filter->filter_locations(@l);
+ last if @$l == 0; # don't bother filtering empty list
+ $l = $filter->filter_locations($l);
}
- return @l;
+ return $l;
}
sub url
@@ -88,6 +88,32 @@ sub canonicalize
return $name;
}
+sub locations_list
+{
+ my $self = shift;
+ if (!defined $self->{locations}) {
+ my $l = [];
+ require OpenBSD::PackageLocation;
+
+ for my $name (@{$self->list}) {
+ push @$l, OpenBSD::PackageLocation->new($self, $name);
+ }
+ $self->{locations} = $l;
+ }
+ return $self->{locations};
+}
+
+sub grab_info
+{
+ my ($repository, $location) = @_;
+ $location->grabInfoFiles;
+}
+
+sub get_plist
+{
+ my ($repository, $location, $code) = @_;
+ $location->_plist($code);
+}
package OpenBSD::PackageRepository::Installed;
our @ISA = (qw(OpenBSD::PackageRepositoryBase));
@@ -123,6 +149,7 @@ sub canonicalize
my ($self, $name) = @_;
return installed_name($name);
}
+
sub find
{
my ($repository, $name, $arch) = @_;
@@ -137,6 +164,19 @@ sub find
return $self;
}
+sub grab_info
+{
+ my ($repository, $location) = @_;
+ $location->{dir} = installed_info($location->name);
+}
+
+sub get_plist
+{
+ my ($repository, $location, $code) = @_;
+ require OpenBSD::PackingList;
+ return OpenBSD::PackingList->from_installation($location->name, $code);
+}
+
sub grabPlist
{
my ($repository, $name, $arch, $code) = @_;
diff --git a/usr.sbin/pkg_add/OpenBSD/PackageRepositoryList.pm b/usr.sbin/pkg_add/OpenBSD/PackageRepositoryList.pm
index 935ba2d299f..f073c13cff3 100644
--- a/usr.sbin/pkg_add/OpenBSD/PackageRepositoryList.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PackageRepositoryList.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: PackageRepositoryList.pm,v 1.16 2007/05/19 09:50:31 espie Exp $
+# $OpenBSD: PackageRepositoryList.pm,v 1.17 2009/04/19 14:58:32 espie Exp $
#
# Copyright (c) 2003-2006 Marc Espie <espie@openbsd.org>
#
@@ -23,20 +23,20 @@ package OpenBSD::PackageRepositoryList;
sub new
{
my $class = shift;
- return bless {list => [] }, $class;
+ return bless [], $class;
}
sub add
{
my $self = shift;
- push @{$self->{list}}, @_;
+ push @$self, @_;
}
sub find
{
my ($self, $pkgname, $arch) = @_;
- for my $repo (@{$self->{list}}) {
+ for my $repo (@$self) {
my $pkg = $repo->find($pkgname, $arch);
return $pkg if defined $pkg;
}
@@ -47,7 +47,7 @@ sub grabPlist
{
my ($self, $pkgname, $arch, $code) = @_;
- for my $repo (@{$self->{list}}) {
+ for my $repo (@$self) {
my $plist = $repo->grabPlist($pkgname, $arch, $code);
return $plist if defined $plist;
}
@@ -57,7 +57,7 @@ sub grabPlist
sub match
{
my ($self, @search) = @_;
- for my $repo (@{$self->{list}}) {
+ for my $repo (@$self) {
my @l = $repo->match(@search);
if (@l > 0) {
return @l;
@@ -69,21 +69,32 @@ sub match
sub match_locations
{
my ($self, @search) = @_;
- for my $repo (@{$self->{list}}) {
- my @l = $repo->match_locations(@search);
- if (@l > 0) {
- return @l;
+ for my $repo (@$self) {
+ my $l = $repo->match_locations(@search);
+ if (@$l > 0) {
+ return $l;
}
}
- return ();
+ return [];
}
sub cleanup
{
my $self = shift;
- for my $repo (@{$self->{list}}) {
+ for my $repo (@$self) {
$repo->cleanup;
}
}
+sub print_without_src
+{
+ my $self = shift;
+ my @l = ();
+ for my $repo (@$self) {
+ next if $repo->isa("OpenBSD::PackageRepository::Source");
+ push(@l, $repo->url);
+ }
+ return join(':', @l);
+}
+
1;
diff --git a/usr.sbin/pkg_add/OpenBSD/PackingElement.pm b/usr.sbin/pkg_add/OpenBSD/PackingElement.pm
index 2b29a4b46d7..f1efc493d72 100644
--- a/usr.sbin/pkg_add/OpenBSD/PackingElement.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PackingElement.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: PackingElement.pm,v 1.155 2009/04/14 17:53:58 espie Exp $
+# $OpenBSD: PackingElement.pm,v 1.156 2009/04/19 14:58:32 espie Exp $
#
# Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org>
#
@@ -130,12 +130,23 @@ sub fullstring
}
}
-sub stringize
+sub name
{
my $self = shift;
return $self->{name};
}
+sub set_name
+{
+ my ($self, $v) = @_;
+ $self->{name} = $v;
+}
+sub stringize
+{
+ my $self = shift;
+ return $self->name;
+}
+
sub IsFile() { 0 }
sub NoDuplicateNames() { 0 }
@@ -176,10 +187,10 @@ sub compute_fullname
my ($self, $state, $absolute_okay) = @_;
$self->{cwd} = $state->{cwd};
- $self->{name} = File::Spec->canonpath($self->{name});
- if ($self->{name} =~ m|^/|) {
+ $self->set_name(File::Spec->canonpath($self->name));
+ if ($self->name =~ m|^/|) {
unless ($absolute_okay) {
- die "Absolute name forbidden: ", $self->{name};
+ die "Absolute name forbidden: ", $self->name;
}
}
}
@@ -187,7 +198,7 @@ sub compute_fullname
sub fullname
{
my $self = $_[0];
- my $fullname = $self->{name};
+ my $fullname = $self->name;
if ($fullname !~ m|^/|o && $self->cwd ne '.') {
$fullname = $self->cwd."/".$fullname;
}
@@ -306,7 +317,7 @@ our @ISA=qw(OpenBSD::PackingElement::Meta);
sub signature
{
my ($self, $hash) = @_;
- $hash->{$self->{name}} = 1;
+ $hash->{$self->name} = 1;
}
# Abstract class for all file-like elements
@@ -391,7 +402,7 @@ sub check_digest
if (!defined $self->{d}) {
$state->fatal($self->fullname, " does not have a signature");
}
- my $d = $self->compute_digest($file->{destdir}.$file->{name});
+ my $d = $self->compute_digest($file->{destdir}.$file->name);
if (!$d->equals($self->{d})) {
$state->fatal("checksum for ", $self->fullname,
" does not match");
@@ -491,13 +502,13 @@ sub register_manpage
sub is_source
{
my $self = shift;
- return $self->{name} =~ m/man\/man[^\/]+\/[^\/]+\.[\dln][^\/]?$/o;
+ return $self->name =~ m/man\/man[^\/]+\/[^\/]+\.[\dln][^\/]?$/o;
}
sub source_to_dest
{
my $self = shift;
- my $v = $self->{name};
+ my $v = $self->name;
$v =~ s/(man\/)man([^\/]+\/[^\/]+)\.[\dln][^\/]?$/$1cat$2.0/;
return $v;
}
@@ -961,7 +972,7 @@ sub check
{
my $self = shift;
my ($name, $passwd, $uid, $gid, $quota, $class, $gcos, $dir, $shell,
- $expire) = getpwnam($self->{name});
+ $expire) = getpwnam($self->name);
return unless defined $name;
if ($self->{uid} =~ m/^\!(.*)$/o) {
return 0 unless $uid == $1;
@@ -1015,7 +1026,7 @@ sub new
sub check
{
my $self = shift;
- my ($name, $passwd, $gid, $members) = getgrnam($self->{name});
+ my ($name, $passwd, $gid, $members) = getgrnam($self->name);
return unless defined $name;
if ($self->{gid} =~ m/^\!(.*)$/o) {
return 0 unless $gid == $1;
@@ -1041,7 +1052,7 @@ __PACKAGE__->register_with_factory;
sub destate
{
my ($self, $state) = @_;
- $state->set_cwd($self->{name});
+ $state->set_cwd($self->name);
}
package OpenBSD::PackingElement::EndFake;
@@ -1069,10 +1080,10 @@ sub destate
{
my ($self, $state) = @_;
- if ($self->{name} eq '') {
+ if ($self->name eq '') {
undef $state->{owner};
} else {
- $state->{owner} = $self->{name};
+ $state->{owner} = $self->name;
}
}
@@ -1086,10 +1097,10 @@ sub destate
{
my ($self, $state) = @_;
- if ($self->{name} eq '') {
+ if ($self->name eq '') {
undef $state->{group};
} else {
- $state->{group} = $self->{name};
+ $state->{group} = $self->name;
}
}
@@ -1103,10 +1114,10 @@ sub destate
{
my ($self, $state) = @_;
- if ($self->{name} eq '') {
+ if ($self->name eq '') {
undef $state->{mode};
} else {
- $state->{mode} = $self->{name};
+ $state->{mode} = $self->name;
}
}
@@ -1141,7 +1152,7 @@ our @ISA=qw(OpenBSD::PackingElement::Action);
sub expand
{
my ($self, $state) = @_;
- my $_ = $self->{name};
+ my $_ = $self->name;
if (m/\%F/o) {
die "Bad expand" unless defined $state->{lastfile};
s/\%F/$state->{lastfile}->{name}/g;
@@ -1248,7 +1259,7 @@ sub destate
sub stringize
{
my $self = shift;
- return $self->{name}."/";
+ return $self->name."/";
}
sub write
diff --git a/usr.sbin/pkg_add/OpenBSD/PackingList.pm b/usr.sbin/pkg_add/OpenBSD/PackingList.pm
index c60ce2bc828..26367230885 100644
--- a/usr.sbin/pkg_add/OpenBSD/PackingList.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PackingList.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: PackingList.pm,v 1.87 2009/04/14 17:53:58 espie Exp $
+# $OpenBSD: PackingList.pm,v 1.88 2009/04/19 14:58:32 espie Exp $
#
# Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org>
#
@@ -45,6 +45,18 @@ sub set_cwd
$self->{cwd} = \$p;
}
+package OpenBSD::PackingList::hashpath;
+sub match
+{
+ my ($a, $b) = @_;
+ for my $i (keys %$a) {
+ if ($b->{$i}) {
+ return 1;
+ }
+ }
+ return 0;
+}
+
package OpenBSD::PackingList;
use OpenBSD::PackingElement;
@@ -352,7 +364,7 @@ sub set_pkgname
{
my ($self, $name) = @_;
if (defined $self->{name}) {
- $self->{name}->{name} = $name;
+ $self->{name}->set_name($name);
} else {
OpenBSD::PackingElement::Name->add($self, $name);
}
@@ -361,7 +373,7 @@ sub set_pkgname
sub pkgname
{
my $self = shift;
- return $self->{name}->{name};
+ return $self->{name}->name;
}
sub localbase
@@ -369,7 +381,7 @@ sub localbase
my $self = shift;
if (defined $self->{localbase}) {
- return $self->{localbase}->{name};
+ return $self->{localbase}->name;
} else {
return '/usr/local';
}
@@ -381,6 +393,30 @@ sub is_signed
return defined $self->{'digital-signature'};
}
+sub pkgpath
+{
+ my $self = shift;
+ if (!defined $self->{_hashpath}) {
+ my $h = $self->{_hashpath} =
+ bless {}, "OpenBSD::PackingList::hashpath";
+ if (defined $self->{extrainfo}) {
+ $h->{$self->{extrainfo}->{subdir}} = 1;
+ }
+ if (defined $self->{pkgpath}) {
+ for my $i (@{$self->{pkgpath}}) {
+ $h->{$i->name} = 1;
+ }
+ }
+ }
+ return $self->{_hashpath};
+}
+
+sub match_pkgpath
+{
+ my ($self, $plist2) = @_;
+ return $self->pkgpath->match($plist2->pkgpath);
+}
+
our @unique_categories =
(qw(name digital-signature no-default-conflict manual-installation extrainfo localbase arch));
diff --git a/usr.sbin/pkg_add/OpenBSD/PkgCfl.pm b/usr.sbin/pkg_add/OpenBSD/PkgCfl.pm
index 7bb508daec2..4135c003564 100644
--- a/usr.sbin/pkg_add/OpenBSD/PkgCfl.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PkgCfl.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: PkgCfl.pm,v 1.25 2007/12/28 12:55:03 espie Exp $
+# $OpenBSD: PkgCfl.pm,v 1.26 2009/04/19 14:58:32 espie Exp $
#
# Copyright (c) 2003-2005 Marc Espie <espie@openbsd.org>
#
@@ -42,7 +42,7 @@ sub make_conflict_list
push(@$l, OpenBSD::Search::PkgSpec->new(".libs-$stem-*"));
if (defined $plist->{conflict}) {
for my $cfl (@{$plist->{conflict}}) {
- push(@$l, OpenBSD::Search::PkgSpec->new($cfl->{name}));
+ push(@$l, OpenBSD::Search::PkgSpec->new($cfl->name));
}
}
bless $l, $class;
diff --git a/usr.sbin/pkg_add/OpenBSD/PkgSpec.pm b/usr.sbin/pkg_add/OpenBSD/PkgSpec.pm
index 9f51cfa3314..45f24086f74 100644
--- a/usr.sbin/pkg_add/OpenBSD/PkgSpec.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PkgSpec.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: PkgSpec.pm,v 1.19 2009/03/07 12:07:37 espie Exp $
+# $OpenBSD: PkgSpec.pm,v 1.20 2009/04/19 14:58:32 espie Exp $
#
# Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org>
#
@@ -17,17 +17,16 @@
use strict;
use warnings;
-package OpenBSD::PkgSpec;
-use OpenBSD::PackageName;
-sub check_version
+package OpenBSD::PkgSpec::flavorspec;
+sub new
{
- my ($v, $constraint_list) = @_;
+ my ($class, $spec) = @_;
+
+ $spec =~ s/^-//o;
+
+ bless \$spec, $class;
- for my $c (@$constraint_list) {
- return 0 if $c->match($v) == 0;
- }
- return 1;
}
sub check_1flavor
@@ -46,32 +45,113 @@ sub check_1flavor
return 1;
}
-sub check_flavor
+sub match
{
- my ($h, $spec) = @_;
- # no flavor constraints
- return 1 if $spec eq '';
-
- $spec =~ s/^-//o;
+ my ($self, $h) = @_;
# check each flavor constraint
- for my $_ (split /\,/o, $spec) {
- if (check_1flavor($h, $_)) {
+ for my $_ (split /\,/o, $$self) {
+ if (check_1flavor($h->{flavors}, $_)) {
return 1;
}
}
return 0;
}
-sub subpattern_match
+package OpenBSD::PkgSpec::exactflavor;
+our @ISA = qw(OpenBSD::PkgSpec::flavorspec);
+sub match
{
- my ($p, $list) = @_;
+ my ($self, $h) = @_;
+ if ($$self eq $h->flavor_string) {
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+package OpenBSD::PkgSpec::versionspec;
+sub new
+{
+ my ($class, $s) = @_;
+ my $spec = OpenBSD::PackageName::versionspec->from_string($s);
+ bless \$spec, $class;
+}
+
+sub match
+{
+ my ($self, $name) = @_;
+
+ return $$self->match($name->{version});
+}
+
+
+package OpenBSD::PkgSpec::SubPattern;
+use OpenBSD::PackageName;
+
+my $exception = {
+ "db-3.*" => "db->=3,<4",
+ "db-4.*" => "db->=4,<5",
+ "db-java-4.*" => "db-java->=4,<5",
+ "emacs-21.*" => "emacs->=21,<22",
+ "emacs-21.4*" => "emacs->=21.4,<21.5",
+ "emacs-22.2*" => "emacs->=22.2,<22.3",
+ "enlightenment-0.16*" => "enlightenment->=0.16,<0.17",
+ "gimp-2.*" => "gimp->=2,<3",
+ "gnupg->=1.4.*" => "gnupg->=1.4",
+ "gstreamer-0.10.*" => "gstreamer->=0.10,<0.11",
+ "gtksourceview-2.*" => "gtksourceview->=2,<3",
+ "hydra-5.4*" => "hydra->=5.4,<5.5",
+ "jdk->=1.5.0.*" => "jdk->=1.5.0",
+ "jdk->=1.6.0.*" => "jdk->=1.6.0",
+ "jre->=1.5.0.*" => "jre->=1.5.0",
+ "libggi->=0.9*" => "libggi->=0.9",
+ "libnet-1.0*" => "libnet->=1.0,<1.1",
+ "libnet-1.0.*" => "libnet->=1.0,<1.1",
+ "libnet-1.1*" => "libnet->=1.1,<1.2",
+ "libsigc++-1.*" => "libsigc++->=1,<2",
+ "libsigc++-2.*" => "libsigc++->=2,<3",
+ "mysql-client-5.0.*" => "mysql-client->=5.0,<5.1",
+ "ocaml-3.09.3*" => "ocaml->=3.09.3,<3.09.4",
+ "openldap-client-2.*" => "openldap-client->=2,<3",
+ "pgp-5.*" => "pgp->=5,<6",
+ "postgresql-client-8.3.*" => "postgresql-client->=8.3,<8.4",
+ "python-2.4*" => "python->=2.4,<2.5",
+ "python-2.4.*" => "python->=2.4,<2.5",
+ "python-2.5*" => "python->=2.5,<2.6",
+ "python-2.5.*" => "python->=2.5,<2.6",
+ "python-2.6.*" => "python->=2.6,<2.7",
+ "python-bsddb-2.5*" => "python-bsddb->=2.5,<2.6",
+ "python-tkinter-2.4*" => "python-tkinter->=2.4,<2.5",
+ "python-tkinter-2.5*" => "python-tkinter->=2.5,<2.6",
+ "rrdtool-1.2.*" => "rrdtool->=1.2,<1.3",
+ "swt-3.2.2*" => "swt->=3.2.2,<3.2.3",
+ "swt-browser-3.2.2*" => "swt-browser->=3.2.2,<3.2.3",
+ "tcl-8.4.*" => "tcl->=8.4,<8.5",
+ "tcl-8.5.*" => "tcl->=8.5,<8.6",
+ "tk-8.4*" => "tk->=8.4,<8.5",
+ "tk-8.4.*" => "tk->=8.4,<8.5",
+ "tk-8.5*" => "tk->=8.5,<8.6",
+ "tomcat-4.*" => "tomcat->=4,<5",
+ "tomcat-5.*" => "tomcat->=5,<6",
+ "tomcat-6.*" => "tomcat->=6,<7",
+ "tomcat-admin-4.*" => "tomcat-admin->=4,<5",
+ "tomcat-admin-5.*" => "tomcat-admin->=5,<6",
+ "xmms-1.2.11*" => "xmms->=1.2.11,<1.2.12"
+};
+
+sub parse
+{
+ my ($class, $p) = @_;
+
+ if (defined $exception->{$p}) {
+ $p = $exception->{$p};
+ }
# let's try really hard to find the stem and the flavors
unless ($p =~ m/^(.*?)\-((?:(?:\>|\>\=|\<\=|\<|\=)?\d|\*)[^-]*)(.*)$/) {
die "Invalid spec $p";
}
-
my ($stemspec, $vspec, $flavorspec) = ($1, $2, $3);
$stemspec =~ s/\./\\\./go;
@@ -79,33 +159,143 @@ sub subpattern_match
$stemspec =~ s/\*/\.\*/go;
$stemspec =~ s/\?/\./go;
$stemspec =~ s/^(\\\.libs)\-/$1\\d*\-/go;
+ return ($stemspec, $vspec, $flavorspec);
+}
- # First trim down the list
- my @l = grep {/^$stemspec-.*$/} @$list;
+sub add_version_constraints
+{
+ my ($class, $constraints, $vspec) = @_;
# turn the vspec into a list of constraints.
- my @constraints = ();
if ($vspec eq '*') {
# non constraint
} else {
for my $c (split /\,/, $vspec) {
- push(@constraints,
- OpenBSD::PackageName::versionspec->from_string($c));
+ push(@$constraints,
+ OpenBSD::PkgSpec::versionspec->new($c));
}
}
+}
+
+sub add_flavor_constraints
+{
+ my ($class, $constraints, $flavorspec) = @_;
+ # and likewise for flavors
+ if ($flavorspec eq '') {
+ # non constraint
+ } else {
+ push(@$constraints,
+ OpenBSD::PkgSpec::flavorspec->new($flavorspec));
+ }
+}
+sub new
+{
+ my ($class, $p) = @_;
+
+ my ($stemspec, $vspec, $flavorspec) = $class->parse($p);
+ my $constraints = [];
+ $class->add_version_constraints($constraints, $vspec);
+ $class->add_flavor_constraints($constraints, $flavorspec);
+
+ bless {
+ exactstem => qr{^$stemspec$},
+ fuzzystem => qr{^$stemspec-.*$},
+ constraints => $constraints,
+ }, $class;
+}
+
+sub match_ref
+{
+ my ($o, $list) = @_;
+ my @l = grep($o->{fuzzystem}, @$list);
my @result = ();
# Now, have to extract the version number, and the flavor...
+LOOP1:
for my $s (@l) {
my $name = OpenBSD::PackageName->from_string($s);
- if ($name->{stem} =~ m/^$stemspec$/ &&
- check_flavor($name->{flavors}, $flavorspec) &&
- check_version($name->{version}, \@constraints)) {
- push(@result, $s);
- }
+ next unless $name->{stem} =~ m/^$o->{exactstem}$/;
+ for my $c (@{$o->{constraints}}) {
+ next LOOP1 unless $c->match($name);
+ }
+ push(@result, $s);
}
return @result;
}
+sub match_locations
+{
+ my ($o, $list) = @_;
+ my @l = grep { $_->name =~ m/$o->{fuzzystem}/} @$list;
+ my $result = [];
+ # Now, have to extract the version number, and the flavor...
+LOOP2:
+ for my $s (@l) {
+ my $name = $s->pkgname;
+ next unless $name->{stem} =~ m/^$o->{exactstem}$/;
+ for my $c (@{$o->{constraints}}) {
+ next LOOP2 unless $c->match($name);
+ }
+ push(@$result, $s);
+ }
+
+ return $result;
+}
+
+package OpenBSD::PkgSpec;
+sub subpattern_class
+{ "OpenBSD::PkgSpec::SubPattern" }
+sub new
+{
+ my ($class, $pattern) = @_;
+ my @l = map { $class->subpattern_class->new($_) }
+ (split /\|/o, $pattern);
+ bless \@l, $class;
+}
+
+sub match_ref
+{
+ my ($self, $r) = @_;
+ my @l = ();
+ for my $subpattern (@$self) {
+ push(@l, $subpattern->match_ref($r));
+ }
+ return @l;
+}
+
+sub match_locations
+{
+ my ($self, $r) = @_;
+ my $l = [];
+ for my $subpattern (@$self) {
+ push(@$l, @{$subpattern->match_locations($r)});
+ }
+ return $l;
+}
+
+package OpenBSD::PkgSpec::SubPattern::Exact;
+our @ISA = qw(OpenBSD::PkgSpec::SubPattern);
+
+sub add_version_constraints
+{
+ my ($class, $constraints, $vspec) = @_;
+ my $v = OpenBSD::PkgSpec::versionspec->new($vspec);
+ die "not a good exact spec" if $$v->{op} ne '=';
+ $$v->{pnum} = -1;
+ push(@$constraints, $v);
+}
+
+sub add_flavor_constraints
+{
+ my ($class, $constraints, $flavorspec) = @_;
+ push(@$constraints, OpenBSD::PkgSpec::exactflavor->new($flavorspec));
+}
+
+package OpenBSD::PkgSpec::Exact;
+our @ISA = qw(OpenBSD::PkgSpec);
+
+sub subpattern_class
+{ "OpenBSD::PkgSpec::SubPattern::Exact" }
+
1;
diff --git a/usr.sbin/pkg_add/OpenBSD/Replace.pm b/usr.sbin/pkg_add/OpenBSD/Replace.pm
index 7c676b9b198..4226c739210 100644
--- a/usr.sbin/pkg_add/OpenBSD/Replace.pm
+++ b/usr.sbin/pkg_add/OpenBSD/Replace.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: Replace.pm,v 1.48 2009/03/05 10:44:59 espie Exp $
+# $OpenBSD: Replace.pm,v 1.49 2009/04/19 14:58:32 espie Exp $
#
# Copyright (c) 2004-2006 Marc Espie <espie@openbsd.org>
#
@@ -103,7 +103,7 @@ sub extract
$self->SUPER::extract($state);
# figure out a safe directory where to put the temp file
- my $d = dirname($file->{destdir}.$file->{name});
+ my $d = dirname($file->{destdir}.$file->name);
# we go back up until we find an existing directory.
# hopefully this will be on the same file system.
while (!-d $d && -e _ || defined $state->{noshadow}->{$d}) {
@@ -123,7 +123,7 @@ sub extract
# XXX don't apply destdir twice
$file->{destdir} = '';
- $file->{name} = $tempname;
+ $file->set_name($tempname);
$file->create;
$self->may_check_digest($file, $state);
}
@@ -158,7 +158,7 @@ package OpenBSD::PackingElement::ScriptFile;
sub update_issue
{
my ($self, $installing) = @_;
- return $self->{name}." script";
+ return $self->name." script";
}
package OpenBSD::PackingElement::FINSTALL;
diff --git a/usr.sbin/pkg_add/OpenBSD/Search.pm b/usr.sbin/pkg_add/OpenBSD/Search.pm
index 63f86be40f6..3a5137911d6 100644
--- a/usr.sbin/pkg_add/OpenBSD/Search.pm
+++ b/usr.sbin/pkg_add/OpenBSD/Search.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: Search.pm,v 1.8 2007/12/28 12:55:03 espie Exp $
+# $OpenBSD: Search.pm,v 1.9 2009/04/19 14:58:32 espie Exp $
#
# Copyright (c) 2007 Marc Espie <espie@openbsd.org>
#
@@ -20,21 +20,22 @@ sub match_locations
{
my ($self, $o) = @_;
require OpenBSD::PackageLocation;
-
- return map {OpenBSD::PackageLocation->new($o, $_)} $self->match($o);
+
+ my @l = map {OpenBSD::PackageLocation->new($o, $_)} $self->match($o);
+ return \@l;
}
# XXX this is not efficient
sub filter_locations
{
- my $self = shift;
- my @r = ();
- while (my $loc = shift @_) {
+ my ($self, $l) = @_;
+ my $r = [];
+ for my $loc (@$l) {
if ($self->filter($loc->{name})) {
- push(@r, $loc);
+ push(@$r, $loc);
}
}
- return @r;
+ return $r;
}
package OpenBSD::Search::PkgSpec;
@@ -43,13 +44,7 @@ our @ISA=(qw(OpenBSD::Search));
sub match_ref
{
my ($self, $r) = @_;
- my @l = ();
-
- for my $subpattern (@{$self->{patterns}}) {
- require OpenBSD::PkgSpec;
- push(@l, OpenBSD::PkgSpec::subpattern_match($subpattern, $r));
- }
- return @l;
+ return $self->{spec}->match_ref($r);
}
sub match
@@ -58,6 +53,18 @@ sub match
return $self->match_ref($o->list);
}
+sub match_locations
+{
+ my ($self, $o) = @_;
+ return $self->{spec}->match_locations($o->locations_list);
+}
+
+sub filter_locations
+{
+ my ($self, $l) = @_;
+ return $self->{$spec}->match_locations($l);
+}
+
sub filter
{
my ($self, @list) = @_;
@@ -67,8 +74,9 @@ sub filter
sub new
{
my ($class, $pattern) = @_;
- my @l = split /\|/o, $pattern;
- bless { patterns => \@l }, $class;
+ require OpenBSD::PkgSpec;
+
+ bless { spec => $class->spec_class->new($pattern)}, $class;
}
sub add_pkgpath_hint
@@ -77,43 +85,13 @@ sub add_pkgpath_hint
$self->{pkgpath} = $pkgpath;
}
+sub spec_class
+{ "OpenBSD::PkgSpec" }
+
package OpenBSD::Search::Exact;
our @ISA=(qw(OpenBSD::Search::PkgSpec));
-sub match_ref
-{
- my ($self, $r) = @_;
- my @l = ();
-
- for my $subpattern (@{$self->{patterns}}) {
- if ($subpattern !~ m/^(.*?)\-(\d[^-]*)(.*)$/o) {
- next;
- }
- my ($stem, $version, $flavor) = ($1, $2, $3);
- $version =~ s/p\d+//;
- for my $pkg (@$r) {
- if ($pkg eq $subpattern) {
- push(@l, $pkg);
- next;
- }
- if ($pkg !~ m/^(.*?)\-(\d[^-]*)(.*)$/o) {
- next;
- }
- if ($1 ne $stem) {
- next;
- }
- if ($3 ne $flavor) {
- next;
- }
- my $pkgversion = $2;
- $pkgversion =~ s/p\d+//;
- if ($pkgversion ne $version) {
- next;
- }
- push(@l, $pkg);
- }
- }
- return @l;
-}
+sub spec_class
+{ "OpenBSD::PkgSpec::Exact" }
package OpenBSD::Search::Stem;
our @ISA=(qw(OpenBSD::Search));
@@ -190,14 +168,6 @@ sub filter
return &{$self->{code}}(@l);
}
-sub keep_most_recent
-{
- my $class = shift;
- require OpenBSD::PackageName;
-
- return $class->new(\&OpenBSD::PackageName::keep_most_recent);
-}
-
package OpenBSD::Search::FilterLocation;
our @ISA=(qw(OpenBSD::Search));
sub new
@@ -209,8 +179,53 @@ sub new
sub filter_locations
{
- my ($self, @l) = @_;
- return &{$self->{code}}(@l);
+ my ($self, $l) = @_;
+ return &{$self->{code}}($l);
+}
+
+sub keep_most_recent
+{
+ my $class = shift;
+ return $class->new(
+sub {
+ my $l = shift;
+ # no need to filter
+ return $l if @$l <= 1;
+
+ require OpenBSD::PackageName;
+ my $h = {};
+ # we have to prove we have to keep it
+ while (my $e = pop @$l) {
+ my $stem = $e->pkgname->{stem};
+ my $keep = 1;
+ # so let's compare with every element in $h with the same stem
+ for my $f (@{$h->{$e->pkgname->{stem}}}) {
+ # if this is not the same flavors,
+ # we don't filter
+ if ($f->pkgname->flavor_string ne $e->pkgname->flavor_string) {
+ next;
+ }
+ # okay, now we need to prove there's a common pkgpath
+ if (!$e->update_info->match_pkgpath($f->update_info)) {
+ next;
+ }
+
+ if ($f->pkgname->{version}->compare($e->pkgname->{version}) < 0) {
+ $f = $e;
+ }
+ $keep = 0;
+ last;
+
+ }
+ if ($keep) {
+ push(@{$h->{$e->pkgname->{stem}}}, $e);
+ }
+ }
+ my $largest = [];
+ push @$largest, map {@$_} values %$h;
+ return $largest;
+}
+ );
}
1;
diff --git a/usr.sbin/pkg_add/OpenBSD/Temp.pm b/usr.sbin/pkg_add/OpenBSD/Temp.pm
index b8b17d46aeb..3c33c5104e0 100644
--- a/usr.sbin/pkg_add/OpenBSD/Temp.pm
+++ b/usr.sbin/pkg_add/OpenBSD/Temp.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: Temp.pm,v 1.13 2007/06/16 09:29:37 espie Exp $
+# $OpenBSD: Temp.pm,v 1.14 2009/04/19 14:58:32 espie Exp $
#
# Copyright (c) 2003-2005 Marc Espie <espie@openbsd.org>
#
@@ -69,7 +69,7 @@ $SIG{'HUP'} = $handler;
$SIG{'KILL'} = $handler;
$SIG{'TERM'} = $handler;
-sub dir()
+sub dir
{
my $caught;
my $h = sub { $caught = shift; };
@@ -90,7 +90,7 @@ sub dir()
return "$dir/";
}
-sub file()
+sub file
{
my $caught;
my $h = sub { $caught = shift; };
diff --git a/usr.sbin/pkg_add/OpenBSD/Update.pm b/usr.sbin/pkg_add/OpenBSD/Update.pm
index f91723474b3..7d2be570e6c 100644
--- a/usr.sbin/pkg_add/OpenBSD/Update.pm
+++ b/usr.sbin/pkg_add/OpenBSD/Update.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: Update.pm,v 1.82 2008/03/08 12:07:45 espie Exp $
+# $OpenBSD: Update.pm,v 1.83 2009/04/19 14:58:32 espie Exp $
#
# Copyright (c) 2004-2006 Marc Espie <espie@openbsd.org>
#
@@ -64,34 +64,29 @@ sub process_package
}
my @search = ();
push(@search, OpenBSD::Search::Stem->split($pkgname));
- if (!$state->{defines}->{allversions}) {
- push(@search, OpenBSD::Search::Filter->keep_most_recent);
- }
-
my $found;
my $plist;
- push(@search, OpenBSD::Search::Filter->new(
+ push(@search, OpenBSD::Search::FilterLocation->new(
sub {
- my @l = @_;
- if (@l == 0) {
- return @l;
+ my $l = shift;
+ if (@$l == 0) {
+ return $l;
}
- if (@l == 1 && $state->{defines}->{pkgpath}) {
- return @l;
+ if (@$l == 1 && $state->{defines}->{pkgpath}) {
+ return $l;
}
my @l2 = ();
$plist = OpenBSD::PackingList->from_installation($pkgname, \&OpenBSD::PackingList::UpdateInfoOnly);
if (!defined $plist) {
Fatal("Can't locate $pkgname");
}
- for my $candidate (@l) {
- my $handle = OpenBSD::PackageLocator->find($candidate, $state->{arch});
+ for my $handle (@$l) {
+ $handle->set_arch($state->{arch});
if (!$handle) {
next;
}
- $handle->close_now;
- my $p2 = $handle->plist(\&OpenBSD::PackingList::UpdateInfoOnly);
+ my $p2 = $handle->update_info;
if (!$p2) {
next;
}
@@ -101,38 +96,35 @@ sub process_package
}
}
if ($plist->signature eq $p2->signature) {
- $found = $candidate;
- push(@l2, $candidate);
+ $found = $handle;
+ push(@l2, $handle);
next;
}
- if ($p2->{extrainfo}->{subdir} eq $plist->{extrainfo}->{subdir}) {
- push(@l2, $candidate);
- } elsif ($p2->has('pkgpath')) {
- for my $p (@{$p2->{pkgpath}}) {
- if ($p->{name} eq $plist->{extrainfo}->{subdir}) {
- push(@l2, $candidate);
- last;
- }
- }
+ if ($plist->match_pkgpath($p2)) {
+ push(@l2, $handle);
}
}
- return @l2;
+ return \@l2;
}));
+ if (!$state->{defines}->{allversions}) {
+ push(@search, OpenBSD::Search::FilterLocation->keep_most_recent);
+ }
+
- my @l = OpenBSD::PackageLocator->match(@search);
- if (@l == 0) {
+ my $l = OpenBSD::PackageLocator->match_locations(@search);
+ if (@$l == 0) {
$self->add2cant($pkgname);
return;
}
- if (@l == 1) {
+ if (@$l == 1) {
if ($state->{defines}->{pkgpath}) {
$state->progress->clear;
- print "Directly updating $pkgname -> ", $l[0], "\n";
- $self->add2updates($l[0]);
+ print "Directly updating $pkgname -> ", $l->[0]->name, "\n";
+ $self->add2updates($l->[0]->name);
return;
}
- if (defined $found && $found eq $l[0] &&
+ if (defined $found && $found eq $l->[0] &&
!$plist->uses_old_libs && !$state->{defines}->{installed}) {
my $msg = "No need to update $pkgname";
$state->progress->message($msg);
@@ -142,20 +134,21 @@ sub process_package
}
$state->progress->clear;
- print "Candidates for updating $pkgname -> ", join(' ', @l), "\n";
+ my %cnd = map {($_->name, $_)} @$l;
+ print "Candidates for updating $pkgname -> ", join(' ', keys %cnd), "\n";
- if (@l == 1) {
- $self->add2updates($l[0]);
+ if (@$l == 1) {
+ $self->add2updates($l->[0]);
return;
}
my $result = OpenBSD::Interactive::choose1($pkgname,
- $state->{interactive}, sort @l);
+ $state->{interactive}, sort keys %cnd);
if (defined $result) {
if (defined $found && $found eq $result &&
!$plist->uses_old_libs) {
print "No need to update $pkgname\n";
} else {
- $self->add2updates($result);
+ $self->add2updates($cnd{$result});
}
} else {
$state->{issues} = 1;
diff --git a/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm b/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm
index b30dd7917fc..db4c993c83c 100644
--- a/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm
+++ b/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: UpdateSet.pm,v 1.3 2008/03/08 12:07:45 espie Exp $
+# $OpenBSD: UpdateSet.pm,v 1.4 2009/04/19 14:58:32 espie Exp $
#
# Copyright (c) 2007 Marc Espie <espie@openbsd.org>
#
@@ -154,7 +154,7 @@ sub from_location
{
my ($class, $location) = @_;
my $handle = $class->new;
- $handle->{pkgname} = $location->{name};
+ $handle->{pkgname} = $location->name;
$handle->{location} = $location;
$handle->{tweaked} = 0;
return $handle;
diff --git a/usr.sbin/pkg_add/OpenBSD/Ustar.pm b/usr.sbin/pkg_add/OpenBSD/Ustar.pm
index 172a3b5abc1..a92bec84004 100644
--- a/usr.sbin/pkg_add/OpenBSD/Ustar.pm
+++ b/usr.sbin/pkg_add/OpenBSD/Ustar.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: Ustar.pm,v 1.50 2007/06/16 09:29:37 espie Exp $
+# $OpenBSD: Ustar.pm,v 1.51 2009/04/19 14:58:32 espie Exp $
#
# Copyright (c) 2002-2007 Marc Espie <espie@openbsd.org>
#
@@ -188,7 +188,7 @@ sub split_name
sub mkheader
{
my ($entry, $type) = @_;
- my ($prefix, $name) = split_name($entry->{name});
+ my ($prefix, $name) = split_name($entry->name);
my $linkname = $entry->{linkname};
my $size = $entry->{size};
if (!$entry->isFile) {
@@ -349,18 +349,30 @@ sub new
bless $object, $class;
}
+sub name
+{
+ my $self = shift;
+ return $self->{name};
+}
+
+sub set_name
+{
+ my ($self, $v) = @_;
+ $self->{name} = $v;
+}
+
sub set_modes
{
my $self = shift;
- chown $self->{uid}, $self->{gid}, $self->{destdir}.$self->{name};
- chmod $self->{mode}, $self->{destdir}.$self->{name};
- utime $self->{mtime}, $self->{mtime}, $self->{destdir}.$self->{name};
+ chown $self->{uid}, $self->{gid}, $self->{destdir}.$self->name;
+ chmod $self->{mode}, $self->{destdir}.$self->name;
+ utime $self->{mtime}, $self->{mtime}, $self->{destdir}.$self->name;
}
sub make_basedir
{
my $self = shift;
- my $dir = $self->{destdir}.File::Basename::dirname($self->{name});
+ my $dir = $self->{destdir}.File::Basename::dirname($self->name);
File::Path::mkpath($dir) unless -d $dir;
}
@@ -376,7 +388,7 @@ sub write
$self->write_contents($arc);
my $k = $self->{key};
if (!defined $arc->{key}->{$k}) {
- $arc->{key}->{$k} = $self->{name};
+ $arc->{key}->{$k} = $self->name;
}
}
@@ -431,7 +443,7 @@ our @ISA=qw(OpenBSD::Ustar::Object);
sub create
{
my $self = shift;
- File::Path::mkpath($self->{destdir}.$self->{name});
+ File::Path::mkpath($self->{destdir}.$self->name);
$self->set_modes;
}
@@ -445,13 +457,14 @@ our @ISA=qw(OpenBSD::Ustar::Object);
sub create
{
my $self = shift;
- $self->make_basedir($self->{name});
+ $self->make_basedir($self->name);
my $linkname = $self->{linkname};
if (defined $self->{cwd}) {
$linkname=$self->{cwd}.'/'.$linkname;
}
- link $self->{destdir}.$linkname, $self->{destdir}.$self->{name} or
- die "Can't link $self->{destdir}$linkname to $self->{destdir}$self->{name}: $!";
+ link $self->{destdir}.$linkname, $self->{destdir}.$self->name or
+ die "Can't link $self->{destdir}$linkname to $self->{destdir}",
+ $self->name, ": $!";
}
sub resolve_links
@@ -478,9 +491,10 @@ our @ISA=qw(OpenBSD::Ustar::Object);
sub create
{
my $self = shift;
- $self->make_basedir($self->{name});
- symlink $self->{linkname}, $self->{destdir}.$self->{name} or
- die "Can't symlink $self->{linkname} to $self->{destdir}$self->{name}: $!";
+ $self->make_basedir($self->name);
+ symlink $self->{linkname}, $self->{destdir}.$self->name or
+ die "Can't symlink $self->{linkname} to $self->{destdir}",
+ $self->name, ": $!";
}
sub isLink() { 1 }
@@ -494,10 +508,10 @@ our @ISA=qw(OpenBSD::Ustar::Object);
sub create
{
my $self = shift;
- $self->make_basedir($self->{name});
+ $self->make_basedir($self->name);
require POSIX;
- POSIX::mkfifo($self->{destdir}.$self->{name}, $self->{mode}) or
- die "Can't create fifo $self->{name}: $!";
+ POSIX::mkfifo($self->{destdir}.$self->name, $self->{mode}) or
+ die "Can't create fifo ", $self->name,": $!";
$self->set_modes;
}
@@ -510,9 +524,9 @@ our @ISA=qw(OpenBSD::Ustar::Object);
sub create
{
my $self = shift;
- $self->make_basedir($self->{name});
+ $self->make_basedir($self->name);
system(OpenBSD::Paths->mknod,
- '-m', $self->{mode}, $self->{destdir}.$self->{name},
+ '-m', $self->{mode}, $self->{destdir}.$self->name,
$self->devicetype, $self->{major}, $self->{minor});
$self->set_modes;
}
@@ -615,11 +629,11 @@ sub new
sub create
{
my $self = shift;
- $self->make_basedir($self->{name});
+ $self->make_basedir($self->name);
my $buffer;
- my $out = OpenBSD::CompactWriter->new($self->{destdir}.$self->{name});
+ my $out = OpenBSD::CompactWriter->new($self->{destdir}.$self->name);
if (!defined $out) {
- die "Can't write to $self->{destdir}$self->{name}: $!";
+ die "Can't write to $self->{destdir}", $self->name, ": $!";
}
my $toread = $self->{size};
while ($toread > 0) {
@@ -634,12 +648,14 @@ sub create
}
$self->{archive}->{swallow} -= $actual;
unless ($out->write($buffer)) {
- die "Error writing to $self->{destdir}$self->{name}: $!";
+ die "Error writing to $self->{destdir}", $self->name,
+ ": $!";
}
$toread -= $actual;
}
- $out->close or die "Error closing $self->{destdir}$self->{name}: $!";
+ $out->close or die "Error closing $self->{destdir}", $self->name,
+ ": $!";
$self->set_modes;
}
@@ -720,7 +736,7 @@ sub copy_contents
print $out "\0" x (512 - $size % 512) or
die "Error writing to archive: $!";
}
- $self->alias($arc, $self->{name});
+ $self->alias($arc, $self->name);
}
sub isFile() { 1 }
diff --git a/usr.sbin/pkg_add/pkg b/usr.sbin/pkg_add/pkg
index 82e21372f91..97e7a07cd73 100644
--- a/usr.sbin/pkg_add/pkg
+++ b/usr.sbin/pkg_add/pkg
@@ -1,6 +1,6 @@
#! /usr/bin/perl
# ex:ts=8 sw=4:
-# $OpenBSD: pkg,v 1.9 2007/06/12 09:53:36 espie Exp $
+# $OpenBSD: pkg,v 1.10 2009/04/19 14:58:32 espie Exp $
#
# Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org>
#
@@ -25,9 +25,9 @@ sub check_dependencies($)
require OpenBSD::Search;
require OpenBSD::PackageRepository::Installed;
my $dependency = shift;
- my @m = OpenBSD::PackageRepository::Installed->new
- ->match(OpenBSD::Search::PkgSpec->new($dependency));
- return (@m != 0) ? 1 : 0;
+ my $m = OpenBSD::PackageRepository::Installed->new
+ ->match_locations(OpenBSD::Search::PkgSpec->new($dependency));
+ return (@$m != 0) ? 1 : 0;
}
# Pass this off to the old package commands
diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add
index 3ba6eb89295..6592b51353e 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.333 2009/04/14 17:53:58 espie Exp $
+# $OpenBSD: pkg_add,v 1.334 2009/04/19 14:58:32 espie Exp $
#
# Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org>
#
@@ -230,20 +230,6 @@ sub can_install
package main;
-sub thunderbird_special_case
-{
- my $plist = shift;
- for my $item (@{$plist->{items}}) {
- next unless $item->IsFile;
- my $t = $item->{tempname};
- if (defined $t && $t =~ s/^(.*\/mozilla-thunderbird)\/extensions(.*)\/pkg\./$1\/pkg\./) {
- rename $item->{tempname}, $t;
- rmdir("$1/extensions$2");
- $item->{tempname} = $t;
- }
- }
-}
-
sub failed_message
{
my ($base_msg, $interrupted, @l) = @_;
@@ -362,10 +348,6 @@ sub really_add
my $oldname = $o->{pkgname};
$state->progress->set_header($oldname." (deleting)");
$state->set_name_from_handle($o);
- require OpenBSD::Search;
- if (OpenBSD::Search::PkgSpec->new("mozilla-thunderbird-<=1.0.2p0")->filter($oldname)) {
- thunderbird_special_case($plist);
- }
require OpenBSD::Delete;
try {
OpenBSD::Delete::delete_plist($o->{plist}, $state);
@@ -504,10 +486,11 @@ sub install_set
}
-sub find_truenames
+sub find_truelocations
{
my ($old, $new, $state) = @_;
+ my $cache = {};
for my $pkgname (@$old) {
if (OpenBSD::PackageName::is_stem($pkgname)) {
my ($h, $path, $repo);
@@ -518,21 +501,30 @@ sub find_truenames
$h = 'OpenBSD::PackageLocator';
$path = "";
}
- my @l = $h->match(OpenBSD::Search::Stem->new($pkgname));
- if (@l > 1 && !$state->{defines}->{allversions}) {
- @l = OpenBSD::PackageName::keep_most_recent(@l);
+ my $l = $h->match_locations(OpenBSD::Search::Stem->new($pkgname));
+ if (@$l > 1 && !$state->{defines}->{allversions}) {
+ $l = OpenBSD::Search::FilterLocation->keep_most_recent->filter_locations($l);
}
- my $result = OpenBSD::Interactive::choose1($pkgname, $state->{interactive}, sort @l);
- if (defined $result) {
- if (defined $path) {
- $result = $path.$result;
- }
- push(@$new, $result);
+ if (@$l == 0) {
+ print "Can't resolve $pkgname\n";
+ $bad = 1;
+ } elsif (@$l > 1) {
+ my %h = map {($_->name, $_)} @$l;
+ $h{'<None>'} = undef;
+ my $result = OpenBSD::Interactive::ask_list("Ambiguous choose package for $pkgname", $state->{interactive}, sort keys %h);
+ if (defined $h{$result}) {
+ push(@$new, OpenBSD::UpdateSet->from_location($h{$result}));
+ } else {
+ $bad = 1;
+ }
} else {
- $bad = 1;
+ push(@$new, OpenBSD::UpdateSet->from_location($l->[0]));
}
} else {
- push(@$new, $pkgname);
+ if (!defined $cache->{$pkgname}) {
+ $cache->{$pkgname} = OpenBSD::UpdateSet->create_new($pkgname);
+ }
+ push(@$new, $cache->{$pkgname});
}
}
}
@@ -641,6 +633,7 @@ $state->check_root;
my @todo = ();
+my @todo2 = ();
if ($opt_u) {
require OpenBSD::Update;
@@ -672,18 +665,19 @@ if ($opt_u) {
@todo = @{$updater->updates};
if (@todo > 0 && !$bad) {
print "Running the equivalent of pkg_add -r ",
- join(' ', @todo), "\n";
+ join(' ', (map {$_->name} @todo)), "\n";
}
+ @todo2 = map { OpenBSD::UpdateSet->from_location($_) } @todo;
} else {
- find_truenames(\@ARGV, \@todo, $state);
- OpenBSD::Add::tag_user_packages(@todo);
- if (defined $state->{defines}->{kitchensink}) {
- reorder(\@todo);
- if (!$opt_r) {
- @todo = grep {s/\.tgz$//o; !is_installed($_);} @todo;
- }
- print "Adding in order:\n", (map { "\t$_\n" } @todo), "\n";
- }
+ find_truelocations(\@ARGV, \@todo2, $state);
+# OpenBSD::Add::tag_user_packages(@todo);
+# if (defined $state->{defines}->{kitchensink}) {
+# reorder(\@todo);
+# if (!$opt_r) {
+# @todo = grep {s/\.tgz$//o; !is_installed($_);} @todo;
+# }
+# print "Adding in order:\n", (map { "\t$_\n" } @todo), "\n";
+# }
}
if ($bad) {
@@ -692,14 +686,6 @@ if ($bad) {
# convert everything to UpdateSets
-my @todo2 = ();
-my $cache = {};
-for my $pkg (@todo) {
- if (!defined $cache->{$pkg}) {
- $cache->{$pkg} = OpenBSD::UpdateSet->create_new($pkg);
- }
- push(@todo2, $cache->{$pkg});
-}
eval {
while (my $set = shift @todo2) {
@@ -777,7 +763,7 @@ sub get_plist
print $state->deptree_header($pkg);
print "parsing $pkg\n";
}
- my $plist = $location->plist;
+ my $plist = $location->grabPlist;
unless (defined $plist) {
print "Can't find CONTENTS from ", $location->url, "\n";
$location->close_with_client_error;
diff --git a/usr.sbin/pkg_add/pkg_audit b/usr.sbin/pkg_add/pkg_audit
index 688ac550e9f..8a60972c5e9 100644
--- a/usr.sbin/pkg_add/pkg_audit
+++ b/usr.sbin/pkg_add/pkg_audit
@@ -1,6 +1,6 @@
#! /usr/bin/perl
# ex:ts=8 sw=4:
-# $OpenBSD: pkg_audit,v 1.5 2008/08/14 13:06:04 espie Exp $
+# $OpenBSD: pkg_audit,v 1.6 2009/04/19 14:58:32 espie Exp $
#
# Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org>
#
@@ -37,7 +37,7 @@ for my $pkg (installed_packages()) {
print "\nFiles not accounted for by any package: \n";
find(sub {
- return unless -f $_;
+ return unless -l $_ || -f _;
if ($found{$File::Find::name}) {
delete $found{$File::Find::name};
} else {
@@ -48,6 +48,7 @@ find(sub {
print "\nStuff that should be there, but isn't:\n";
my %packages;
for my $item (keys %found) {
+ next unless $item =~ m|^/usr/local|;
push(@{$packages{$found{$item}}}, $item);
}
for my $pkg (keys %packages) {
diff --git a/usr.sbin/pkg_add/pkg_create b/usr.sbin/pkg_add/pkg_create
index 409309ec8fe..2d105dc2604 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.120 2009/04/14 17:53:58 espie Exp $
+# $OpenBSD: pkg_create,v 1.121 2009/04/19 14:58:32 espie Exp $
#
# Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org>
#
@@ -112,7 +112,7 @@ sub makesum_plist_with_base
sub verify_checksum_with_base
{
my ($self, $base, $stash) = @_;
- my $check = ref($self)->new($self->{name});
+ my $check = ref($self)->new($self->name);
$self->compute_checksum($check, $base, $stash);
for my $field (qw(symlink link size)) { # md5
@@ -162,7 +162,7 @@ sub pretend_to_archive
sub comment_create_package
{
my ($self) = @_;
- print "Adding ", $self->{name}, "\n";
+ print "Adding ", $self->name, "\n";
}
sub makesum_plist
@@ -213,20 +213,20 @@ package OpenBSD::PackingElement::Cwd;
sub archive
{
my ($self, $arc, $base) = @_;
- $arc->destdir($base."/".$self->{name});
+ $arc->destdir($base."/".$self->name);
}
sub pretend_to_archive
{
my ($self, $arc, $base) = @_;
- $arc->destdir($base."/".$self->{name});
+ $arc->destdir($base."/".$self->name);
$self->comment_create_package;
}
sub comment_create_package
{
my ($self) = @_;
- print "Cwd: ", $self->{name}, "\n";
+ print "Cwd: ", $self->name, "\n";
}
package OpenBSD::PackingElement::FileBase;
@@ -251,7 +251,7 @@ sub pretend_to_archive
sub comment_create_package
{
my ($self) = @_;
- print "Adding ", $self->{name}, "\n";
+ print "Adding ", $self->name, "\n";
}
sub print_file
@@ -290,7 +290,7 @@ sub makesum_plist
my $fname = $self->fullname;
for (my $i = 1; ; $i++) {
if (-e "$base/$fname-$i") {
- my $e = OpenBSD::PackingElement::File->add($plist, $self->{name}."-".$i);
+ my $e = OpenBSD::PackingElement::File->add($plist, $self->name."-".$i);
$e->compute_checksum($e, $base, $stash);
} else {
last;
@@ -592,7 +592,7 @@ if ($regen_package) {
}
print "Creating package $ARGV[0]\n" if !(defined $opt_q) && $opt_v;
if (!$opt_q) {
- $plist->set_infodir(OpenBSD::Temp::dir());
+ $plist->set_infodir(OpenBSD::Temp->dir);
}
add_description($plist, DESC, $opt_c, $opt_d);
add_special_file($plist, INSTALL, $opt_i);
diff --git a/usr.sbin/pkg_add/pkg_info b/usr.sbin/pkg_add/pkg_info
index 64d2720a210..04f3aba03ad 100644
--- a/usr.sbin/pkg_add/pkg_info
+++ b/usr.sbin/pkg_add/pkg_info
@@ -1,6 +1,6 @@
#! /usr/bin/perl
# ex:ts=8 sw=4:
-# $OpenBSD: pkg_info,v 1.72 2009/04/14 17:53:58 espie Exp $
+# $OpenBSD: pkg_info,v 1.73 2009/04/19 14:58:32 espie Exp $
#
# Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org>
#
@@ -72,11 +72,10 @@ sub find_pkg_in
if (OpenBSD::PackageName::is_stem($pkgname)) {
require OpenBSD::Search;
- my @l = sort ($repo->match(OpenBSD::Search::Stem->new($pkgname)));
- if (@l != 0) {
- for my $p (@l) {
- my $pkg = $repo->find($p);
- &$code($p, $pkg);
+ my $l = $repo->match_locations(OpenBSD::Search::Stem->new($pkgname));
+ if (@$l != 0) {
+ for my $pkg (sort {$a->name cmp $b->name} @$l) {
+ &$code($pkg->name, $pkg);
$pkg->close_now;
$pkg->wipe_info;
}
@@ -213,7 +212,7 @@ sub find_by_path
$plist->pkgname);
if ($plist->has('pkgpath')) {
for my $p (@{$plist->{pkgpath}}) {
- add_to_path_info($p->{name},
+ add_to_path_info($p->name,
$plist->pkgname);
}
}