Changeset 31513

Show
Ignore:
Timestamp:
14.03.2017 15:30:24 (2 years ago)
Author:
ak19
Message:

servercontrol.pm uses established functions to generate tmpfiles in tmp directories, and then immediately deletes them after using them. Made some modifications for this in util.pm and added some extra helper functions there.

Location:
main/trunk/greenstone2/perllib
Files:
2 modified

Legend:

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

    r31507 r31513  
    140140 
    141141    my $wget_file_path = &FileUtils::filenameConcatenate($ENV{'GSDLHOME'}, "bin", $ENV{'GSDLOS'}, "wget"); 
    142     my $tmpfilename = time . ".html"; # random name for file wherein we'll store the HTML page retrieved by wget 
    143      
     142    my $tmpfilename = &util::get_tmp_filename(".html", 1); # random file name with html extension in timestamped-tmpdir location (2nd param=1)  
     143                                                            # wherein we'll store the HTML page retrieved by wget 
     144         
    144145    # https://www.gnu.org/software/wget/manual/wget.html 
    145146    # output-document set to - (STDOUT), so page is streamed to STDOUT 
     
    181182        # server not running 
    182183        $self->print_msg("*** Server not running. $library_url$command\n", 3); 
     184        &util::rm_tmp_file($tmpfilename); # will also remove any randomly named tmp directories containing the file 
    183185        return 0; 
    184186    } 
     
    195197        sysread(FIN, $resultstr, -s FIN);        
    196198        close(FIN); 
    197         &FileUtils::removeFiles("$tmpfilename"); 
     199        &util::rm_tmp_file($tmpfilename); # will also remove any randomly named tmp directories containing the file 
     200         
    198201         
    199202        #$resultstr =~ s@.*gs_content\"\>@@s;   ## only true for default library servlet     
  • main/trunk/greenstone2/perllib/util.pm

    r31475 r31513  
    276276{ 
    277277    my $file_ext = shift(@_) || undef; 
     278    my $use_timestamped_tmp_dir = shift(@_) || 0; # else defaults to using super directory named "tmp" 
    278279 
    279280    my $opt_dot_file_ext = ""; 
     
    290291    } 
    291292 
    292     my $tmpdir = &util::determine_tmp_dir(0); 
     293    my $tmpdir = $use_timestamped_tmp_dir ? &util::get_timestamped_tmp_folder() : &util::determine_tmp_dir(0); 
    293294 
    294295    my $count = 1000; 
     
    340341 
    341342    return $tmp_dirname; 
    342 } 
    343  
    344 sub get_parent_folder 
    345 { 
    346     my ($path) = @_; 
    347     my ($tailname, $dirname, $suffix) 
    348     = &File::Basename::fileparse($path, "\\.[^\\.]+\$"); 
    349  
    350     return &FileUtils::sanitizePath($dirname); 
    351343} 
    352344 
     
    397389} 
    398390 
     391sub rm_tmp_file 
     392{ 
     393    my $tmpfilename = shift(@_); 
     394     
     395    my $tmpdir = &util::get_parent_folder($tmpfilename); 
     396     
     397    &FileUtils::removeFiles($tmpfilename);   
     398    # if the containing folder is a randomly named temporary subdirectory, remove it 
     399    # but not if it is the temporary "tmp" super directory itself. 
     400    if($tmpdir !~ m@^tmp(\\|\/)*$@) { 
     401        &FileUtils::removeFilesRecursive($tmpdir); 
     402    } 
     403} 
     404 
     405sub get_parent_folder 
     406{ 
     407    my ($path) = @_; 
     408    my ($tailname, $dirname, $suffix) 
     409    = &File::Basename::fileparse($path, "\\.[^\\.]+\$"); 
     410 
     411    return &FileUtils::sanitizePath($dirname); 
     412} 
    399413 
    400414sub filename_to_regex {