Changeset 22887

Show
Ignore:
Timestamp:
13.09.2010 11:01:23 (9 years ago)
Author:
kjdon
Message:

use new util::get_timestamped_dir, and clean_up_after_doc_processing to delete it

Files:
1 modified

Legend:

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

    r22879 r22887  
    231231 
    232232    # softlink to collection tmp dir 
    233     my $tmp_dirname = $dirname; 
    234     if(defined $ENV{'GSDLCOLLECTDIR'}) { 
    235     $tmp_dirname = $ENV{'GSDLCOLLECTDIR'}; 
    236     } elsif(defined $ENV{'GSDLHOME'}) { 
    237     $tmp_dirname = $ENV{'GSDLHOME'}; 
    238     } 
    239  
    240     $tmp_dirname = &util::filename_cat($tmp_dirname, "tmp"); 
    241     &util::mk_dir($tmp_dirname) if (!-e $tmp_dirname); 
    242  
    243     # add the timestamp into the path otherwise we can run into problems  
    244     # if documents have the same name 
    245     my $timestamp = time; 
    246     my $time_tmp_dirname = &util::filename_cat($tmp_dirname, $timestamp); 
    247     $tmp_dirname = $time_tmp_dirname; 
    248     my $i = 1; 
    249     while (-e $tmp_dirname) { 
    250     $tmp_dirname = "$time_tmp_dirname$i"; 
    251     $i++; 
    252     } 
    253     &util::mk_dir($tmp_dirname); 
    254  
    255     # The following is not necessary and will cause problems with 
    256     # replacing_srcdoc_with_html in the GSDLremote case: 
    257     # Remove any white space from filename -- no risk of name collision, and 
    258     # makes later conversion by utils simpler. Leave spaces in path... 
    259     # tidy up the filename with space, dot, hyphen between 
    260     #$tailname =~ s/\s+//g;  
    261     #$tailname =~ s/\.+//g; 
    262     #$tailname =~ s/\-+//g; 
    263  
     233    my $tmp_dirname = &util::get_timestamped_tmp_folder(); 
     234    if (defined $tmp_dirname) { 
     235    $self->{'tmp_dir'} = $tmp_dirname; 
     236    } else { 
     237    $tmp_dirname = $dirname; 
     238    } 
     239     
    264240    # convert to utf-8 otherwise we have problems with the doc.xml file later on 
    265241#    print STDERR "**** filename $tailname$suffix is already UTF8\n" if &unicode::check_is_utf8($tailname); 
     
    493469} 
    494470 
     471sub clean_up_after_doc_obj_processing { 
     472     my $self = shift(@_); 
     473 
     474     my $tmp_dir = $self->{'tmp_dir'}; 
     475     if (defined $tmp_dir && -d $tmp_dir) { 
     476     &util::rm_r($tmp_dir); 
     477     $self->{'tmp_dir'} = undef; 
     478     } 
     479      
     480 
     481} 
    4954821; 
    496483