From: Euler Taveira de Oliveira Date: Fri, 14 Dec 2012 13:00:52 +0000 (-0200) Subject: Fix the progress bar. It was trying to use gunzip to get real file size X-Git-Tag: v3.2~85^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=afb88a9c75314b5611a2cbc600fa86f96150559e;p=pgbadger Fix the progress bar. It was trying to use gunzip to get real file size for all formats (by default). Unbreak the bz2 format (that does not report real size) and add support for zip format. --- diff --git a/pgbadger b/pgbadger index 8695dd0..bdeb0fc 100755 --- a/pgbadger +++ b/pgbadger @@ -47,7 +47,8 @@ my $JQGRAPH = 1; my $zcat = 'zcat'; my $bzcat = 'bunzip2 -c'; my $ucat = 'unzip -p'; -my $uncompress_size = "gunzip -l %f | grep -E '^\\s*[0-9]+' | awk '{print \$2}'"; +my $gzip_uncompress_size = "gunzip -l %f | grep -E '^\\s*[0-9]+' | awk '{print \$2}'"; +my $zip_uncompress_size = "unzip -l %f | awk '{if (NR==4) print \$1}'"; my $format = ''; my $outfile = ''; my $outdir = ''; @@ -4868,11 +4869,17 @@ sub open_log_file open($lfile,"$uncompress \"$logf\" |") || die "FATAL: cannot read from pipe to $uncompress \"$logf\". $!\n"; # Real size of the file is unknown, try to find it - my $cmd_file_size = $uncompress_size; - $cmd_file_size =~ s/\%f/$logf/g; - $totalsize = `$cmd_file_size`; - chomp($totalsize); - $totalsize ||= 0; + # bz2 does not report real size + $totalsize = 0; + if ($logf =~ /\.(gz|zip)/i) { + my $cmd_file_size = $gzip_uncompress_size; + if ($logf =~ /\.zip/i) { + $cmd_file_size = $zip_uncompress_size; + } + $cmd_file_size =~ s/\%f/$logf/g; + $totalsize = `$cmd_file_size`; + chomp($totalsize); + } } return ($lfile, $totalsize);