Ignore:
Timestamp:
2013-09-04T21:46:07+12:00 (11 years ago)
Author:
ak19
Message:

No more absolute paths in archiveinf-doc.gdb and archiveinf-src.gdb

File:
1 edited

Legend:

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

    r28177 r28211  
    824824    }
    825825
     826    if (!defined $ENV{'GREENSTONEHOME'}) { # for GS3, would have been defined in use_site_collection, to GSDL3HOME
     827     $ENV{'GREENSTONEHOME'} = $ENV{'GSDLHOME'};
     828    }
     829
    826830    # get and check the collection
    827831    if (!defined($collection) || $collection eq "") {
     
    842846    # are defined
    843847    $ENV{'GSDLCOLLECTION'} = $collection;
     848    $ENV{'GSDLCOLLECTHOME'} = $collectdir;
    844849    $ENV{'GSDLCOLLECTDIR'} = &FileUtils::filenameConcatenate($collectdir, $collection);
    845850
     
    868873    die "GSDL3HOME not set.\n" unless defined $ENV{'GSDL3HOME'};
    869874    $collectdir = &FileUtils::filenameConcatenate($ENV{'GSDL3HOME'}, "sites", $site, "collect");
     875    }
     876
     877    if (defined $ENV{'GSDL3HOME'}) {
     878    $ENV{'GREENSTONEHOME'} = $ENV{'GSDL3HOME'};     
     879    $ENV{'SITEHOME'} = &FileUtils::filenameConcatenate($ENV{'GREENSTONEHOME'}, "sites", $site);
     880    } elsif (defined $ENV{'GSDL3SRCHOME'}) {
     881    $ENV{'GREENSTONEHOME'} = &FileUtils::filenameConcatenate($ENV{'GSDL3SRCHOME'}, "web"); 
     882    $ENV{'SITEHOME'} = &FileUtils::filenameConcatenate($ENV{'GREENSTONEHOME'}, "sites", $site);
     883    } else {
     884    print STDERR "*** util::use_site_collection(). Warning: Neither GSDL3HOME nor GSDL3SRCHOME set.\n";
    870885    }
    871886
     
    12131228    my ($collect_dir, $qualified_collection, $site) = @_; #, $gs_mode
    12141229   
     1230    if (defined $ENV{'GSDLCOLLECTDIR'}) { # a predefined collection dir exists
     1231        return $ENV{'GSDLCOLLECTDIR'};
     1232    }
     1233
    12151234    my ($colgroup, $collection) = &util::get_collection_parts($qualified_collection);   
    12161235   
     
    12241243# work out the full path to "collect" of this greenstone 2/3 installation
    12251244sub get_working_collect_dir {
    1226     my ($site) = @_;
    1227    
    1228     if (defined $ENV{'GSDLCOLLECTDIR'}) { # a predefined collect dir exists
    1229     return $ENV{'GSDLCOLLECTDIR'};
    1230     }
    1231    
    1232     elsif (defined $site && $site) { # site non-empty, so get default collect dir for GS3
    1233     return &FileUtils::filenameConcatenate(&util::get_site_dir($site),"collect");
     1245    my ($site) = @_;   
     1246
     1247    if (defined $ENV{'GSDLCOLLECTHOME'}) { # a predefined collect dir exists
     1248    return $ENV{'GSDLCOLLECTHOME'};
     1249    }
     1250
     1251    if (defined $site && $site) { # site non-empty, so get default collect dir for GS3
     1252   
     1253    if (defined $ENV{'GSDL3HOME'}) {
     1254        return &FileUtils::filenameConcatenate($ENV{'GSDL3HOME'},"sites",$site,"collect"); # web folder
     1255    }
     1256    elsif (defined $ENV{'GSDL3SRCHOME'}) {
     1257        return &FileUtils::filenameConcatenate($ENV{'GSDL3SRCHOME'},"web","sites",$site,"collect");
     1258    }
     1259    }
     1260
     1261    elsif (defined $ENV{'SITEHOME'}) { #&FileUtils::filenameConcatenate(&util::get_site_dir($site),"collect");
     1262    return &FileUtils::filenameConcatenate($ENV{'SITEHOME'},"collect");
    12341263    }
    12351264   
     
    12391268}
    12401269
    1241 # returns path to current GS3 site.
    1242 # Returns "" if $site parameter is empty string, undefined or otherwise false
    1243 sub get_site_dir {
    1244     my ($site) = @_;
    1245    
    1246     if (defined $ENV{'GSDL3HOME'}) {
    1247     return &FileUtils::filenameConcatenate($ENV{'GSDL3HOME'},"sites",$site); # web folder
    1248     }
    1249     elsif (defined $ENV{'GSDL3SRCHOME'}) {
    1250     return &FileUtils::filenameConcatenate($ENV{'GSDL3SRCHOME'},"web","sites",$site);
    1251     }
    1252     else { # site has no meaning, return "" (covers the case of this subroutine having been called for a GS2 situation)
    1253     return "";
    1254     }
    1255 }
    1256 
    1257 # returns path to GSDL3HOME if GS3, or GSDLHOME if GS2
    1258 sub get_gs_home {
    1259     my ($site) = @_;
    1260 
    1261     if (defined $site && $site) { # not undefined or empty string, so GS3 case
    1262     if (defined $ENV{'GSDL3HOME'}) {
    1263         return $ENV{'GSDL3HOME'};
    1264     } else {
    1265         return &FileUtils::filenameConcatenate($ENV{'GSDL3SRCHOME'},"web");
    1266     }
    1267     } else {
    1268     return $ENV{'GSDLHOME'};
    1269     }
    1270 }
    1271 
    1272 sub is_abs_path {
     1270sub is_abs_path_this_os {
    12731271    my ($path) = @_;
     1272
     1273    # File::Spec loads the module appropriate for the OS
     1274    return &FileUtils::isFilenameAbsolute(@_); #return File::Spec->file_name_is_absolute( $path );
     1275}
     1276
     1277
     1278sub is_abs_path_any_os {
     1279    my ($path) = @_;
     1280
     1281    # We can have filenames in our DBs that were produced on other OS, so this method exists
     1282    # to help identify absolute paths in such cases.
    12741283
    12751284    return 1 if($path =~ m@^/@); # full paths begin with forward slash on linux/mac
     
    12771286
    12781287    return 0;
    1279 
    1280     # File::Spec loads the module appropriate for the OS, but abs paths in archiveinf-doc.xml may be generated on another OS to this one
    1281     #return File::Spec->file_name_is_absolute( $path );   
    1282 }
    1283 
    1284 # returns an array of the FULL PATHS to the specific collection given, to the general collect_dir,
    1285 # to the site directory if gs3 and to the greenstone home folder (GSDLHOME or GSDL3HOME).
    1286 # These elements are returned in this ORDER, in order to allow matching from longest to shortest path.
    1287 sub get_common_gs_paths {
    1288 
    1289     my ($site, $qualified_collection_name) = @_;
    1290    
    1291     my $collect_dir = &util::get_working_collect_dir($site);
    1292     my $collection_path = "";
    1293     if($qualified_collection_name ne "") {
    1294     $collection_path = &util::resolve_collection_dir($collect_dir, $qualified_collection_name, $site);
    1295     }
    1296    
    1297     my $site_dir = &util::get_site_dir($site); # returns "" for GS2
    1298     my $gs_home = &util::get_gs_home(); # GSDLHOME or GSDL3HOME folder
    1299    
    1300     return ($collection_path, $collect_dir, $site_dir, $gs_home); # list in this order: from longest to shortest path
    1301     #my @gs_paths = ($collection_path, $collect_dir, $site_dir, $gs_home); # list in this order: from longest to shortest path
    1302     #return @gs_paths;
    1303 }
     1288}
     1289
    13041290
    13051291# This subroutine is for improving portability of Greenstone collections from one OS to another,
     
    13161302    my $path = shift(@_); # path to convert from absolute to one with placeholders
    13171303
    1318     my ($collection_path, $collect_dir, $site_dir, $gs_home) = @_;
    1319 
    1320     return $path unless is_abs_path($path); # path is relative
     1304    return $path unless is_abs_path_any_os($path); # path is relative
    13211305   
    13221306    # now we know we're dealing with absolute paths and have to replace gs prefixes with placeholders
    13231307
    1324     my @gs_paths = ($collection_path, $collect_dir, $site_dir, $gs_home); # list in this order: from longest to shortest path
    1325 
    1326     my %placeholder_map = ($gs_home => '@GSDLHOME@', # can't use double-quotes around at-sign, else perl tries to evaluate it as referring to an array
    1327                $site_dir => '@SITEHOME@',
    1328                $collect_dir => '@COLLECTHOME@',
    1329                $collection_path => '@THISCOLLECTPATH@'
     1308    my $site = $ENV{'SITEHOME'} ? $ENV{'SITEHOME'} : "";
     1309    my @gs_paths = ($ENV{'GSDLCOLLECTDIR'}, $ENV{'GSDLCOLLECTHOME'}, $site, $ENV{'GREENSTONEHOME'}); # list in this order: from longest to shortest path
     1310
     1311    my %placeholder_map = ($ENV{'GREENSTONEHOME'} => '@GSDLHOME@', # can't use double-quotes around at-sign, else perl tries to evaluate it as referring to an array
     1312               $site => '@SITEHOME@',
     1313               $ENV{'GSDLCOLLECTHOME'} => '@COLLECTHOME@',
     1314               $ENV{'GSDLCOLLECTDIR'} => '@THISCOLLECTPATH@'
    13301315    );
    13311316
     
    13361321
    13371322    foreach my $gs_path (@gs_paths) {
     1323    next if($gs_path eq ""); # site can be empty
     1324
    13381325    my $re_path =  &util::filename_to_regex($gs_path); # escape for regex
    13391326
    1340     next if($re_path eq ""); # site can be empty
    1341 
    1342     if($path =~ m/^$re_path/) { # case sensitive or not for OS?
     1327    if($path =~ m/^$re_path/i) { # case sensitive or not for OS?
    13431328
    13441329        my $placeholder = $placeholder_map{$gs_path}; # get the placeholder to replace the matched path with
     
    13581343    my $path = shift(@_); # path that can contain placeholders to convert to resolved absolute path
    13591344
    1360     my ($collection_path, $collect_dir, $site_dir, $gs_home) = @_;
    1361 
    13621345    return $path if($path !~ m/@/); # path contains no placeholders
    13631346   
    13641347    # replace placeholders with gs prefixes
    1365 
     1348    my $site = $ENV{'SITEHOME'} ? $ENV{'SITEHOME'} : "";
    13661349    my @placeholders = ('@THISCOLLECTPATH@', '@COLLECTHOME@', '@SITEHOME@', '@GSDLHOME@'); # order of paths not crucial in this case,
    13671350                       # but listed here from longest to shortest once placeholders are have been resolved
    13681351
    1369     my %placeholder_to_gspath_map = ('@GSDLHOME@' => $gs_home, # can't use double-quotes around at-sign, else perl tries to evaluate it as referring to an array
    1370                '@SITEHOME@' => $site_dir,
    1371                '@COLLECTHOME@' => $collect_dir,
    1372                '@THISCOLLECTPATH@' => $collection_path
     1352    my %placeholder_to_gspath_map = ('@GSDLHOME@' => $ENV{'GREENSTONEHOME'}, # can't use double-quotes around at-sign, else perl tries to evaluate it as referring to an array
     1353               '@SITEHOME@' => $site,
     1354               '@COLLECTHOME@' => $ENV{'GSDLCOLLECTHOME'},
     1355               '@THISCOLLECTPATH@' => $ENV{'GSDLCOLLECTDIR'}
    13731356    );
    13741357
Note: See TracChangeset for help on using the changeset viewer.