Ignore:
Timestamp:
2023-12-06T22:05:16+13:00 (6 months ago)
Author:
anupama
Message:

Related to the previous commit. Calling the new subroutine to tidy up cached filename paths to avoid internal path duplication (that used to produce very long filepaths inside the cache directory). And the new subroutine finally retuns the file parameter it had been working out.

File:
1 edited

Legend:

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

    r38476 r38477  
    103103    $prefixre_to_replacere_map{qr/^$collect_dir(.*?)$/} = "";
    104104    $prefixre_to_replacere_map{qr@^$ENV{'GSDLHOME'}/tmp/[^/]*(.*?)$@} = $orig_file_root_replacere; # prefix this
    105     #%prefixre_to_replacere_map{qr//} = qr//;
    106 
     105    #$prefixre_to_replacere_map{qr/^$ENV{'GSDLHOME'}(.*?)$/} = ""; # Not found a real-world use for this yet
     106    #$prefixre_to_replacere_map{qr//} = qr//; # dummy template line to add additional regex match processing rules
     107   
    107108    my $file;
    108109   
     
    140141    $file =~ s@^(\.(\/|\/))*@@; # get rid of any ./ at the start
    141142    print STDERR "\tXXXX final file is: $file\n";
     143
     144    return $file
    142145}
    143146
     
    160163    print STDERR "@@@@ filename: $filename\n";
    161164
    162 #    $self->get_cache_filename_for_location($filename, $orig_file_root, $base_dir, $collect_dir);
    163    
    164     my ($file) = ($filename =~ m/^$base_dir(.*?)$/);
    165 
    166     print STDERR "@@@@ orig_file_root : $orig_file_root\n" if $orig_file_root;
    167     print STDERR "@@@@ file    : $file\n";
    168     print STDERR "@@@@ base_dir: $base_dir\n";
    169    
    170     if (!defined $file || $file eq $filename) {
    171     # Perhaps the filename is taken from within cache_dir area?
    172     my $cached_dir = &FileUtils::filenameConcatenate($collect_dir,"cached");
    173     ($file) = ($filename =~ m/^$cached_dir(.*?)$/);
    174     # A cached name already has the fileroot baked -in as the last directory name
    175     # => strip it out
    176         if (defined $file) {
    177             $file =~ s/[\/\\][^\/\\]+([\/\\][^\/\\]*)$/$1/;
    178         }
    179 #       Commented out code is the previous version that looked to
    180 #       handle this situation, but ran foul of situtation where
    181 #       sub-directories within 'import' are used
    182 #
    183 #   # Perhaps the filename is taken from within cache_dir area?
    184 #   my $prev_cached_dir = $self->{'cached_dir'};
    185 #   ($file) = ($filename =~ m/^$prev_cached_dir(.*?)$/);
    186     }
    187     if (!defined $file || $file eq $filename) {
    188         # perhaps the filename is in the tmp folder? This can happen if the file was in a zip inside the import folder, e.g. as happens with remote gli
    189         ($file) = ($filename =~ m/^$collect_dir\/(tmp\/.*?)$/);
    190 
    191     }
    192    
    193     print STDERR "@@@@ file mid: $file\n" if defined $file;
    194 
    195    
    196     if(!defined $file || $file eq $filename) {
    197     ($file) = ($filename =~ m/^$collect_dir(.*?)$/);   
    198     print STDERR "@@@@ file    : $file\n" if $file;
    199     }
    200     if($orig_file_root && !defined $file || $file eq $filename) {
    201         ($file) = ($filename =~ m@^$ENV{'GSDLHOME'}/tmp/[^/]*(.*?)$@);
    202         #$file = "/$orig_file_root/resized".$file if $file;
    203     $file = "/$orig_file_root".$file if $file;
    204         print STDERR "@@@@ file FIN: $file\n" if $file;
    205     }
    206     #if(!defined $file || $file eq $filename) {
    207     #   ($file) = ($filename =~ m/^$ENV{'GSDLHOME'}(.*?)$/);   
    208     #   print STDERR "@@@@ file FIN: $file\n" if $file;
    209     #}
    210     if(!defined $file) {
    211     $file = $filename;
    212     }
    213    
    214     $file =~ s/^\/|\\//; # get rid of leading slash from relative filename
    215     $file =~ s@^(\.(\/|\/))*@@; # get rid of any ./ at the start
    216    
    217     print STDERR "@@@@ FIN file : $file\n";
    218 
    219    
     165    my $file = $self->get_cache_filename_for_location($filename, $orig_file_root, $base_dir, $collect_dir);
     166
    220167    # Setup cached_dir and file_root
    221168
Note: See TracChangeset for help on using the changeset viewer.