Changeset 22896

Show
Ignore:
Timestamp:
14.09.2010 13:01:09 (9 years ago)
Author:
kjdon
Message:

fixed an odd bug. If had a metadata file directly in import folder, referring to files in a subfolder, then the metadata wouldn't be assigned. But if all of these were in a subfolder, then it would work. Problem was with local_dirname. instead of being empty for import, it was full path. Then when storing subdir_extrametakeys, local_dirname is appended to front of path to make all paths relative to base dir. But for import, this meant it was a full path. so didn't match later on. local_dirname is now empty for import folder.

Files:
1 modified

Legend:

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

    r21586 r22896  
    413413    $base_dir_regexp =~ s/\//$os_dirsep/g; 
    414414    my $local_dirname = $dirname; 
    415     $local_dirname =~ s/^$base_dir_regexp($os_dirsep)//; 
    416     $local_dirname .= $dirsep; 
    417      
    418     if (defined $self->{'subdir_extrametakeys'}->{$local_dirname}) { 
    419     my $extrakeys = $self->{'subdir_extrametakeys'}->{$local_dirname}; 
    420     foreach my $ek (@$extrakeys) { 
    421         my $extrakeys_re  = $ek->{'re'}; 
    422         my $extrakeys_md  = $ek->{'md'}; 
    423         my $extrakeys_mf  = $ek->{'mf'}; 
    424         push(@extrametakeys,$extrakeys_re); 
    425         $extrametadata{$extrakeys_re} = $extrakeys_md; 
    426         $extrametafile{$extrakeys_re} = $extrakeys_mf; 
    427     } 
    428     delete($self->{'subdir_extrametakeys'}->{$local_dirname}); 
    429     } 
    430      
     415     
     416    $local_dirname =~ s/^$base_dir_regexp($os_dirsep)*//; 
     417    # if we are in import folder, then local_dirname will be empty 
     418    if ($local_dirname ne "") { 
     419    # look for extra metadata passed down from higher folders  
     420    $local_dirname .= $dirsep; 
     421    if (defined $self->{'subdir_extrametakeys'}->{$local_dirname}) { 
     422        my $extrakeys = $self->{'subdir_extrametakeys'}->{$local_dirname}; 
     423        foreach my $ek (@$extrakeys) { 
     424        my $extrakeys_re  = $ek->{'re'}; 
     425        my $extrakeys_md  = $ek->{'md'}; 
     426        my $extrakeys_mf  = $ek->{'mf'}; 
     427        push(@extrametakeys,$extrakeys_re); 
     428        $extrametadata{$extrakeys_re} = $extrakeys_md; 
     429        $extrametafile{$extrakeys_re} = $extrakeys_mf; 
     430        } 
     431        delete($self->{'subdir_extrametakeys'}->{$local_dirname}); 
     432    } 
     433    } 
    431434    # apply metadata pass for each of the files in the directory 
    432435    my $num_files = scalar(@dir); 
     
    456459    # filter out any extrametakeys that mention subdirectories and store 
    457460    # for later use (i.e. when that sub-directory is being processed) 
    458  
    459461    foreach my $ek (@extrametakeys) { 
    460462    my ($subdir_re,$extrakey_dir) = &File::Basename::fileparse($ek); 
    461      
    462463    $extrakey_dir =~ s/\\\./\./g; # remove RE syntax for . 
    463464    $extrakey_dir =~ s/\\\\/\\/g; # remove RE syntax for \ 
     
    578579    if ($additionalmetadata == 1) { 
    579580        foreach my $filespec (@extrametakeys) { 
    580          
    581581        ## use the utf8 encoded filename to do the filename comparison 
    582582        if ($tmpfile =~ /^$filespec$/) {