From f7ce960b96de7df4424f093ec1a6156b830998d4 Mon Sep 17 00:00:00 2001 From: Rob Vermaas Date: Tue, 10 Aug 2010 13:11:41 +0000 Subject: [PATCH] hydra: make sure viewing logs works when logs are bz2'd --- src/lib/Hydra/Controller/Build.pm | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/lib/Hydra/Controller/Build.pm b/src/lib/Hydra/Controller/Build.pm index f71462c0..7e69b79b 100644 --- a/src/lib/Hydra/Controller/Build.pm +++ b/src/lib/Hydra/Controller/Build.pm @@ -106,11 +106,16 @@ sub view_log : Chained('build') PathPart('log') { sub showLog { my ($c, $path, $mode) = @_; - notFound($c, "Log file $path no longer exists.") unless -f $path; + my $fallbackpath = -f $path ? $path : "$path.bz2"; + + notFound($c, "Log file $path no longer exists.") unless -f $fallbackpath; + $path = $fallbackpath; + + my $pipestart = ($path =~ /.bz2$/ ? "cat $path | bzip2 -d" : "cat $path") ; if (!$mode) { # !!! quick hack - my $pipeline = ($path =~ /.bz2$/ ? "cat $path | bzip2 -d" : "cat $path") + my $pipeline = $pipestart . " | nix-log2xml | xsltproc " . $c->path_to("xsl/mark-errors.xsl") . " -" . " | xsltproc " . $c->path_to("xsl/log2html.xsl") . " - | tail -n +2"; @@ -119,11 +124,12 @@ sub showLog { } elsif ($mode eq "raw") { - $c->serve_static_file($path); + $c->stash->{'plain'} = { data => (scalar `$pipestart`) || " " }; + $c->forward('Hydra::View::Plain'); } elsif ($mode eq "tail") { - $c->stash->{'plain'} = { data => (scalar `tail -n 50 $path`) || " " }; + $c->stash->{'plain'} = { data => (scalar `$pipestart | tail -n 50`) || " " }; $c->forward('Hydra::View::Plain'); }