diff --git a/src/lib/Hydra/Controller/Build.pm b/src/lib/Hydra/Controller/Build.pm index f3b6f49f..b96d0f2f 100644 --- a/src/lib/Hydra/Controller/Build.pm +++ b/src/lib/Hydra/Controller/Build.pm @@ -204,8 +204,6 @@ sub download : Chained('buildChain') PathPart { } my $storePath = $1; - notFound($c, "File " . $product->path . " does not exist.") unless -e $product->path; - return $c->res->redirect(defaultUriForProduct($self, $c, $product, @path)) if scalar @path == 0 && ($product->name || $product->defaultpath); @@ -221,22 +219,32 @@ sub download : Chained('buildChain') PathPart { my $path = $product->path; $path .= "/" . join("/", @path) if scalar @path > 0; - # Make sure the file is in the Nix store. - $path = checkPath($self, $c, $path); + if (isLocalStore) { - # If this is a directory but no "/" is attached, then redirect. - if (-d $path && substr($c->request->uri, -1) ne "/") { - return $c->res->redirect($c->request->uri . "/"); + notFound($c, "File " . $product->path . " does not exist.") unless -e $product->path; + + # Make sure the file is in the Nix store. + $path = checkPath($self, $c, $path); + + # If this is a directory but no "/" is attached, then redirect. + if (-d $path && substr($c->request->uri, -1) ne "/") { + return $c->res->redirect($c->request->uri . "/"); + } + + $path = "$path/index.html" if -d $path && -e "$path/index.html"; + + notFound($c, "File $path does not exist.") if !-e $path; + + notFound($c, "Path $path is a directory.") if -d $path; + + $c->serve_static_file($path); + $c->response->headers->last_modified($c->stash->{build}->stoptime); + + } else { + $c->stash->{'plain'} = { data => readNixFile($path) }; + $c->response->content_type('application/octet-stream'); + $c->forward('Hydra::View::Plain'); } - - $path = "$path/index.html" if -d $path && -e "$path/index.html"; - - notFound($c, "File $path does not exist.") if !-e $path; - - notFound($c, "Path $path is a directory.") if -d $path; - - $c->serve_static_file($path); - $c->response->headers->last_modified($c->stash->{build}->stoptime); }