From 6f04299411caddf632850545ed47860ea566dd03 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 31 Jul 2015 17:50:22 +0200 Subject: [PATCH] Allow downloading file by filename For instance, instead of http://.../build/3770911/download/4/source.tar.gz you can get http://.../build/3770911/download/source.tar.gz This is useful when file names are constant across builds but product numbers are not. --- 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 005902dd..98ee7364 100644 --- a/src/lib/Hydra/Controller/Build.pm +++ b/src/lib/Hydra/Controller/Build.pm @@ -197,12 +197,18 @@ sub checkPath { sub download : Chained('buildChain') PathPart { - my ($self, $c, $productnr, @path) = @_; + my ($self, $c, $productRef, @path) = @_; - $productnr = 1 if !defined $productnr; + $productRef = 1 if !defined $productRef; - my $product = $c->stash->{build}->buildproducts->find({productnr => $productnr}); - notFound($c, "Build doesn't have a product #$productnr.") if !defined $product; + my $product; + if ($productRef =~ /^[0-9]+$/) { + $product = $c->stash->{build}->buildproducts->find({productnr => $productRef}); + } else { + $product = $c->stash->{build}->buildproducts->find({name => $productRef}); + @path = ($productRef, @path); + } + notFound($c, "Build doesn't have a product $productRef.") if !defined $product; notFound($c, "Build product " . $product->path . " has disappeared.") unless -e $product->path;