diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2010-12-24 09:09:55 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2010-12-24 09:09:55 +0000 |
commit | bca9417115a99cf39aed2e3a6a102d9a6774ee5c (patch) | |
tree | 00cdfa82ec78a3724b7334da65ea932b4f8e48f5 /usr.sbin/pkg_add | |
parent | fad9aa48fa7616bef3da618e4d69e10390f368af (diff) |
move the handling of ldconfig to AddDelete::State
actually simplifies code a great deal. It's not as if trying to avoid
loading ten lines of code is a good idea.
Diffstat (limited to 'usr.sbin/pkg_add')
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Add.pm | 4 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/AddDelete.pm | 76 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Delete.pm | 4 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PackingElement.pm | 22 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/SharedLibs.pm | 49 |
5 files changed, 84 insertions, 71 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Add.pm b/usr.sbin/pkg_add/OpenBSD/Add.pm index 1cc4f6e7a9b..9f0275086f2 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.117 2010/12/24 09:04:14 espie Exp $ +# $OpenBSD: Add.pm,v 1.118 2010/12/24 09:09:54 espie Exp $ # # Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org> # @@ -649,7 +649,7 @@ sub install my ($self, $state) = @_; $self->SUPER::install($state); return if $state->{do_faked}; - $self->mark_ldconfig_directory($state->{destdir}); + $self->mark_ldconfig_directory($state); } package OpenBSD::PackingElement::SpecialFile; diff --git a/usr.sbin/pkg_add/OpenBSD/AddDelete.pm b/usr.sbin/pkg_add/OpenBSD/AddDelete.pm index 3bf8d67c262..0d73727fcf9 100644 --- a/usr.sbin/pkg_add/OpenBSD/AddDelete.pm +++ b/usr.sbin/pkg_add/OpenBSD/AddDelete.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: AddDelete.pm,v 1.42 2010/12/24 09:04:14 espie Exp $ +# $OpenBSD: AddDelete.pm,v 1.43 2010/12/24 09:09:54 espie Exp $ # # Copyright (c) 2007-2010 Marc Espie <espie@openbsd.org> # @@ -64,7 +64,7 @@ sub framework my $dielater = $self->do_the_main_work($state); # cleanup various things $state->{recorder}->cleanup($state); - OpenBSD::PackingElement::Lib::ensure_ldconfig($state); + $state->ldconfig->ensure; OpenBSD::PackingElement::Fontdir::finish_fontdirs($state); $state->progress->clear; $state->log->dump; @@ -328,6 +328,78 @@ sub check_dir } } +OpenBSD::Auto::cache(ldconfig, + sub { + my $self = shift; + return OpenBSD::LdConfig->new($self); + }); + +# this is responsible for running ldconfig when needed +package OpenBSD::LdConfig; + +sub new +{ + my ($class, $state) = @_; + bless { state => $state, todo => 0 }, $class; +} + +# called once to figure out which directories are actually used +sub init +{ + my $self = shift; + my $state = $self->{state}; + my $destdir = $state->{destdir}; + + $self->{ldconfig} = [OpenBSD::Paths->ldconfig]; + + $self->{path} = {}; + if ($destdir ne '') { + unshift @{$self->{ldconfig}}, OpenBSD::Paths->chroot, '--', + $destdir; + } + open my $fh, "-|", @{$self->{ldconfig}}, "-r"; + if (defined $fh) { + my $_; + while (<$fh>) { + if (m/^\s*search directories:\s*(.*?)\s*$/o) { + for my $d (split(/\:/o, $1)) { + $self->{path}{$d} = 1; + } + last; + } + } + close($fh); + } else { + $state->errsay("Can't find ldconfig"); + } +} + +# called from libs to figure out whether ldconfig should be rerun +sub mark_directory +{ + my ($self, $name) = @_; + if (!defined $self->{path}) { + $self->init; + } + require File::Basename; + my $d = File::Basename::dirname($name); + if ($self->{path}{$d}) { + $self->{todo} = 1; + } +} + +# call before running any command (or at end) to run ldconfig just in time +sub ensure +{ + my $self = shift; + if ($self->{todo}) { + my $state = $self->{state}; + $state->vsystem(@{$self->{ldconfig}}, "-R") + unless $state->{not}; + $self->{todo} = 0; + } +} + # the object that gets displayed during status updates package OpenBSD::Status; diff --git a/usr.sbin/pkg_add/OpenBSD/Delete.pm b/usr.sbin/pkg_add/OpenBSD/Delete.pm index 345c7127cbe..ad1087ab532 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.111 2010/12/24 09:04:14 espie Exp $ +# $OpenBSD: Delete.pm,v 1.112 2010/12/24 09:09:54 espie Exp $ # # Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org> # @@ -655,7 +655,7 @@ sub delete { my ($self, $state) = @_; $self->SUPER::delete($state); - $self->mark_ldconfig_directory($state->{destdir}); + $self->mark_ldconfig_directory($state); } package OpenBSD::PackingElement::FDEINSTALL; diff --git a/usr.sbin/pkg_add/OpenBSD/PackingElement.pm b/usr.sbin/pkg_add/OpenBSD/PackingElement.pm index eb3657b8846..1325a57705b 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.189 2010/12/24 09:04:14 espie Exp $ +# $OpenBSD: PackingElement.pm,v 1.190 2010/12/24 09:09:54 espie Exp $ # # Copyright (c) 2003-2010 Marc Espie <espie@openbsd.org> # @@ -584,20 +584,8 @@ __PACKAGE__->register_with_factory; sub mark_ldconfig_directory { - require OpenBSD::SharedLibs; - - my ($self, $destdir) = @_; - OpenBSD::SharedLibs::mark_ldconfig_directory($self->fullname, - $destdir); -} - -sub ensure_ldconfig -{ - if ($todo) { - require OpenBSD::SharedLibs; - - &OpenBSD::SharedLibs::ensure_ldconfig; - } + my ($self, $state) = @_; + $state->ldconfig->mark_directory($self->fullname); } sub parse @@ -1291,7 +1279,7 @@ sub run { my ($self, $state) = @_; - OpenBSD::PackingElement::Lib::ensure_ldconfig($state); + $state->ldconfig->ensure; $state->say("#1 #2", $self->keyword, $self->{expanded}) if $state->verbose >= 2; $state->log->system(OpenBSD::Paths->sh, '-c', $self->{expanded}) @@ -1603,7 +1591,7 @@ sub run return if $state->{dont_run_scripts}; - OpenBSD::PackingElement::Lib::ensure_ldconfig($state); + $state->ldconfig->ensure; $state->say("#1 script: #2 #3 #4", $self->beautify, $name, $pkgname, join(' ', @args)) if $state->verbose >= 2; return if $state->{not}; diff --git a/usr.sbin/pkg_add/OpenBSD/SharedLibs.pm b/usr.sbin/pkg_add/OpenBSD/SharedLibs.pm index c35ab517e91..dfb646ab3e8 100644 --- a/usr.sbin/pkg_add/OpenBSD/SharedLibs.pm +++ b/usr.sbin/pkg_add/OpenBSD/SharedLibs.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: SharedLibs.pm,v 1.55 2010/12/24 09:04:14 espie Exp $ +# $OpenBSD: SharedLibs.pm,v 1.56 2010/12/24 09:09:54 espie Exp $ # # Copyright (c) 2003-2010 Marc Espie <espie@openbsd.org> # @@ -40,53 +40,6 @@ package OpenBSD::SharedLibs; use File::Basename; use OpenBSD::Error; -my $path; -my @ldconfig = (OpenBSD::Paths->ldconfig); - - -sub init_path($) -{ - my $destdir = shift; - $path={}; - if ($destdir ne '') { - unshift @ldconfig, OpenBSD::Paths->chroot, '--', $destdir; - } - open my $fh, "-|", @ldconfig, "-r"; - if (defined $fh) { - my $_; - while (<$fh>) { - if (m/^\s*search directories:\s*(.*?)\s*$/o) { - for my $d (split(/\:/o, $1)) { - $path->{$d} = 1; - } - last; - } - } - close($fh); - } else { - print STDERR "Can't find ldconfig\n"; - } -} - -sub mark_ldconfig_directory -{ - my ($name, $destdir) = @_; - if (!defined $path) { - init_path($destdir); - } - my $d = dirname($name); - if ($path->{$d}) { - $OpenBSD::PackingElement::Lib::todo = 1; - } -} - -sub ensure_ldconfig -{ - my $state = shift; - $state->vsystem(@ldconfig, "-R") unless $state->{not}; - $OpenBSD::PackingElement::Lib::todo = 0; -} - our $repo = OpenBSD::LibRepo->new; sub register_library |