From 5d0baa53370ca836f6ca024e2b4082235f6a82af Mon Sep 17 00:00:00 2001 From: Stefano Zacchiroli Date: Fri, 16 Mar 2001 12:26:51 +0000 Subject: [PATCH] Fixed a bug in the case cachemode=gzipped, resourcetype=normal. (note: it's time to adopt "use strict" in http_getter.pl !!!!) --- helm/http_getter/http_getter.pl.in | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/helm/http_getter/http_getter.pl.in b/helm/http_getter/http_getter.pl.in index 67d295624..963f08220 100755 --- a/helm/http_getter/http_getter.pl.in +++ b/helm/http_getter/http_getter.pl.in @@ -23,8 +23,14 @@ # For details, see the HELM World-Wide-Web page, # http://cs.unibo.it/helm/. +#use strict; + my $VERSION = "@VERSION@"; +# various variables +my ($HELM_LIB_PATH); +my (%map); + # First of all, let's load HELM configuration use Env; my $HELM_LIB_DIR = $ENV{"HELM_LIB_DIR"}; @@ -49,8 +55,8 @@ if (($cachemode ne 'gzipped') and ($cachemode ne 'normal')) { require $HELM_LIB_PATH; # Let's override the configuration file -$style_dir = $ENV{"HELM_STYLE_DIR"} if (defined ($ENV{"HELM_STYLE_DIR"})); -$dtd_dir = $ENV{"HELM_DTD_DIR"} if (defined ($ENV{"HELM_DTD_DIR"})); +my $style_dir = $ENV{"HELM_STYLE_DIR"} if (defined ($ENV{"HELM_STYLE_DIR"})); +my $dtd_dir = $ENV{"HELM_DTD_DIR"} if (defined ($ENV{"HELM_DTD_DIR"})); use HTTP::Daemon; use HTTP::Status; @@ -518,12 +524,14 @@ sub gunzip { # gunzip a file and return the deflated content sub gzip { # gzip the content argument and save it to filename argument my ($cont, $filename) = @_; + #my $debug=1; # debug only - my ($gz, $cont); - - $gz = gzopen($filename, "w") + print "gzopening $filename ...\n" if (defined($debug)); + my $gz = gzopen($filename, "w") or die "Cannot gzopen for writing file $filename: $gzerrno"; - $gz->gzwrite($cont) or die "error writing: $gzerrno\n" ; + print "gzwriting ...\n" if (defined($debug)); + $gz->gzwrite($cont) or die "error writing: $gzerrno, exiting!\n"; + print "gzclosing ...\n" if (defined($debug)); $gz->gzclose(); } @@ -532,6 +540,8 @@ sub download my ($remove_headers,$str,$url,$filename) = @_; my ($gz, $buffer); + #my $debug=1; # for DEBUG only + my $resourcetype; # retrieve mode: "normal" (.xml) or "gzipped" (.xml.gz) if ($filename =~ /\.xml$/) { # set retrieve mode $resourcetype = "normal"; @@ -573,12 +583,17 @@ sub download # TODO: inefficent, I haven't yet undestood how to deflate # in memory gzipped file, without call "gzopen" print "Storing the $str file\n"; + print "Making dirs ...\n" if (defined($debug)); mkdirs($filename); + print "Opening tmp file for writing ...\n" if (defined($debug)); open(FD, ">".$filename.".tmp") or die "Cannot open $filename.tmp\n"; + print "Writing on tmp file ...\n" if (defined($debug)); print FD $cont; + print "Closing tmp file ...\n" if (defined($debug)); close(FD); # handle cache conversion normal->gzipped or gzipped->normal as user choice + print "cachemode:$cachemode, resourcetype:$resourcetype\n" if (defined($debug)); if (($cachemode eq 'normal') and ($resourcetype eq 'normal')) { # cache the file as is rename "$filename.tmp", $filename; @@ -597,6 +612,7 @@ sub download unlink "$filename.tmp"; # delete old gzipped file } elsif (($cachemode eq 'gzipped') and ($resourcetype eq 'normal')) { # compress cache entry + print "gzipping ...\n" if (defined($debug)); gzip($cont, $basefname.".gz"); unlink "$filename.tmp"; # delete old uncompressed file } else { -- 2.39.2