From e35f0005e612907439722f8b6bfc73773786a493 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 22 Jun 2010 12:00:19 +0000 Subject: [PATCH] * Move NARs from the NixChannel controller to the Root controller and drop the "/nix/store". I.e. instead of http://hydra.nixos.org/jobset/nixpkgs/trunk/channel/latest/nar/nix/store/99djmii6l4yw9gn07zxqabh8z58pp84c-libmspack-0.0.20040308alpha.drv we now have http://hydra.nixos.org/nar/99djmii6l4yw9gn07zxqabh8z58pp84c-libmspack-0.0.20040308alpha.drv The main reason is that this is much faster, since we don't need to get all the channel data (which isn't used anyway for NAR generation). This speeds up downloading a NAR from the Nixpkgs channel by > 2 seconds. * Drop "Hydra::View::" from view names to get rid of an ugly warning. --- src/lib/Hydra/Base/Controller/NixChannel.pm | 27 ++++----------------- src/lib/Hydra/Controller/Build.pm | 4 +-- src/lib/Hydra/Controller/Root.pm | 15 ++++++++++++ src/lib/Hydra/View/NixManifest.pm | 3 ++- 4 files changed, 24 insertions(+), 25 deletions(-) diff --git a/src/lib/Hydra/Base/Controller/NixChannel.pm b/src/lib/Hydra/Base/Controller/NixChannel.pm index 77d154f0..1d28735a 100644 --- a/src/lib/Hydra/Base/Controller/NixChannel.pm +++ b/src/lib/Hydra/Base/Controller/NixChannel.pm @@ -9,7 +9,7 @@ use Hydra::Helper::CatalystUtils; sub closure : Chained('nix') PathPart { my ($self, $c) = @_; - $c->stash->{current_view} = 'Hydra::View::NixClosure'; + $c->stash->{current_view} = 'NixClosure'; # !!! quick hack; this is to make HEAD requests return the right # MIME type. This is set in the view as well, but the view isn't @@ -20,25 +20,8 @@ sub closure : Chained('nix') PathPart { sub manifest : Chained('nix') PathPart("MANIFEST") Args(0) { my ($self, $c) = @_; - $c->stash->{current_view} = 'Hydra::View::NixManifest'; - $c->stash->{narBase} = $c->uri_for($self->action_for("nar"), $c->req->captures); -} - - -sub nar : Chained('nix') PathPart { - my ($self, $c, @rest) = @_; - - my $path .= "/" . join("/", @rest); - - if (!isValidPath($path)) { - $c->response->status(410); # "Gone" - error($c, "Path " . $path . " is no longer available."); - } - - # !!! check that $path is in the closure of $c->stash->{storePaths}. - - $c->stash->{current_view} = 'Hydra::View::NixNAR'; - $c->stash->{storePath} = $path; + $c->stash->{current_view} = 'NixManifest'; + $c->stash->{narBase} = $c->uri_for($c->controller('Root')->action_for("nar")); } @@ -54,7 +37,7 @@ sub pkg : Chained('nix') PathPart Args(1) { $c->stash->{manifestUri} = $c->uri_for($self->action_for("manifest"), $c->req->captures); - $c->stash->{current_view} = 'Hydra::View::NixPkg'; + $c->stash->{current_view} = 'NixPkg'; $c->response->content_type('application/nix-package'); } @@ -62,7 +45,7 @@ sub pkg : Chained('nix') PathPart Args(1) { sub nixexprs : Chained('nix') PathPart('nixexprs.tar.bz2') Args(0) { my ($self, $c) = @_; - $c->stash->{current_view} = 'Hydra::View::NixExprs'; + $c->stash->{current_view} = 'NixExprs'; } diff --git a/src/lib/Hydra/Controller/Build.pm b/src/lib/Hydra/Controller/Build.pm index 26310011..a08c7a28 100644 --- a/src/lib/Hydra/Controller/Build.pm +++ b/src/lib/Hydra/Controller/Build.pm @@ -266,7 +266,7 @@ sub runtimedeps : Chained('build') PathPart('runtime-deps') { notFound($c, "Path " . $build->outpath . " is no longer available.") unless isValidPath($build->outpath); - $c->stash->{current_view} = 'Hydra::View::NixDepGraph'; + $c->stash->{current_view} = 'NixDepGraph'; $c->stash->{storePaths} = [$build->outpath]; $c->res->content_type('image/png'); # !!! @@ -281,7 +281,7 @@ sub buildtimedeps : Chained('build') PathPart('buildtime-deps') { notFound($c, "Path " . $build->drvpath . " is no longer available.") unless isValidPath($build->drvpath); - $c->stash->{current_view} = 'Hydra::View::NixDepGraph'; + $c->stash->{current_view} = 'NixDepGraph'; $c->stash->{storePaths} = [$build->drvpath]; $c->res->content_type('image/png'); # !!! diff --git a/src/lib/Hydra/Controller/Root.pm b/src/lib/Hydra/Controller/Root.pm index b031da21..b67b228e 100644 --- a/src/lib/Hydra/Controller/Root.pm +++ b/src/lib/Hydra/Controller/Root.pm @@ -158,4 +158,19 @@ sub end : ActionClass('RenderView') { } +sub nar :Local :Args(1) { + my ($self, $c, $path) = @_; + + $path = "/nix/store/$path"; + + if (!isValidPath($path)) { + $c->response->status(410); # "Gone" + error($c, "Path " . $path . " is no longer available."); + } + + $c->stash->{current_view} = 'NixNAR'; + $c->stash->{storePath} = $path; +} + + 1; diff --git a/src/lib/Hydra/View/NixManifest.pm b/src/lib/Hydra/View/NixManifest.pm index b14ee36f..927cc548 100644 --- a/src/lib/Hydra/View/NixManifest.pm +++ b/src/lib/Hydra/View/NixManifest.pm @@ -26,11 +26,12 @@ sub process { # Escape the characters that are allowed to appear in a Nix # path name but have special meaning in a URI. my $escaped = $path; + $escaped =~ s/^.*\///; # remove /nix/store/ $escaped =~ s/\+/%2b/g; $escaped =~ s/\=/%3d/g; $escaped =~ s/\?/%3f/g; - my $url = $c->stash->{narBase} . $escaped; + my $url = $c->stash->{narBase} . "/" . $escaped; $manifest .= "{\n" .