Ignore:
Timestamp:
11/25/09 15:51:48 (2 years ago)
Author:
OlivierRaginel
Message:

Item8084: Add -c option to extender.pl to prevent CPAN.
Use Getopt::Std to parse arguments.
Allow directories in MANIFEST.
Cleanup session once it's been used.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/Release01x00/core/tools/extender.pl

    r5638 r5639  
    3434use File::Copy; 
    3535use File::Path; 
     36use Getopt::Std; 
    3637 
    3738no warnings 'redefine'; 
    3839 
    39 my $noconfirm  = 0; 
    40 my $downloadOK = 0; 
    41 my $alreadyUnpacked = 0; 
    42 my $reuseOK    = 0; 
    43 my $inactive   = 0; 
     40my $noconfirm; 
     41my $downloadOK; 
     42my $alreadyUnpacked; 
     43my $reuseOK; 
     44my $inactive; 
     45my $noCPAN; 
     46my $action; 
    4447my $session; 
    4548my %available; 
     
    5861    $installationRoot = $1; 
    5962 
     63    sub processParameters { 
     64        my %opts; 
     65        getopts('acdnru', \%opts); 
     66        $noconfirm = $opts{a}; 
     67        $noCPAN = $opts{c}; 
     68        $downloadOK = $opts{d}; 
     69        $reuseOK = $opts{r}; 
     70        $inactive = $opts{n}; 
     71        $alreadyUnpacked = $opts{u}; 
     72        if( @ARGV > 1 ) { 
     73            usage(); 
     74            die 'Too many parameters: ' . join(" ", @ARGV); 
     75        } 
     76        $action = $ARGV[0]; 
     77        $action ||= 'install';  # Default target is install 
     78    } 
     79 
    6080    # Check if we were invoked from configure 
    6181    # by looking at the call stack 
     
    6787            } 
    6888        } 
    69         return 0; 
    70     } 
     89        return; 
     90    } 
     91 
    7192    my $check_perl_module = sub { 
    7293        my $module = shift; 
    7394 
    7495        if ( $module =~ /^CPAN/ ) { 
    75  
    76             # Check how we were invoked as CPAN shouldn't 
    77             # be loaded from the configure 
    78             if (running_from_configure) { 
    79                 print "Running from configure, disabling $module\n"; 
     96            if ($noCPAN) { 
     97                print "CPAN is disabled, disabling $module\n"; 
    8098                return $available{$module} = 0; 
    8199            } 
     
    100118    } 
    101119 
     120    processParameters(); 
    102121    # read setlib.cfg 
    103122    chdir('bin'); 
     
    126145    } 
    127146    &$check_perl_module('CPAN'); 
    128      
    129     $session->finish(); 
    130     undef $session; 
    131147} 
    132148 
     
    581597        $cmd .= ' -r' if $reuseOK; 
    582598        $cmd .= ' -n' if $inactive; 
     599        $cmd .= ' -c' if $noCPAN; 
    583600        $cmd .= ' install'; 
    584601        local $| = 0; 
     
    794811        $err = $@; 
    795812    } 
     813    $session->finish(); 
     814    undef $session; 
    796815    return ( !$err ); 
    797816} 
     
    852871        print "Install $target, permissions $MANIFEST->{$file}->{perms}\n"; 
    853872        unless ($inactive) { 
    854             if ( -e $target ) { 
     873            if ( -e $target && ! -d _ ) { 
    855874                # Save current permissions, remove write protect for Windows sake,   
    856875                # Back up the file and then restore the original permissions 
     
    864883                } 
    865884            } 
    866             my @path = split( /[\/\\]+/, $target ); 
     885            my @path = split( /[\/\\]+/, $target, -1 ); # -1 allows directories 
    867886            pop(@path); 
    868887            if ( scalar(@path) ) { 
    869888                File::Path::mkpath( join( '/', @path ) ); 
    870889            } 
    871             File::Copy::move( $source, $target ) 
    872               || die "Failed to move $source to $target: $!\n"; 
     890            unless( -d $source ) { 
     891                File::Copy::move( $source, $target ) 
     892                    || print STDERR "Failed to move $source to $target: $!\n"; 
     893            } 
    873894        } 
    874895        unless ($inactive) { 
     
    11321153    unshift( @INC, 'lib' ); 
    11331154 
    1134     my $n      = 0; 
    1135     my $action = 'install'; 
    1136     while ( $n < scalar(@ARGV) ) { 
    1137         if ( $ARGV[$n] eq '-a' ) { 
    1138             $noconfirm = 1; 
    1139         } 
    1140         elsif ( $ARGV[$n] eq '-d' ) { 
    1141             $downloadOK = 1; 
    1142         } 
    1143         elsif ( $ARGV[$n] eq '-r' ) { 
    1144             $reuseOK = 1; 
    1145         } 
    1146         elsif ( $ARGV[$n] eq '-n' ) { 
    1147             $inactive = 1; 
    1148         } 
    1149         elsif ( $ARGV[$n] eq '-u' ) { 
    1150             $alreadyUnpacked = 1; 
    1151         } 
    1152         elsif ( $ARGV[$n] =~ m/(install|uninstall|manifest|dependencies)/ ) { 
    1153             $action = $1; 
    1154         } 
    1155  
    1156 # SMELL:   There really shouldn't be a null argument.  But installer breaks if it is there. 
    1157         elsif ( $ARGV[$n] eq '' ) { 
    1158             $n++; 
    1159             next; 
    1160         } 
    1161         else { 
    1162             usage(); 
    1163             die 'Bad parameter ' . $ARGV[$n]; 
    1164         } 
    1165         $n++; 
    1166     } 
    1167  
    11681155    if ( $action eq 'manifest' ) { 
    11691156        foreach my $row ( split( /\r?\n/, $data{MANIFEST} ) ) { 
Note: See TracChangeset for help on using the changeset viewer.