From 424d6eadbe8a0c863a4f6a4ea5e60a86a309de50 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Fri, 22 Jul 2011 12:57:16 +0200 Subject: [PATCH] In Konfiguration angegebene Anwendungen in PATH suchen MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Fix für Bug 1690. --- SL/Dispatcher.pm | 22 ---------------------- SL/LxOfficeConf.pm | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 22 deletions(-) diff --git a/SL/Dispatcher.pm b/SL/Dispatcher.pm index 4aadef74d..97a2f45f4 100644 --- a/SL/Dispatcher.pm +++ b/SL/Dispatcher.pm @@ -81,7 +81,6 @@ sub pre_startup_setup { my ($self) = @_; SL::LxOfficeConf->read; - _init_environment(); eval { package main; @@ -370,27 +369,6 @@ sub get_standard_filehandles { return $self->{interface} =~ m/f(?:ast)cgi/i ? $self->{request}->GetHandles() : (\*STDIN, \*STDOUT, \*STDERR); } -sub _init_environment { - my %key_map = ( lib => { name => 'PERL5LIB', append_path => 1 }, - path => { name => 'PATH', append_path => 1 }, - ); - my $cfg = $::lx_office_conf{environment} || {}; - - while (my ($key, $value) = each %{ $cfg }) { - next unless $value; - - my $info = $key_map{$key} || {}; - $key = $info->{name} || $key; - - if ($info->{append_path}) { - $value = ':' . $value unless $value =~ m/^:/ || !$ENV{$key}; - $value = $ENV{$key} . $value; - } - - $ENV{$key} = $value; - } -} - sub _check_for_old_config_files { my @old_files = grep { -f "config/${_}" } qw(authentication.pl console.conf lx-erp.conf lx-erp-local.conf); return unless @old_files; diff --git a/SL/LxOfficeConf.pm b/SL/LxOfficeConf.pm index 7690eebda..c13318677 100644 --- a/SL/LxOfficeConf.pm +++ b/SL/LxOfficeConf.pm @@ -5,6 +5,8 @@ use strict; use Config::Std; use Encode; +my $environment_initialized; + sub read { my ($class, $file_name) = @_; @@ -18,6 +20,9 @@ sub read { _decode_recursively(\%local_conf); _flat_merge(\%::lx_office_conf, \%local_conf); } + + _init_environment(); + _determine_application_paths(); } sub _decode_recursively { @@ -45,4 +50,44 @@ sub _flat_merge { } } +sub _init_environment { + return if $environment_initialized; + + my %key_map = ( lib => { name => 'PERL5LIB', append_path => 1 }, + path => { name => 'PATH', append_path => 1 }, + ); + my $cfg = $::lx_office_conf{environment} || {}; + + while (my ($key, $value) = each %{ $cfg }) { + next unless $value; + + my $info = $key_map{$key} || {}; + $key = $info->{name} || $key; + + if ($info->{append_path}) { + $value = ':' . $value unless $value =~ m/^:/ || !$ENV{$key}; + $value = $ENV{$key} . $value; + } + + $ENV{$key} = $value; + } + + $environment_initialized = 1; +} + +sub _determine_application_paths { + my @paths = grep { $_ } split m/:/, $ENV{PATH}; + + foreach my $key (keys %{ $::lx_office_conf{applications} }) { + my ($program) = split m/\s+/, $::lx_office_conf{applications}->{$key}; + next if $program =~ m|/|; + + foreach my $path (@paths) { + next unless -f "${path}/${program}"; + $::lx_office_conf{applications}->{$key} = "${path}/" . $::lx_office_conf{applications}->{$key}; + last; + } + } +} + 1; -- 2.20.1