Changeset 15167

Show
Ignore:
Timestamp:
02.04.2008 18:15:29 (11 years ago)
Author:
ak19
Message:

Modified tmp_area_convert_file routine to use pass new argument ensure_path_absolute to util::soft_link to make sure soft-linking works for GSDL remote case

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • gsdl/trunk/perllib/plugins/TEXTPlug.pm

    r15150 r15167  
    150150    = &File::Basename::fileparse($input_filename, "\\.[^\\.]+\$"); 
    151151 
    152     # softlink to collection tmp dir 
     152    # Softlink to collection tmp dir 
     153    # First find a temporary directory to create the output file in 
    153154    my $tmp_dirname = $dirname; 
    154155    if(defined $ENV{'GSDLCOLLECTDIR'}) { 
     
    160161    &util::mk_dir($tmp_dirname) if (!-e $tmp_dirname); 
    161162 
    162  
    163163    # convert to utf-8 otherwise we have problems with the doc.xml file 
    164164    # later on 
    165165    &unicode::ensure_utf8(\$tailname); # TODO: does this change the filename or not? 
    166166             # need to test this out on a windows computer using a Greek filename 
    167  
     167    $suffix = lc($suffix); 
    168168    my $tmp_filename = &util::filename_cat($tmp_dirname, "$tailname$suffix");  
    169     &util::soft_link($input_filename, $tmp_filename); 
    170     # softlink symbolic link to or copy of original, so we don't accidentally damage it 
    171  
    172     #my $output_filename = $tailname$output_ext;#output_ext has to be html! 
     169     
     170    # Make sure we have the absolute path to the input file 
     171    # (If gsdl is remote, we're given relative path to input file, of the form import/tailname.suffix 
     172    # But we can't softlink to relative paths. Therefore, we need to ensure that 
     173    # the input_filename is the absolute path. 
     174    my $ensure_path_absolute = 1; # true 
     175 
     176    # Now make the softlink,  so we don't accidentally damage the input file 
     177    # softlinking creates a symbolic link to (or, if that's not possible, it makes a copy of) the original 
     178    &util::soft_link($input_filename, $tmp_filename, $ensure_path_absolute); 
     179      
     180    my $verbosity = $self->{'verbosity'}; 
     181    if ($verbosity > 0) { 
     182    # need this output statement, as GShell.java's runRemote() sets status to CANCELLED 
     183    # if there is no output! (Therefore, it only had this adverse affect when running GSDL remotely) 
     184    print $outhandle "Converting $tailname$suffix to html\n"; 
     185    } 
     186 
     187    #my $output_filename = $tailname$output_ext; #output_ext has to be html! 
    173188    my $output_filename = &util::filename_cat($tmp_dirname, $tailname.".html"); 
    174189     
    175     # read contents of text file line by line into an array 
     190    # Read contents of text file line by line into an array 
    176191    # create an HTML file from the text file 
    177192    # Recreate the original file for writing the updated contents 
    178193    unless(open(TEXT, "<$tmp_filename")) { # open it as a new file for writing 
    179     print STDERR "TEXTPlug.pm: Unable to open and read from $input_filename for converting to html...ERROR\n"; 
     194    print STDERR "TEXTPlug.pm: Unable to open and read from $tmp_filename for converting to html...ERROR: $!\n"; 
    180195    return ""; # no file name 
    181196    } 
    182197 
     198    # Read the entire file at once 
    183199    my $text; 
    184200    {  
    185     local $/ = undef; # Read entire file at once. This is from http://perl.plover.com/local.html 
    186     $text = <TEXT>;  # Now file is read in as one single 'line' 
     201    local $/ = undef; # Now can read the entire file at once. From http://perl.plover.com/local.html 
     202    $text = <TEXT>;   # File is read in as one single 'line' 
    187203    } 
    188204    close(TEXT); # close the file 
     
    196212    # try creating this new file writing and try opening it for writing, else exit with error value 
    197213    unless(open(HTML, ">$output_filename")) {  # open the new html file for writing 
    198     print STDERR "TEXTPlug.pm: Unable to create $output_filename for writing $tailname$suffix txt converted to html...ERROR\n"; 
     214    print STDERR "TEXTPlug.pm: Unable to create $output_filename for writing $tailname$suffix txt converted to html...ERROR: $!\n"; 
    199215    return ""; # no filename 
    200216    }