summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2004-10-31 11:33:52 +0000
committerMarc Espie <espie@cvs.openbsd.org>2004-10-31 11:33:52 +0000
commit7325169003f85df86e20ac2b8785c127fe247dd5 (patch)
tree114aa8a49b772310499d75aaa6519f67ce9b21b0
parent2f0ab5c8cdd215d2ef0b0b640f98a7a14e9c6c8b (diff)
Simplify ldconfig handling: one single ensure_ldconfig routine that
reruns ldconfig -R (okay, we don't check that -m would be enough, so what ?) First hooks for -r: check that replacement should work.
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackingElement.pm66
-rw-r--r--usr.sbin/pkg_add/pkg_add70
-rw-r--r--usr.sbin/pkg_add/pkg_delete9
3 files changed, 78 insertions, 67 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/PackingElement.pm b/usr.sbin/pkg_add/OpenBSD/PackingElement.pm
index b642f8d3cd9..1a08817f35f 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.59 2004/10/23 09:43:16 espie Exp $
+# $OpenBSD: PackingElement.pm,v 1.60 2004/10/31 11:33:51 espie Exp $
#
# Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org>
#
@@ -401,51 +401,57 @@ sub register_manpage
package OpenBSD::PackingElement::Lib;
our @ISA=qw(OpenBSD::PackingElement::FileBase);
use File::Basename;
+use OpenBSD::Error;
__PACKAGE__->setKeyword('lib');
sub keyword() { "lib" }
-our $todo;
+my $todo = 0;
my $path;
our @ldconfig = ('/sbin/ldconfig');
-sub add_ldconfig_dirs()
+sub init_path($)
{
- my $sub = shift;
- return unless defined $todo;
- for my $d (keys %$todo) {
- &$sub($d);
+ my $destdir = shift;
+ $path={};
+ if ($destdir ne '') {
+ unshift @ldconfig, 'chroot', $destdir;
+ }
+ open my $fh, "-|", @ldconfig, "-r";
+ if (defined $fh) {
+ local $_;
+ while (<$fh>) {
+ if (m/^\s*search directories:\s*(.*?)\s*$/) {
+ for my $d (split(':', $1)) {
+ $path->{$d} = 1;
+ }
+ }
+ }
+ close($fh);
+ } else {
+ print STDERR "Can't find ldconfig\n";
}
- $todo={};
}
sub mark_ldconfig_directory
{
my ($self, $destdir) = @_;
if (!defined $path) {
- $path={};
- if ($destdir ne '') {
- unshift @ldconfig, 'chroot', $destdir;
- }
- open my $fh, "-|", @ldconfig, "-r";
- if (defined $fh) {
- local $_;
- while (<$fh>) {
- if (m/^\s*search directories:\s*(.*?)\s*$/) {
- for my $d (split(':', $1)) {
- $path->{$d} = 1;
- }
- }
- }
- close($fh);
- } else {
- print STDERR "Can't find ldconfig\n";
- }
+ init_path($destdir);
}
my $d = dirname($self->fullname());
if ($path->{$d}) {
- $todo = {} unless defined $todo;
- $todo->{$d} = 1;
+ $todo = 1;
+ }
+}
+
+sub ensure_ldconfig
+{
+ my $state = shift;
+ if ($todo) {
+ VSystem($state->{very_verbose},
+ @ldconfig, "-R") unless $state->{not};
+ $todo = 0;
}
}
@@ -937,7 +943,7 @@ sub run
{
my ($self, $state) = @_;
- main::ensure_ldconfig($state);
+ OpenBSD::PackingElement::Lib::ensure_ldconfig($state);
print $self->keyword(), " ", $self->{expanded}, "\n" if $state->{beverbose};
$state->system('/bin/sh', '-c', $self->{expanded}) unless $state->{not};
}
@@ -1131,7 +1137,7 @@ sub run
return if $state->{dont_run_scripts};
- main::ensure_ldconfig($state);
+ OpenBSD::PackingElement::Lib::ensure_ldconfig($state);
print $self->beautify(), " script: $dir$name $pkgname ", join(' ', @args), "\n" if $state->{beverbose};
return if $not;
chmod 0755, $dir.$name;
diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add
index a29aa265ec3..ab7b541684f 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.85 2004/10/31 09:06:04 espie Exp $
+# $OpenBSD: pkg_add,v 1.86 2004/10/31 11:33:50 espie Exp $
#
# Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org>
#
@@ -35,18 +35,6 @@ use File::Copy;
our %forced = ();
our ($ftp_only, $cdrom_only);
-sub ensure_ldconfig
-{
- my $state = shift;
- return if $state->{not};
- return if $state->{do_faked};
- return unless defined $OpenBSD::PackingElement::Lib::todo;
- VSystem($state->{very_verbose},
- @OpenBSD::PackingElement::Lib::ldconfig, "-m",
- keys %$OpenBSD::PackingElement::Lib::todo);
- undef $OpenBSD::PackingElement::Lib::todo;
-}
-
# used by newuser/newgroup to deal with options.
sub add_entry
{
@@ -396,9 +384,9 @@ sub fill_conflict_lists
my $errors = 0;
-our ($opt_a, $opt_v, $opt_n, $opt_I, $opt_f, $opt_L, $opt_B, $opt_A, $opt_P, $opt_Q, $opt_x);
+our ($opt_a, $opt_v, $opt_n, $opt_I, $opt_f, $opt_L, $opt_B, $opt_A, $opt_P, $opt_Q, $opt_x, $opt_r);
$opt_v = 0;
-getopts('avnxIL:f:B:A:P:Q:',
+getopts('avnrxIL:f:B:A:P:Q:',
{'v' => sub {++$opt_v;} });
if ($opt_f) {
%forced = map {($_, 1)} split(/,/, $opt_f);
@@ -424,6 +412,7 @@ my $state = new OpenBSD::Error;
$state->{cache} = {};
$state->{deptree} = {};
$state->{do_faked} = 0;
+$state->{replace} = $opt_r;
if (defined $opt_Q and defined $opt_B) {
Fatal "-Q and -B are incompatible options";
}
@@ -455,24 +444,45 @@ $state->{beverbose} = $opt_n || ($opt_v >= 2);
fill_conflict_lists($state);
-sub can_install($$)
+sub find_conflicts
{
- my ($pkgname, $state) = @_;
-
+ my $pkgname = shift;
+ my @bad = ();
if (is_installed $pkgname) {
- print "package $pkgname is already installed\n";
- return undef unless $forced{installed};
+ push(@bad, $pkgname);
}
-
while (my ($name, $l) = each %{$state->{conflict_list}}) {
+ next if $name eq $pkgname;
if ($l->conflicts_with($pkgname)) {
- print "package $pkgname conflicts with installed package $name\n";
- $errors++;
- return undef unless $forced{conflicts};
+ push(@bad, $name);
}
}
+ return @bad;
+}
- return 1;
+sub can_install($$)
+{
+ my ($pkgname, $state) = @_;
+
+ my @l = find_conflicts($pkgname);
+
+ return 1 if @l == 0;
+ if (!$state->{replace} || @l >= 2) {
+ print "Can't install $pkgname because of conflicts (",join(',', @l), ")\n";
+ $errors++;
+ return undef;
+ }
+
+ require OpenBSD::Update;
+
+ my $toreplace = $l[0];
+ if (OpenBSD::Update::can_do($toreplace, $pkgname)) {
+ print "Will be able to update $toreplace once we're done\n";
+ } else {
+ print "Can't update $toreplace into $pkgname\n";
+ }
+ $errors++;
+ return undef;
}
@@ -713,9 +723,9 @@ sub collision_report($)
}
}
-sub validate_plist($$)
+sub validate_plist($$$)
{
- my ($plist, $destdir) = @_;
+ my ($plist, $destdir, $replace) = @_;
my $problems = 0;
my $pkgname = $plist->pkgname();
@@ -736,7 +746,7 @@ sub validate_plist($$)
for my $item (@{$plist->{items}}) {
next unless $item->IsFile();
my $fname = $destdir.$item->fullname();
- if (OpenBSD::Vstat::vexists($fname)) {
+ if (OpenBSD::Vstat::vexists($fname) && !$replace) {
push(@$colliding, $fname);
$problems++;
}
@@ -808,7 +818,7 @@ sub really_add($$)
}
print "\n";
}
- my $totsize = validate_plist($plist, $destdir);
+ my $totsize = validate_plist($plist, $destdir, $state->{replace});
if (!defined $handle) {
Fatal "Archive in $pkgname broken";
@@ -969,7 +979,7 @@ my $dielater = $@;
OpenBSD::PackingElement::Fontdir::finish_fontdirs();
manpages_index($state);
-ensure_ldconfig($state);
+OpenBSD::PackingElement::Lib::ensure_ldconfig($state);
if ($state->{beverbose}) {
OpenBSD::Vstat::tally();
diff --git a/usr.sbin/pkg_add/pkg_delete b/usr.sbin/pkg_add/pkg_delete
index 1379c81cb43..f0dfdad6158 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.66 2004/10/31 10:26:17 espie Exp $
+# $OpenBSD: pkg_delete,v 1.67 2004/10/31 11:33:50 espie Exp $
#
# Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org>
#
@@ -30,11 +30,6 @@ use OpenBSD::PackageInfo;
our %forced = ();
-sub ensure_ldconfig
-{
- &OpenBSD::Delete::ensure_ldconfig;
-}
-
our ($opt_v, $opt_D, $opt_d, $opt_n, $opt_f, $opt_q, $opt_p, $opt_c, $opt_L, $opt_B, $opt_I, $opt_x);
$opt_v = 0;
@@ -193,7 +188,7 @@ eval {
my $dielater = $@;
-ensure_ldconfig($state);
+OpenBSD::PackingElement::Lib::ensure_ldconfig($state);
# delayed directory/user/group removal
if (defined $state->{dirs_to_rm} or defined $state->{users_to_rm} or
defined $state->{groups_to_rm}) {