Ignore:
Timestamp:
2013-09-05T21:17:20+12:00 (11 years ago)
Author:
ak19
Message:

For windows, need to check for short (not long) file/path names when replacing common Greenstone prefixes with placeholders and vice-versa. Tested with GS SVN and modified binary from yesterday. Need to regenerate the gs2 model collections once more.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/util.pm

    r28226 r28228  
    13001300    return $path unless is_abs_path_any_os($path); # path is relative
    13011301   
    1302     if ($ENV{'GSDLOS'} =~ /^windows$/i) {       
    1303         $path = &Win32::GetLongPathName($path);
    1304     }   
    1305    
    13061302    # now we know we're dealing with absolute paths and have to replace gs prefixes with placeholders
    13071303    my @gs_paths = ($ENV{'GSDLCOLLECTDIR'}, $ENV{'GSDLCOLLECTHOME'}, $ENV{'SITEHOME'}, $ENV{'GREENSTONEHOME'}); # list in this order: from longest to shortest path
     
    13131309    $placeholder_map{$ENV{'SITEHOME'}} = '@SITEHOME@' if defined $ENV{'SITEHOME'};
    13141310
     1311    $path = &util::_abspath_to_placeholders($path, \@gs_paths, \%placeholder_map);
     1312
     1313    if ($ENV{'GSDLOS'} =~ /^windows$/i) {
     1314    # for windows need to look for matches on short file names too
     1315    # matched paths are again to be replaced with the usual placeholders
     1316
     1317    my $gsdlcollectdir = &util::downgrade_if_dos_filename($ENV{'GSDLCOLLECTDIR'});
     1318    my $gsdlcollecthome = &util::downgrade_if_dos_filename($ENV{'GSDLCOLLECTHOME'});
     1319    my $sitehome = (defined $ENV{'SITEHOME'}) ? &util::downgrade_if_dos_filename($ENV{'SITEHOME'}) : undef;
     1320    my $greenstonehome =  &util::downgrade_if_dos_filename($ENV{'GREENSTONEHOME'});
     1321
     1322    @gs_paths = ($gsdlcollectdir, $gsdlcollecthome, $sitehome, $greenstonehome); # order matters
     1323
     1324    %placeholder_map = ($greenstonehome => '@GSDLHOME@', # can't use double-quotes around at-sign, else perl tries to evaluate it as referring to an array
     1325                $gsdlcollecthome => '@COLLECTHOME@',
     1326                $gsdlcollectdir => '@THISCOLLECTPATH@'
     1327        );
     1328    $placeholder_map{$sitehome} = '@SITEHOME@' if defined $sitehome;
     1329
     1330    $path = &util::_abspath_to_placeholders($path, \@gs_paths, \%placeholder_map);
     1331    }
     1332
     1333    return $path;
     1334}
     1335
     1336sub _abspath_to_placeholders {
     1337    my ($path, $gs_paths_ref, $placeholder_map_ref) = @_;
    13151338
    13161339    # The sequence of elements in @gs_paths matters   
     
    13181341    # to the shortest matching path (the path to gsdlhome/gsdl3home folder):
    13191342
    1320     foreach my $gs_path (@gs_paths) {
     1343    foreach my $gs_path (@$gs_paths_ref) {
    13211344    next if(!defined $gs_path); # site undefined for GS2
    13221345
     
    13251348    if($path =~ m/^$re_path/i) { # case sensitive or not for OS?
    13261349
    1327         my $placeholder = $placeholder_map{$gs_path}; # get the placeholder to replace the matched path with
     1350        my $placeholder = $placeholder_map_ref->{$gs_path}; # get the placeholder to replace the matched path with
    13281351
    13291352        $path =~ s/^$re_path/$placeholder/; #case sensitive or not?
     
    13481371
    13491372    # can't use double-quotes around at-sign, else perl tries to evaluate it as referring to an array
    1350     my %placeholder_to_gspath_map = ('@GSDLHOME@' => $ENV{'GREENSTONEHOME'},
    1351                      '@SITEHOME@' => $ENV{'SITEHOME'},
    1352                      '@COLLECTHOME@' => $ENV{'GSDLCOLLECTHOME'},
    1353                      '@THISCOLLECTPATH@' => $ENV{'GSDLCOLLECTDIR'}
    1354     ); # $placeholder_to_gspath_map{'@SITEHOME@'} = $ENV{'SITEHOME'} if defined $ENV{'SITEHOME'};
     1373    my %placeholder_to_gspath_map;
     1374    if ($ENV{'GSDLOS'} =~ /^windows$/i) {
     1375    # always replace placeholders with short file names of the absolute paths on windows?
     1376    %placeholder_to_gspath_map = ('@GSDLHOME@' => &util::downgrade_if_dos_filename($ENV{'GREENSTONEHOME'}),
     1377                     '@COLLECTHOME@' => &util::downgrade_if_dos_filename($ENV{'GSDLCOLLECTHOME'}),
     1378                     '@THISCOLLECTPATH@' => &util::downgrade_if_dos_filename($ENV{'GSDLCOLLECTDIR'})
     1379    );
     1380    $placeholder_to_gspath_map{'@SITEHOME@'} =  &util::downgrade_if_dos_filename($ENV{'SITEHOME'}) if defined $ENV{'SITEHOME'};
     1381    } else {
     1382    %placeholder_to_gspath_map = ('@GSDLHOME@' => $ENV{'GREENSTONEHOME'},
     1383                      '@SITEHOME@' => $ENV{'SITEHOME'}, # can be undef
     1384                      '@COLLECTHOME@' => $ENV{'GSDLCOLLECTHOME'},
     1385                      '@THISCOLLECTPATH@' => $ENV{'GSDLCOLLECTDIR'}
     1386        ); # $placeholder_to_gspath_map{'@SITEHOME@'} = $ENV{'SITEHOME'} if defined $ENV{'SITEHOME'};
     1387    }
    13551388
    13561389    foreach my $placeholder (@placeholders) {
     
    13581391
    13591392    next if(!defined $gs_path); # sitehome for GS2 is undefined
    1360 
    1361     #my $sep = ($ENV{'GSDLOS'} eq "windows") ? "\\" : "/";
    1362     #$gs_path = $gs_path . "$sep" if ($gs_path !~ m/$sep$/); # add in any trailing separator to the path prefix
    13631393
    13641394    if($path =~ m/^$placeholder/) {
Note: See TracChangeset for help on using the changeset viewer.