Changeset 31514
- Timestamp:
- 2017-03-14T18:54:14+13:00 (7 years ago)
- Location:
- main/trunk/greenstone2/perllib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/perllib/servercontrol.pm
r31513 r31514 140 140 141 141 my $wget_file_path = &FileUtils::filenameConcatenate($ENV{'GSDLHOME'}, "bin", $ENV{'GSDLOS'}, "wget"); 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 142 my $tmpfilename = &util::get_tmp_filename(".html"); # random file name with html extension in tmp location in which we'll store the HTML page retrieved by wget 143 145 144 # https://www.gnu.org/software/wget/manual/wget.html 146 145 # output-document set to - (STDOUT), so page is streamed to STDOUT … … 154 153 155 154 ##print STDERR "@@@@ $wgetCommand\n"; 156 157 my $response_content = `$wgetCommand`;155 156 my $response_content; 158 157 my $response_code = undef; 158 #my $response_content = `$wgetCommand`; # Dr Bainbridge advises against using backticks for running a process. If capturing std output, use open(): 159 if (open(PIN, "$wgetCommand |")) { 160 while (defined (my $perl_output_line = <PIN>)) { 161 $response_content = $response_content . $perl_output_line; 162 } 163 close(PIN); 164 } else { 165 print STDERR "servercontrol.pm::config() failed to run $wgetCommand\n"; 166 } 167 168 159 169 my @lines = split( /\n/, $response_content ); 160 170 foreach my $line (@lines) { … … 182 192 # server not running 183 193 $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 file194 &FileUtils::removeFiles($tmpfilename); # get rid of the ping response's temporary html file we downloaded 185 195 return 0; 186 196 } … … 197 207 sysread(FIN, $resultstr, -s FIN); 198 208 close(FIN); 199 & util::rm_tmp_file($tmpfilename); # will also remove any randomly named tmp directories containing the file209 &FileUtils::removeFiles($tmpfilename); # get rid of the ping response's temporary html file we downloaded 200 210 201 211 -
main/trunk/greenstone2/perllib/util.pm
r31513 r31514 276 276 { 277 277 my $file_ext = shift(@_) || undef; 278 my $use_timestamped_tmp_dir = shift(@_) || 0; # else defaults to using super directory named "tmp"279 278 280 279 my $opt_dot_file_ext = ""; … … 291 290 } 292 291 293 my $tmpdir = $use_timestamped_tmp_dir ? &util::get_timestamped_tmp_folder() :&util::determine_tmp_dir(0);292 my $tmpdir = &util::determine_tmp_dir(0); 294 293 295 294 my $count = 1000; … … 387 386 388 387 return $tmp_dirname; 389 }390 391 sub rm_tmp_file392 {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 it399 # but not if it is the temporary "tmp" super directory itself.400 if($tmpdir !~ m@^tmp(\\|\/)*$@) {401 &FileUtils::removeFilesRecursive($tmpdir);402 }403 388 } 404 389 … … 1298 1283 my $host = $uri->host; 1299 1284 #print STDERR "@@@@@ host: $host\n"; 1300 if($url =~ m/http :\/\/$host(\/)?$/) {1285 if($url =~ m/https?:\/\/$host(\/)?$/) { 1301 1286 #if($url !~ m/http:\/\/$host:$portnumber(\/)?/ || $url =~ m/http:\/\/$host(\/)?$/) { 1302 1287 # (if the URL does not contain the portnumber, OR if the port is implicitly 80 and) … … 1338 1323 while (defined (my $perl_output_line = <PIN>)) { 1339 1324 1340 if($perl_output_line =~ m@ http:\/\/(\S*)@) { # grab all the non-whitespace chars1341 $url=" http://".$1;1325 if($perl_output_line =~ m@(https?):\/\/(\S*)@) { # grab all the non-whitespace chars 1326 $url="$1://".$2; # preserve the http protocol #$url="http://".$1; 1342 1327 } 1343 1328 } … … 1345 1330 } else { 1346 1331 print STDERR "util::get_library_URL() failed to run $perl_command to work out library URL for $gs_mode\n"; 1347 } 1332 } 1348 1333 } 1349 1334
Note:
See TracChangeset
for help on using the changeset viewer.