Changeset 28228 for main/trunk/greenstone2
- Timestamp:
- 2013-09-05T21:17:20+12:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/perllib/util.pm
r28226 r28228 1300 1300 return $path unless is_abs_path_any_os($path); # path is relative 1301 1301 1302 if ($ENV{'GSDLOS'} =~ /^windows$/i) {1303 $path = &Win32::GetLongPathName($path);1304 }1305 1306 1302 # now we know we're dealing with absolute paths and have to replace gs prefixes with placeholders 1307 1303 my @gs_paths = ($ENV{'GSDLCOLLECTDIR'}, $ENV{'GSDLCOLLECTHOME'}, $ENV{'SITEHOME'}, $ENV{'GREENSTONEHOME'}); # list in this order: from longest to shortest path … … 1313 1309 $placeholder_map{$ENV{'SITEHOME'}} = '@SITEHOME@' if defined $ENV{'SITEHOME'}; 1314 1310 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 1336 sub _abspath_to_placeholders { 1337 my ($path, $gs_paths_ref, $placeholder_map_ref) = @_; 1315 1338 1316 1339 # The sequence of elements in @gs_paths matters … … 1318 1341 # to the shortest matching path (the path to gsdlhome/gsdl3home folder): 1319 1342 1320 foreach my $gs_path (@ gs_paths) {1343 foreach my $gs_path (@$gs_paths_ref) { 1321 1344 next if(!defined $gs_path); # site undefined for GS2 1322 1345 … … 1325 1348 if($path =~ m/^$re_path/i) { # case sensitive or not for OS? 1326 1349 1327 my $placeholder = $placeholder_map {$gs_path}; # get the placeholder to replace the matched path with1350 my $placeholder = $placeholder_map_ref->{$gs_path}; # get the placeholder to replace the matched path with 1328 1351 1329 1352 $path =~ s/^$re_path/$placeholder/; #case sensitive or not? … … 1348 1371 1349 1372 # 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 } 1355 1388 1356 1389 foreach my $placeholder (@placeholders) { … … 1358 1391 1359 1392 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 prefix1363 1393 1364 1394 if($path =~ m/^$placeholder/) {
Note:
See TracChangeset
for help on using the changeset viewer.