Changeset 25094


Ignore:
Timestamp:
02/16/12 15:10:43 (9 years ago)
Author:
kjdon
Message:

extrametadata must have url style filepaths, ie / for dirsep. and they are regex. FileName entires in metadata.xml must be regex, but they allow
on windows for dirsep, which we convert to /

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

Legend:

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

    r24971 r25094  
    482482    # filter out any extrametakeys that mention subdirectories and store
    483483    # for later use (i.e. when that sub-directory is being processed)
    484     foreach my $ek (@extrametakeys) { # where each Extrametakey (which is a filename) is stored as a regex
    485     my $ek_non_re = &util::unregex_filename($ek); # unregex it. This step is *also* required for the fileparse operation since the file suffix
    486                                                   # will be specified as \.txt and we don't want fileparse to split it there making \.txt the "filename"
    487     my ($subdir_re,$extrakey_dir) = &File::Basename::fileparse($ek_non_re);     
    488     my $dirsep_re = &util::get_re_dirsep();
    489     if ($ek_non_re =~ m/$dirsep_re/) { # specifies at least one directory
     484    foreach my $ek (@extrametakeys) { # where each Extrametakey (which is a filename) is stored as a  url-style regex
     485   
     486    my ($subdir_re,$extrakey_dir) = &util::url_fileparse($ek);
     487   
     488    if ($extrakey_dir ne "") {
     489        # a subdir was specified
    490490        my $md = &extrametautil::getmetadata(\%extrametadata, $ek);
    491491        my $mf = &extrametautil::getmetafile(\%extrametafile, $ek);
    492492
    493493        my $subdir_extrametakeys = $self->{'subdir_extrametakeys'};
    494        
    495     # Indexing into the extrameta data structures requires the filename's style of slashes to be in URL format
    496     # Then need to convert the filename to a regex, no longer to protect windows directory chars \, but for
    497     # protecting special characters like brackets in the filepath such as "C:\Program Files (x86)\Greenstone".
    498     $subdir_re = &util::filepath_to_url_format($subdir_re); # Possibly not necessary since subdir_re is the last segment of the filepath $ek ####
    499     $subdir_re = &util::filename_to_regex($subdir_re);      # Escape any special chars like brackets and . in subdir_re
    500        
    501494        my $subdir_rec = { 're' => $subdir_re, 'md' => $md, 'mf' => $mf };
    502495
    503496        # when it's looked up, it must be relative to the base dir
    504497        push(@{$subdir_extrametakeys->{"$local_dirname$extrakey_dir"}},$subdir_rec);
    505         #push(@{$subdir_extrametakeys->{"$extrakey_dir"}},$subdir_rec);
    506498    }
    507499    }
  • main/trunk/greenstone2/perllib/plugins/MetadataXMLPlugin.pm

    r24971 r25094  
    158158    $self->{'in_filename'} = 0;
    159159   
    160    
    161160    return bless $self, $class;
    162161}
     
    329328    foreach my $target (@{$self->{'saved_targets'}}) {
    330329   
    331         # Indexing into the extrameta data structures requires the filename's style of slashes to be in URL
    332         # format. But if metadata.xml was user-constructed, its FileName fields (stored in the saved_targets
    333         # map) could represent pathnames in Windows format using \ as file separator, instead of pathnames
    334         # being in URL format as Greenstone would've generated. Need to convert such filepaths to URL style
    335         # paths. Then need convert this to a regex to protect special characters like brackets in the
    336         # filepath, such as "C:\Program Files (x86)\Greenstone".
    337        
    338         $target = &util::unregex_filename($target); # filename is a regex, before converting it to URL form, unregex it
    339         $target = &util::filepath_to_url_format($target); # convert to URL form
    340         $target = &util::filename_to_regex($target); # regex it. Now we have regexed URL form of filename
    341    
    342         my $file_metadata = &extrametautil::getmetadata($self->{'metadataref'}, $target);
     330        # FileNames must be regex, but we allow \\ for path separator on windows. convert to /
     331        $target = &util::filepath_regex_to_url_format($target);
     332        my $file_metadata = &extrametautil::getmetadata($self->{'metadataref'}, $target);
    343333        my $saved_metadata = $self->{'saved_metadata'};
    344334
Note: See TracChangeset for help on using the changeset viewer.