Skip to content

Commit

Permalink
Item1177: Move dependency to UNIVERSAL::require after loading setlib.…
Browse files Browse the repository at this point in the history
…cfg, in case it's not installed on the system, so we can use the one bundled with Foswiki

Fixed setlib.cfg so it doesn't rely on Cwd, otherwise installer scripts won't find our local CPAN librairies (and thus UNIVERSAL::require)
Also removed the last remaining eval's to check for module existence, so they'll use this module.
We still have an old bug laying around, that we can't decide if we're Foswiki or TWiki.

git-svn-id: http://svn.foswiki.org/trunk@2848 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
OlivierRaginel authored and OlivierRaginel committed Mar 3, 2009
1 parent 6ec63eb commit 9d2d716
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
8 changes: 6 additions & 2 deletions core/bin/setlib.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,18 @@

use vars qw( $foswikiLibPath @localPerlLibPath );

eval 'require "LocalLib.cfg"';
my $LocalLib = __FILE__; # the dir where this setlib.cfg resides
$LocalLib =~ s/setlib.cfg$/LocalLib.cfg/;
require $LocalLib if -r $LocalLib;
# if foswikiLibPath isn't defined, then see if $twikiLibPath is
# for compatibility
$foswikiLibPath = $twikiLibPath unless defined( $foswikiLibPath );

unless (( defined ($foswikiLibPath) ) and (-e $foswikiLibPath)) {
use Cwd qw( abs_path );
( $foswikiLibPath ) = ($foswikiLibPath = Cwd::abs_path( "../lib" )) =~ /(.*)/;
my $bindir = __FILE__;
$bindir =~ s/setlib.cfg$//;
( $foswikiLibPath ) = ($foswikiLibPath = Cwd::abs_path( "$bindir/../lib" )) =~ /(.*)/;
}
if ($foswikiLibPath eq "") {
$foswikiLibPath = "../lib";
Expand Down
42 changes: 19 additions & 23 deletions core/tools/extender.pl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ package Foswiki::Extender;
use File::Temp;
use File::Copy;
use File::Path;
use UNIVERSAL::require;

no warnings 'redefine';

Expand Down Expand Up @@ -79,8 +78,7 @@ BEGIN
return $available{$module} = 0;
}
}
eval "use $module;";
if ($@) {
unless ( $module->use ) {
print
"Warning: $module is not available, some installer functions have been disabled\n";
$available{$module} = 0;
Expand All @@ -103,6 +101,10 @@ BEGIN
chdir('bin');
require 'setlib.cfg';

# This has to be read after setlib.cfg, as it might not exist in the system
# so we will use the one we ship
require UNIVERSAL::require;

# See if we can make a Foswiki. If we can, then we can save topic
# and attachment histories. Key off Foswiki::Merge because it is
# fairly new and fairly unique.
Expand Down Expand Up @@ -539,8 +541,7 @@ sub unpackArchive {
sub unzip {
my $archive = shift;

eval 'use Archive::Zip';
unless ($@) {
unless ( 'Archive::Zip'->use ) {
my $zip = Archive::Zip->new();
my $numberOfFiles = $zip->read($archive);
unless ( $numberOfFiles > 0 ) {
Expand Down Expand Up @@ -582,8 +583,7 @@ sub untar {

my $compressed = ( $archive =~ /z$/i ) ? 'z' : '';

eval 'use Archive::Tar';
unless ($@) {
unless ( 'Archive::Tar'->use ) {
my $tar = Archive::Tar->new();
my $numberOfFiles = $tar->read( $archive, $compressed );
unless ( $numberOfFiles > 0 ) {
Expand Down Expand Up @@ -851,18 +851,15 @@ sub _install {
$path = $source . '::' . $type . '::' . $rootModule;
}

eval 'use ' . $path;
unless ($@) {
my $version = eval '$' . $path . '::VERSION';
if ($version) {
unless (
ask(
if ( $path->use ) {
# Module is already installed
# XXX SMELL: Could be more user-friendly:
# test that current version isn't newest
if ( my $version = $path->VERSION ) {
return 0
unless ask(
"$MODULE version $version is already installed. Are you sure you want to re-install this module?"
)
)
{
return 0;
}
);
print <<DONE;
I will keep a backup of any files I overwrite.
DONE
Expand Down Expand Up @@ -903,9 +900,9 @@ sub _validatePerlModule {
# Do not use \w as this is localized, and might be tainted
my $replacements = $module =~ s/[^a-zA-Z:_0-9]//g;
print STDERR 'validatePerlModule removed '
. $replacements
. ' characters, leading to '
. $module ."\n"
. $replacements
. ' characters, leading to '
. $module . "\n"
if $replacements;
return $module;
}
Expand All @@ -927,8 +924,7 @@ sub install {
foreach my $row ( split( /\r?\n/, $data{DEPENDENCIES} ) ) {
my ( $module, $condition, $trigger, $type, $desc ) =
split( ',', $row, 5 );
$module =
Foswiki::Sandbox::untaint( $module, \&_validatePerlModule );
$module = Foswiki::Sandbox::untaint( $module, \&_validatePerlModule );
if ( $trigger eq '1' ) {

# ONLYIF usually isn't used, and is dangerous
Expand Down

0 comments on commit 9d2d716

Please sign in to comment.