Changeset 15564


Ignore:
Timestamp:
2008-05-19T12:07:11+12:00 (16 years ago)
Author:
ak19
Message:

2 changes to make this up-to-date with GS2's gliserver.pl: 1. added file-exists command and matching routine file_exists; 2. modified run_script to also deal with replace_srcdoc_with_html.pl and to escape any spaces in filenames

File:
1 edited

Legend:

Unmodified
Added
Removed
  • greenstone3/trunk/web/WEB-INF/cgi/gliserver4gs3.pl

    r14602 r15564  
    118118    while (1) { }
    119119    }
     120    elsif ($cmd eq "file-exists") {
     121    &file_exists($gsdl_cgi);
     122    }   
    120123    else {
    121124    $gsdl_cgi->generate_error("Unrecognised command: '$cmd'");
     
    542545}
    543546
     547# Method that will check if the given file exists
     548# No error message: all messages generated are OK messages
     549# This method will simply state whether the file exists or does not exist.
     550sub file_exists
     551{
     552    my ($gsdl_cgi, $username, $timestamp) = @_;
     553
     554    my ($gsdl_cgi) = @_;
     555
     556    my $collection = $gsdl_cgi->clean_param("c");
     557    if ((!defined $collection) || ($collection =~ m/^\s*$/)) {
     558    $gsdl_cgi->generate_error("No collection specified.");
     559    }
     560    my $file = $gsdl_cgi->clean_param("file");
     561    if ((!defined $file) || ($file =~ m/^\s*$/)) {
     562    $gsdl_cgi->generate_error("No file specified.");
     563    }
     564    $file =~ s/\|/&util::get_dirsep()/eg;  # Convert the '|' characters into whatever is right for this OS
     565   
     566    # Not necessary: checking whether the user is authenticated to query existance of the file
     567    #&authenticate_user($gsdl_cgi, $username, $collection);
     568
     569    my $gsdlhome = $ENV{'GSDLHOME'};
     570    my $collection_directory = &util::filename_cat($gsdlhome, "collect", $collection);
     571    $gsdl_cgi->checked_chdir($collection_directory);
     572
     573    # Check that the collection file exists
     574    if (-e $file) {
     575    $gsdl_cgi->generate_ok_message("File $file exists.");
     576    } else {
     577    $gsdl_cgi->generate_ok_message("File $file does not exist.");
     578    }
     579}
    544580
    545581sub download_collection_file
     
    862898    &lock_collection($gsdl_cgi, $username, $collection, $site) unless ($script eq "mkcol.pl");
    863899
    864     # Last argument is the collection name, except for explode_metadata_database.pl
     900    # Last argument is the collection name, except for explode_metadata_database.pl and
     901    # replace_srcdoc_with_html (where there's a "file" option followed by the filename. These two preceed the collection name)
    865902    my $perl_args = $collection;
    866     if ($script eq "explode_metadata_database.pl") {
    867     # Last argument is the file to be exploded
     903    if ($script eq "explode_metadata_database.pl" || $script eq "replace_srcdoc_with_html.pl") {
     904    # Last argument is the file to be exploded or it is the file to be replaced with its html version
    868905    my $file = $gsdl_cgi->clean_param("file");
    869906    if ((!defined $file) || ($file =~ m/^\s*$/)) {
     
    871908    }
    872909    $gsdl_cgi->delete("file");
     910    $file =~ s/ /\\ /g; # escape all spaces in filename with a backslash, i.e. "\ ".
    873911    $perl_args = $file;
    874912    }
Note: See TracChangeset for help on using the changeset viewer.