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.
This commit is contained in:
Eelco Dolstra 2015-07-31 17:50:22 +02:00
parent ff3f5eb4d8
commit 6f04299411

View file

@ -197,12 +197,18 @@ sub checkPath {
sub download : Chained('buildChain') PathPart { 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}); my $product;
notFound($c, "Build doesn't have a product #$productnr.") if !defined $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; notFound($c, "Build product " . $product->path . " has disappeared.") unless -e $product->path;