Show
Ignore:
Timestamp:
16.06.2016 19:20:23 (3 years ago)
Author:
ak19
Message:

Improving dispersed GS3: changes to util.pm fix the bug whereby the perl code always write to gs2build\tmp when building, even if the Greenstone folder is not writable. Now the TMP env var location is used and the tmp files get written to TMP\greenstone\web when the GS folder is not writable. Further tidied up bat and cmd files to remove extra variables, to break out of loop reading in build.properties file when the necessary properties are found.

Files:
1 modified

Legend:

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

    r30561 r30574  
    234234 
    235235 
     236# works out the temporary directory, including in the case where Greenstone is not writable 
     237# In that case, gs3-setup.bat would already have set the GS_TMP_OUTPUT_DIR temp variable 
     238sub determine_tmp_dir 
     239{ 
     240    my $try_collect_dir = shift(@_) || 0; 
     241 
     242    my $tmp_dirname; 
     243    if(defined $ENV{'GS_TMP_OUTPUT_DIR'}) { 
     244        $tmp_dirname = $ENV{'GS_TMP_OUTPUT_DIR'}; 
     245    } elsif($try_collect_dir && defined $ENV{'GSDLCOLLECTDIR'}) { 
     246        $tmp_dirname = $ENV{'GSDLCOLLECTDIR'}; 
     247    } elsif(defined $ENV{'GSDLHOME'}) { 
     248        $tmp_dirname = $ENV{'GSDLHOME'}; 
     249    } else { 
     250        return undef; 
     251    } 
     252     
     253    if(!defined $ENV{'GS_TMP_OUTPUT_DIR'}) { 
     254        # test the tmp_dirname folder is writable, by trying to write out a file 
     255        # Unfortunately, cound not get if(-w $dirname) to work on directories on Windows 
     256            ## http://alvinalexander.com/blog/post/perl/perl-file-test-operators-reference-cheat-sheet (test file/dir writable) 
     257            ## http://www.makelinux.net/alp/083 (real and effective user IDs) 
     258         
     259        my $tmp_test_file = &FileUtils::filenameConcatenate($tmp_dirname, "writability_test.tmp"); 
     260        if (open (FOUT, $tmp_test_file)) { 
     261            close(FOUT); 
     262            &FileUtils::removeFiles($tmp_test_file); 
     263        } else { # location not writable, use TMP location 
     264            $tmp_dirname = &FileUtils::filenameConcatenate($ENV{'TMP'}, "greenstone"); 
     265            $ENV{'GS_TMP_OUTPUT_DIR'} = $tmp_dirname; # store for next time 
     266        } 
     267    } 
     268     
     269    $tmp_dirname = &FileUtils::filenameConcatenate($tmp_dirname, "tmp"); 
     270    &FileUtils::makeAllDirectories ($tmp_dirname) unless -e $tmp_dirname; 
     271 
     272    return $tmp_dirname; 
     273} 
     274 
    236275sub get_tmp_filename  
    237276{ 
     
    251290    } 
    252291 
    253     my $tmpdir = &FileUtils::filenameConcatenate($ENV{'GSDLHOME'}, "tmp"); 
    254     &FileUtils::makeAllDirectories ($tmpdir) unless -e $tmpdir; 
     292    my $tmpdir = &util::determine_tmp_dir(0); 
    255293 
    256294    my $count = 1000; 
     
    274312sub get_timestamped_tmp_folder 
    275313{ 
    276      
    277     my $tmp_dirname; 
    278     if(defined $ENV{'GSDLCOLLECTDIR'}) { 
    279     $tmp_dirname = $ENV{'GSDLCOLLECTDIR'}; 
    280     } elsif(defined $ENV{'GSDLHOME'}) { 
    281     $tmp_dirname = $ENV{'GSDLHOME'}; 
    282     } else { 
    283     return undef; 
    284     } 
    285  
    286     $tmp_dirname = &FileUtils::filenameConcatenate($tmp_dirname, "tmp"); 
    287     &FileUtils::makeDirectory($tmp_dirname) if (!-e $tmp_dirname); 
    288  
     314    my $tmp_dirname = &util::determine_tmp_dir(1); 
     315     
    289316    # add the timestamp into the path otherwise we can run into problems  
    290317    # if documents have the same name