Changeset 24932


Ignore:
Timestamp:
01/10/12 16:18:19 (9 years ago)
Author:
ak19
Message:

Diego noticed how the metadata in a toplevel metadata.xml, which specifies metadata for files in import's subfolders, does not get attached to the files on Windows, while this works on Linux. It had to do with the difference between the file slashes used on the OS versus the URL-type fileslashes used in the metadata.xml Diego had constructed. This has now been fixed and Dr Bainbridge came up with a tidier solution of a new method in util.pm that would handle the details.

Location:
main/trunk/greenstone2/perllib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/plugins/DirectoryPlugin.pm

    r24829 r24932  
    382382    $dirname = &util::filename_cat ($base_dir, $file) if $base_dir =~ /\w/;
    383383    }
    384 
     384   
    385385    my $directory_ok = $self->check_directory_path($dirname);
    386386    return $directory_ok unless (defined $directory_ok && $directory_ok == 1);
     
    424424
    425425
    426     my $os_dirsep = &util::get_os_dirsep();
     426    my $os_dirsep = &util::get_os_dirsep();
    427427    my $dirsep    = &util::get_dirsep();
    428428    my $base_dir_regexp = $base_dir;
    429429    $base_dir_regexp =~ s/\//$os_dirsep/g;
    430     my $local_dirname = $dirname;
    431    
    432     $local_dirname =~ s/^$base_dir_regexp($os_dirsep)*//;
     430       
     431    # Want to get relative path of local_dirname within the base_directory
     432    # but with URL style slashes.
     433    my $local_dirname = &util::filename_within_directory_url_format($dirname, $base_dir);
     434
    433435    # if we are in import folder, then local_dirname will be empty
    434436    if ($local_dirname ne "") {
    435     # look for extra metadata passed down from higher folders
    436     $local_dirname .= $dirsep;
     437    # look for extra metadata passed down from higher folders  
     438    $local_dirname .= "/"; # closing slash must be URL type slash also and not $dirsep;
    437439    if (defined $self->{'subdir_extrametakeys'}->{$local_dirname}) {
    438440        my $extrakeys = $self->{'subdir_extrametakeys'}->{$local_dirname};
     
    491493
    492494        my $subdir_extrametakeys = $self->{'subdir_extrametakeys'};
    493 
     495       
    494496        my $subdir_rec = { 're' => $subdir_re, 'md' => $md, 'mf' => $mf };
    495497
  • main/trunk/greenstone2/perllib/util.pm

    r24874 r24932  
    845845    $filename =~ s@\(@\\(@g; # escape brackets
    846846    $filename =~ s@\)@\\)@g; # escape brackets
     847    $filename =~ s@\[@\\[@g; # escape brackets
     848    $filename =~ s@\]@\\]@g; # escape brackets
    847849   
    848850    return $filename;
     
    857859    $filename =~ s@\\\(@(@g; # remove RE syntax for ( => "\(" turns into "("
    858860    $filename =~ s@\\\)@)@g; # remove RE syntax for ) => "\)" turns into ")"
     861    $filename =~ s@\\\[@[@g; # remove RE syntax for [ => "\[" turns into "["
     862    $filename =~ s@\\\]@]@g; # remove RE syntax for ] => "\]" turns into "]"
    859863    return $filename;
    860864}
     
    10321036}
    10331037
    1034 
     1038# If filename is relative to within_dir, returns the relative path of filename to that directory
     1039# with slashes in the filename returned as they were in the original (absolute) filename.
    10351040sub filename_within_directory
    10361041{
     
    10491054    return $filename;
    10501055}
     1056
     1057# If filename is relative to within_dir, returns the relative path of filename to that directory in URL format.
     1058# Filename and within_dir can be any type of slashes, but will be compared as URLs (i.e. unix-style slashes).
     1059# The subpath returned will also be a URL type filename.
     1060sub filename_within_directory_url_format
     1061{
     1062    my ($filename,$within_dir) = @_;
     1063   
     1064    # convert parameters only to / slashes if Windows
     1065   
     1066    my $filename_urlformat = $filename;
     1067    my $within_dir_urlformat = $within_dir;
     1068   
     1069    if ($ENV{'GSDLOS'} =~ /^windows$/i) {
     1070        # Only need to worry about Windows, as Unix style directories already in url-format
     1071        # Convert Windows style \ => /
     1072        $filename_urlformat =~ s@\\@/@g;
     1073        $within_dir_urlformat =~ s@\\@/@g;
     1074    }
     1075   
     1076    #if ($within_dir_urlformat !~ m/\/$/) {
     1077        # make sure directory ends with a slash
     1078        #$within_dir_urlformat .= "/";
     1079    #}
     1080   
     1081    my $within_dir_urlformat_re = &filename_to_regex($within_dir_urlformat); # escape any special RE characters, such as brackets
     1082   
     1083    #print STDERR "@@@@@ $filename_urlformat =~ $within_dir_urlformat_re\n";
     1084   
     1085    # dir prefix may or may not end with a slash (this is discarded when extracting the sub-filepath)
     1086    if ($filename_urlformat =~ m/^$within_dir_urlformat_re(?:\/)*(.*)$/) {
     1087        $filename_urlformat = $1;
     1088    }
     1089   
     1090    return $filename_urlformat;
     1091}
     1092
    10511093
    10521094sub filename_within_collection
Note: See TracChangeset for help on using the changeset viewer.