Skip to content

Commit

Permalink
Item2366: Handle relocated / renamed bin directory
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk@8403 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
GeorgeClark authored and GeorgeClark committed Aug 2, 2010
1 parent 7387273 commit 9faa827
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 9 deletions.
4 changes: 2 additions & 2 deletions UnitTestContrib/test/unit/ConfigureTests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -531,10 +531,10 @@ sub test_Util_mapTarget {
# Remap bin directory and script suffix - WebPrefsTopicName - default WebPreferences

$Foswiki::cfg{ScriptSuffix} = '.pl';
$Foswiki::cfg{ScriptDir} = 'C:/asdf/bin/';
$Foswiki::cfg{ScriptDir} = 'C:/asdf/cgi-bin/';
$file = 'bin/compare';
$results = Foswiki::Configure::Util::mapTarget( "C:/asdf/", "$file" );
$this->assert_str_equals( "C:/asdf/bin/compare.pl", $results );
$this->assert_str_equals( "C:/asdf/cgi-bin/compare.pl", $results );

# Remap the data/mime.types file location

Expand Down
7 changes: 2 additions & 5 deletions core/lib/Foswiki/Configure/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,12 @@ names and also Web names. The following mapping is performed:
* =TemplateDir=
* =ToolsDir=
* =LocalesDir=
* =ScriptDir=
---+++ Other
* =ScriptSuffix=
* =MimeTypesFileName=
---+++ NOT Handled
* bin directory is assumed to be bin
=cut

sub mapTarget {
Expand Down Expand Up @@ -133,10 +131,9 @@ sub mapTarget {
}
elsif ( $file =~ s#^locale/#$Foswiki::cfg{LocalesDir}/# ) {
}
elsif ( $file =~ s#^(bin/\w+)$#$root$1$Foswiki::cfg{ScriptSuffix}# ) {
elsif ( $file =~ s#^bin/(\w+)$#$Foswiki::cfg{ScriptDir}$1$Foswiki::cfg{ScriptSuffix}# ) {

#This makes a couple of bad assumptions
#1. that the foswiki's bin dir _is_ called bin
#2. that any file going into there _is_ a script - making installing the
# .htaccess file via this machanism impossible
#3. that softlinks are not in use (same issue below)
Expand Down
50 changes: 48 additions & 2 deletions core/tools/extender.pl
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,15 @@ sub _stop {
return $available{$module};
};

unless ( -d 'lib' && -d 'bin' && -e 'bin/setlib.cfg' ) {
unless ( -d 'lib' && -d 'data' && -e 'lib/LocalSite.cfg' ) {
_stop( 'This installer must be run from the root directory'
. ' of a Foswiki installation' );
}

my $bindir = getScriptDir('lib/LocalSite.cfg');

# read setlib.cfg
chdir('bin');
chdir($bindir);
require 'setlib.cfg';
chdir($installationRoot);

Expand Down Expand Up @@ -486,6 +488,50 @@ sub _validatePerlModule {
return $module;
}

=begin TML
---++ StaticMethod getScriptDir( )
This routine will recover the Script Directory from LocalSite.cfg
without processing the entire file.
=cut

sub getScriptDir {

my $lscFile = shift;

# - Single-quoted string
my $reSqString = qr{
\'
([^\']+)
\'
}x;

# - Double-quoted string
my $reDqString = qr{
\"
([^\"]+)
\"
}x;

my $reBinDir = qr{
^\s*\$Foswiki::cfg\{ScriptDir\} # Variable
\s*=\s* # Equal sign - optional spaces
(?: (?:$reSqString) | (?:$reDqString) ) # delimited value
\s*;\s*$ # ending bracket
}msx;

local $/ = '';
open( my $fh, '<',
$lscFile )
|| die 'Unable to open LocalSite.cfg';
my $cfgfile = <$fh>;
close($fh);
$cfgfile =~ m/$reBinDir/;
return $1;

}

#
# Install is the main routine called by the [package]_installer script
#
Expand Down

0 comments on commit 9faa827

Please sign in to comment.