Ignore:
Timestamp:
2012-01-24T16:19:58+13:00 (12 years ago)
Author:
ak19
Message:
  1. Introduced the util::filepath_to_url_format subroutine which will be used to convert filenames to URL style filenames to match the slashes used in the filename regex-es in extrameta keys used to index into extrameta data structures. 2. Fixed bug on windows where metadata.xml specifies filenames as regex with backslash in front of the file extension's period mark: DirectoryPlugin needed to unregex the filepath before calling fileparse on it, else the escaping backslash would interfere with perl's fileparse routine (only on windows, since backslash also represents a dirsep here). 3. Updated all those perl plugins where the new util::filepath_to_url_format needs to be called so that they use URL style filenames (thereafter regexed) to index into the extrameta data structures.
File:
1 edited

Legend:

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

    r24940 r24971  
    837837    my $filename = shift (@_);
    838838
    839     # need to put single backslash back to double so that regex works
     839    # need to make single backslashes double so that regex works
    840840    $filename =~ s/\\/\\\\/g; # if ($ENV{'GSDLOS'} =~ /^windows$/i);   
    841841   
     
    10671067    # convert parameters only to / slashes if Windows
    10681068   
    1069     my $filename_urlformat = $filename;
    1070     my $within_dir_urlformat = $within_dir;
    1071    
    1072     if ($ENV{'GSDLOS'} =~ /^windows$/i) {
    1073         # Only need to worry about Windows, as Unix style directories already in url-format
    1074         # Convert Windows style \ => /
    1075         $filename_urlformat =~ s@\\@/@g;
    1076         $within_dir_urlformat =~ s@\\@/@g;
    1077     }
    1078    
     1069    my $filename_urlformat = &filepath_to_url_format($filename);
     1070    my $within_dir_urlformat = &filepath_to_url_format($within_dir);
     1071
    10791072    #if ($within_dir_urlformat !~ m/\/$/) {
    10801073        # make sure directory ends with a slash
     
    10921085   
    10931086    return $filename_urlformat;
     1087}
     1088
     1089# Convert parameter to use / slashes if Windows (if on Linux leave any \ as is,
     1090# since on Linux it doesn't represent a file separator but an escape char).
     1091sub filepath_to_url_format
     1092{
     1093    my ($filepath) = @_;
     1094    if ($ENV{'GSDLOS'} =~ /^windows$/i) {
     1095        # Only need to worry about Windows, as Unix style directories already in url-format
     1096        # Convert Windows style \ => /
     1097        $filepath =~ s@\\@/@g;     
     1098    }
     1099    return $filepath;
    10941100}
    10951101
Note: See TracChangeset for help on using the changeset viewer.