Changeset 22873

Show
Ignore:
Timestamp:
07.09.2010 14:39:06 (9 years ago)
Author:
kjdon
Message:

new subroutine get_timestamped_tmp_filename_in_collection, which does just that

Files:
1 modified

Legend:

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

    r22856 r22873  
    663663} 
    664664 
     665sub get_timstamped_tmp_filename_in_collection 
     666{ 
     667 
     668    my ($input_filename, $output_ext) = @_; 
     669    # derive tmp filename from input filename 
     670    my ($tailname, $dirname, $suffix) 
     671    = &File::Basename::fileparse($input_filename, "\\.[^\\.]+\$"); 
     672 
     673    # softlink to collection tmp dir 
     674    my $tmp_dirname = $dirname; 
     675    if(defined $ENV{'GSDLCOLLECTDIR'}) { 
     676    $tmp_dirname = $ENV{'GSDLCOLLECTDIR'}; 
     677    } elsif(defined $ENV{'GSDLHOME'}) { 
     678    $tmp_dirname = $ENV{'GSDLHOME'}; 
     679    } 
     680 
     681    $tmp_dirname = &util::filename_cat($tmp_dirname, "tmp"); 
     682    &util::mk_dir($tmp_dirname) if (!-e $tmp_dirname); 
     683 
     684    # add the timestamp into the path otherwise we can run into problems  
     685    # if documents have the same name 
     686    my $timestamp = time; 
     687    my $time_tmp_dirname = &util::filename_cat($tmp_dirname, $timestamp); 
     688    $tmp_dirname = $time_tmp_dirname; 
     689    my $i = 1; 
     690    while (-e $tmp_dirname) { 
     691    $tmp_dirname = "$time_tmp_dirname$i"; 
     692    $i++; 
     693    } 
     694    &util::mk_dir($tmp_dirname); 
     695  
     696 
     697    # following two steps copied from ConvertBinaryFile 
     698    #$tailname = $self->SUPER::filepath_to_utf8($tailname) unless &unicode::check_is_utf8($tailname); 
     699 
     700    # URLEncode this since htmls with images where the html filename is utf8 don't seem 
     701    # to work on Windows (IE or Firefox), as browsers are looking for filesystem-encoded 
     702    # files on the filesystem. 
     703    #$tailname = &util::rename_file($tailname, $self->{'file_rename_method'}, "without_suffix"); 
     704    if (defined $output_ext) { 
     705    $output_ext = ".$output_ext"; # add the dot 
     706    } else { 
     707    $output_ext = $suffix; 
     708    } 
     709    $output_ext= lc($output_ext); 
     710    my $tmp_filename = &util::filename_cat($tmp_dirname, "$tailname$output_ext"); 
     711     
     712    return $tmp_filename; 
     713} 
     714 
    665715sub get_toplevel_tmp_dir 
    666716{