summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2009-10-15 10:45:48 +0000
committerMarc Espie <espie@cvs.openbsd.org>2009-10-15 10:45:48 +0000
commit79c5d277257cd0dd954ca3aea4805f704391bea8 (patch)
tree383d07ad5e5ee1fdeb1d3d51fe4c83350ec86efa
parent071c67a432b2772d433712002c7698df9ff0087f (diff)
let handle compute pkgnames correctly, simplifies code a bit
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Dependencies.pm22
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Handle.pm45
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Replace.pm4
-rw-r--r--usr.sbin/pkg_add/OpenBSD/UpdateSet.pm8
-rw-r--r--usr.sbin/pkg_add/pkg_add31
5 files changed, 65 insertions, 45 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Dependencies.pm b/usr.sbin/pkg_add/OpenBSD/Dependencies.pm
index cbc509ce014..e697b06a6ae 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.71 2009/10/12 11:57:36 espie Exp $
+# $OpenBSD: Dependencies.pm,v 1.72 2009/10/15 10:45:47 espie Exp $
#
# Copyright (c) 2005-2007 Marc Espie <espie@openbsd.org>
#
@@ -227,10 +227,10 @@ sub add_todo
for my $set (@extra) {
for my $n ($set->newer) {
- $self->{to_install}->{OpenBSD::PackageName::url2pkgname($n->{pkgname})} = $set;
+ $self->{to_install}->{$n->pkgname} = $set;
}
for my $n ($set->older) {
- $self->{to_update}->{OpenBSD::PackageName::url2pkgname($n->{pkgname})} = $set;
+ $self->{to_update}->{$n->pkgname} = $set;
}
}
}
@@ -350,7 +350,7 @@ sub dump
print "Dependencies for ", $self->{set}->short_print,
" resolve to: ", join(', ', $self->dependencies);
print " (todo: ",
- join(',', (map {$_->handle->{pkgname}} @{$self->{deplist}})),
+ join(',', (map {$_->handle->pkgname} @{$self->{deplist}})),
")"
if @{$self->{deplist}} > 0;
print "\n";
@@ -362,7 +362,7 @@ sub register_dependencies
my ($self, $state) = @_;
require OpenBSD::RequiredBy;
- my $pkgname = $self->{set}->handle->{pkgname};
+ my $pkgname = $self->{set}->handle->pkgname;
my @l = $self->dependencies;
OpenBSD::Requiring->new($pkgname)->add(@l);
@@ -378,7 +378,7 @@ sub record_old_dependencies
my ($self, $state) = @_;
for my $o ($self->{set}->older_to_do) {
require OpenBSD::RequiredBy;
- my @wantlist = OpenBSD::RequiredBy->new($o->{pkgname})->list;
+ my @wantlist = OpenBSD::RequiredBy->new($o->pkgname)->list;
$o->{wantlist} = \@wantlist;
}
}
@@ -386,13 +386,13 @@ sub record_old_dependencies
sub adjust_old_dependencies
{
my ($self, $state) = @_;
- my $pkgname = $self->{set}->handle->{pkgname};
+ my $pkgname = $self->{set}->handle->pkgname;
for my $o ($self->{set}->older) {
next unless defined $o->{wantlist};
require OpenBSD::Replace;
require OpenBSD::RequiredBy;
- my $oldname = $o->{pkgname};
+ my $oldname = $o->pkgname;
print "Adjusting dependencies for $pkgname/$oldname\n"
if $state->{beverbose};
@@ -412,7 +412,7 @@ sub adjust_old_dependencies
sub repair_dependencies
{
my ($self, $state) = @_;
- my $pkgname = $self->{set}->handle->{pkgname};
+ my $pkgname = $self->{set}->handle->pkgname;
for my $pkg (installed_packages(1)) {
my $plist = OpenBSD::PackingList->from_installation($pkg,
\&OpenBSD::PackingList::DependOnly);
@@ -462,7 +462,7 @@ sub solve_wantlibs
next if $lib_finder->lookup($solver, $state,
$lib->{name});
OpenBSD::Error::Warn "Can't install ",
- $h->{pkgname}, ": lib not found ",
+ $h->pkgname, ": lib not found ",
$lib->{name}, "\n";
if ($okay) {
$solver->dump;
@@ -486,7 +486,7 @@ sub solve_tags
for my $tag (keys %{$h->{plist}->{tags}}) {
next if $tag_finder->lookup($solver, $state, $tag);
OpenBSD::Error::Warn "Can't install ",
- $h->{pkgname}, ": tag definition not found ",
+ $h->pkgname, ": tag definition not found ",
$tag, "\n";
if ($okay) {
$solver->dump;
diff --git a/usr.sbin/pkg_add/OpenBSD/Handle.pm b/usr.sbin/pkg_add/OpenBSD/Handle.pm
index 15701fee4bd..d45ae27c10c 100644
--- a/usr.sbin/pkg_add/OpenBSD/Handle.pm
+++ b/usr.sbin/pkg_add/OpenBSD/Handle.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: Handle.pm,v 1.1 2009/10/14 22:59:34 espie Exp $
+# $OpenBSD: Handle.pm,v 1.2 2009/10/15 10:45:47 espie Exp $
#
# Copyright (c) 2007-2009 Marc Espie <espie@openbsd.org>
#
@@ -35,6 +35,25 @@ sub new
return bless {}, $class;
}
+sub pkgname
+{
+ my $self = shift;
+ if (!defined $self->{pkgname}) {
+ if (defined $self->{plist}) {
+ $self->{pkgname} = $self->{plist}->pkgname;
+ } elsif (defined $self->{location}) {
+ $self->{pkgname} = $self->{location}->name;
+ } elsif (defined $self->{name}) {
+ require OpenBSD::PackageName;
+
+ $self->{pkgname} =
+ OpenBSD::PackageName::url2pkgname($self->{name});
+ }
+ }
+
+ return $self->{pkgname};
+}
+
sub set_error
{
my ($self, $error) = @_;
@@ -58,7 +77,7 @@ sub create_old
my ($class, $pkgname, $state) = @_;
my $self= $class->new;
- $self->{pkgname} = $pkgname;
+ $self->{name} = $pkgname;
require OpenBSD::PackageRepository::Installed;
@@ -74,6 +93,7 @@ sub create_old
$self->{plist} = $plist;
}
}
+
return $self;
}
@@ -81,7 +101,7 @@ sub create_new
{
my ($class, $pkg) = @_;
my $handle = $class->new;
- $handle->{pkgname} = $pkg;
+ $handle->{name} = $pkg;
$handle->{tweaked} = 0;
return $handle;
}
@@ -90,7 +110,6 @@ sub from_location
{
my ($class, $location) = @_;
my $handle = $class->new;
- $handle->{pkgname} = $location->name;
$handle->{location} = $location;
$handle->{tweaked} = 0;
return $handle;
@@ -101,7 +120,7 @@ sub get_plist
my ($handle, $state) = @_;
my $location = $handle->{location};
- my $pkg = $handle->{pkgname};
+ my $pkg = $handle->pkgname;
if ($state->{verbose}) {
print $state->deptree_header($pkg);
@@ -140,8 +159,7 @@ sub get_plist
return;
}
if ($pkg ne '-') {
- if (!defined $pkgname or
- OpenBSD::PackageName::url2pkgname($pkg) ne $pkgname) {
+ if (!defined $pkgname or $pkg ne $pkgname) {
print "Package name is not consistent ???\n";
$location->close_with_client_error;
$location->wipe_info;
@@ -158,26 +176,29 @@ sub complete
return if $handle->has_error;
- my $pkgname = $handle->{pkgname};
if (!defined $handle->{location}) {
- my $location = OpenBSD::PackageLocator->find($pkgname,
+ my $name = $handle->{name};
+
+ my $location = OpenBSD::PackageLocator->find($name,
$state->{arch});
if (!$location) {
- print $state->deptree_header($pkgname);
+ print $state->deptree_header($name);
$handle->set_error(NOT_FOUND);
$handle->{tweaked} =
- OpenBSD::Add::tweak_package_status($pkgname,
+ OpenBSD::Add::tweak_package_status($handle->pkgname,
$state);
if (!$handle->{tweaked}) {
- print "Can't find $pkgname\n";
+ print "Can't find $name\n";
}
return;
}
$handle->{location} = $location;
+ $handle->{pkgname} = $location->name;
}
if (!defined $handle->{plist}) {
$handle->get_plist($state);
}
}
+
1;
diff --git a/usr.sbin/pkg_add/OpenBSD/Replace.pm b/usr.sbin/pkg_add/OpenBSD/Replace.pm
index 1fd88125925..8b65a2d344e 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.50 2009/10/11 11:51:22 espie Exp $
+# $OpenBSD: Replace.pm,v 1.51 2009/10/15 10:45:47 espie Exp $
#
# Copyright (c) 2004-2006 Marc Espie <espie@openbsd.org>
#
@@ -432,7 +432,7 @@ sub save_old_libraries
for my $o ($set->older) {
- my $oldname = $o->{pkgname};
+ my $oldname = $o->pkgname;
my $libs = {};
my $p = {};
diff --git a/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm b/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm
index 432eebe79ee..ce651f2e8ac 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.8 2009/10/14 22:59:34 espie Exp $
+# $OpenBSD: UpdateSet.pm,v 1.9 2009/10/15 10:45:47 espie Exp $
#
# Copyright (c) 2007 Marc Espie <espie@openbsd.org>
#
@@ -131,7 +131,7 @@ sub add_older
{
my $self = shift;
for my $h (@_) {
- $self->{older}->{$h->{pkgname}} = $h;
+ $self->{older}->{$h->pkgname} = $h;
}
return $self;
}
@@ -157,7 +157,7 @@ sub older_names
sub newer_names
{
my $self =shift;
- return map {$_->{pkgname}} $self->newer;
+ return map {$_->pkgname} $self->newer;
}
sub older_to_do
@@ -169,7 +169,7 @@ sub older_to_do
require OpenBSD::PackageInfo;
my @l = ();
for my $h ($self->older) {
- if (OpenBSD::PackageInfo::is_installed($h->{pkgname})) {
+ if (OpenBSD::PackageInfo::is_installed($h->pkgname)) {
push(@l, $h);
}
}
diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add
index 8c5be5f4c69..4fa3825e749 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.352 2009/10/14 22:59:34 espie Exp $
+# $OpenBSD: pkg_add,v 1.353 2009/10/15 10:45:47 espie Exp $
#
# Copyright (c) 2003-2009 Marc Espie <espie@openbsd.org>
#
@@ -74,13 +74,12 @@ sub build_deptree
my ($state, $pkg, @deps) = @_;
my $tree = $state->{deptree};
- $pkg = OpenBSD::PackageName::url2pkgname($pkg);
# flatten info
if (defined $tree->{$pkg}) {
$pkg = $tree->{$pkg};
}
for my $i (@deps) {
- my $j = $i->handle->{pkgname};
+ my $j = $i->handle->pkgname;
$tree->{$j} = $pkg unless defined $tree->{$j};
}
}
@@ -116,7 +115,7 @@ sub installed
sub set_name_from_handle
{
my ($state, $h) = @_;
- $state->set_pkgname($h->{pkgname});
+ $state->set_pkgname($h->pkgname);
}
package OpenBSD::UpdateSet;
@@ -127,7 +126,7 @@ sub setup_header
{
my ($set, $state) = @_;
- my $pkgname = $set->handle->{pkgname};
+ my $pkgname = $set->handle->pkgname;
my $header = $state->deptree_header($pkgname).$pkgname;
if ($set->older) {
@@ -174,7 +173,7 @@ sub reorder_old
my $resolved;
my @l = ();
- my %todo = map {($_->{pkgname}, $_)} $set->older;
+ my %todo = map {($_->pkgname, $_)} $set->older;
do {
$resolved = 0;
BIGLOOP: while (my ($pkg, $h) = each %todo) {
@@ -195,7 +194,7 @@ sub can_install
my ($set, $state) = @_;
for my $handle ($set->newer) {
my $plist = $handle->{plist};
- my $pkgname = $handle->{pkgname};
+ my $pkgname = $handle->pkgname;
my @conflicts = OpenBSD::PkgCfl::find_all($plist, $state);
next if @conflicts == 0;
@@ -363,7 +362,7 @@ sub really_add
if ($replacing) {
for my $handle ($set->newer) {
- my $pkgname = $handle->{pkgname};
+ my $pkgname = $handle->pkgname;
$state->progress->set_header("$pkgname (extracting)");
try {
@@ -384,7 +383,7 @@ sub really_add
$set->{solver}->record_old_dependencies($state);
for my $o ($set->older_to_do) {
- my $oldname = $o->{pkgname};
+ my $oldname = $o->pkgname;
$state->progress->set_header($oldname." (deleting)");
$state->set_name_from_handle($o);
require OpenBSD::Delete;
@@ -407,7 +406,7 @@ sub really_add
}
for my $handle ($set->newer) {
- my $pkgname = $handle->{pkgname};
+ my $pkgname = $handle->pkgname;
my $plist = $handle->{plist};
$state->progress->set_header("$pkgname (installing)");
$state->set_name_from_handle($handle);
@@ -432,7 +431,7 @@ sub really_add
}
}
for my $handle ($set->newer) {
- my $pkgname = $handle->{pkgname};
+ my $pkgname = $handle->pkgname;
my $plist = $handle->{plist};
OpenBSD::SharedLibs::add_libs_from_plist($plist);
OpenBSD::Add::tweak_plist_status($plist, $state);
@@ -457,7 +456,7 @@ sub install_set
my ($set, $state, @todo) = @_;
my $handle = $set->handle;
- if ($state->is_installed($handle->{pkgname})) {
+ if ($state->is_installed($handle->pkgname)) {
if (defined $handle->{location}) {
$handle->{location}->close_now;
}
@@ -483,7 +482,7 @@ sub install_set
if ($plist->has('arch')) {
unless ($plist->{arch}->check($state->{arch})) {
- print "$handle->{pkgname} is not for the right architecture\n";
+ print $handle->pkgname, " is not for the right architecture\n";
return () unless $defines{arch};
}
}
@@ -494,7 +493,7 @@ sub install_set
$set->{solver}->dump;
}
if (@deps > 0) {
- $state->build_deptree($handle->{pkgname}, @deps);
+ $state->build_deptree($handle->pkgname, @deps);
return (@deps, $set);
}
}
@@ -503,7 +502,7 @@ sub install_set
my @baddeps = $set->{solver}->check_depends;
if (@baddeps) {
- print "Can't install $handle->{pkgname}: can't resolve ",
+ print "Can't install ", $handle->pkgname,": can't resolve ",
join(',', @baddeps), "\n";
$location->close_now;
$bad++;
@@ -528,7 +527,7 @@ sub install_set
really_add($set, $state);
$location->wipe_info;
delete $handle->{plist};
- $state->mark_installed($handle->{pkgname});
+ $state->mark_installed($handle->pkgname);
return ();
}