forked from lix-project/hydra
Use "nix cat-store" to serve files from the Nix store
This makes downloading/viewing build results work with binary cache
stores. For good performance, this should be used in conjunction with
ca580bec35
,
i.e. you should set store_uri to something like
s3://my-cache?local-nar-cache=/tmp/nar-cache
to cache NARs between requests.
This commit is contained in:
parent
bc60fccf78
commit
42fbde0383
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue