greenstone.org greenstone wiki greenstone trac planet greenstone

Changeset 16266

Show
Ignore:
Timestamp:
2008-07-02 08:51:56 (5 months ago)
Author:
davidb
Message:

get_tmp_filename() can now optionally take an argument that is the file name extension to use. Without this ImageConverter? would get a temp filename, append a .gif (or whatever) extension on to it and use this a the filename to convert an image to. The problem came when get_tmp_filename randomly generates the same filename again: when it looks to see if its random name already exists, it gets the answer no (because it doesn't use a filename extension, but the one used by ImageConverter? does). Getting modules like ImageConverter? to pass in the filename extension they plan to use fixes this.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gsdl/trunk/perllib/util.pm

    r15875 r16266  
    572572 
    573573 
    574 sub get_tmp_filename { 
     574sub get_tmp_filename  
     575
     576    my $file_ext = shift(@_) || undef; 
     577 
     578    my $opt_dot_file_ext = (defined $file_ext) ? ".$file_ext" : ""; 
     579 
    575580    my $tmpdir = filename_cat($ENV{'GSDLHOME'}, "tmp"); 
    576581    &mk_all_dir ($tmpdir) unless -e $tmpdir; 
     
    578583    my $count = 1000; 
    579584    my $rand = int(rand $count); 
    580     while (-e &filename_cat($tmpdir, "F$rand")) { 
     585    my $full_tmp_filename = &filename_cat($tmpdir, "F$rand$opt_dot_file_ext"); 
     586 
     587    while (-e $full_tmp_filename) { 
    581588        $rand = int(rand $count); 
     589        $full_tmp_filename = &filename_cat($tmpdir, "F$rand$opt_dot_file_ext"); 
    582590        $count++; 
    583591    } 
    584  
    585     return filename_cat($tmpdir, "F$rand")
     592     
     593    return $full_tmp_filename
    586594} 
    587595 
     
    591599    my (@filenames) = @_; 
    592600 
    593 #   Useful for debugging 
    594 #   my ($cpackage,$cfilename,$cline,$csubr,$chas_args,$cwantarray) = caller(0); 
     601#   Useful for debugging  
     602#     -- might make sense to call caller(0) rather than (1)?? 
     603#   my ($cpackage,$cfilename,$cline,$csubr,$chas_args,$cwantarray) = caller(1); 
    595604#   print STDERR "Calling method; $cfilename:$cline $cpackage->$csubr\n"; 
    596605