forked from lix-project/hydra
Merge pull request #103 from civodul/nar-uncompressed
Don't compress already-compressed files.
This commit is contained in:
commit
9d7c14b342
2 changed files with 17 additions and 2 deletions
|
@ -2,6 +2,7 @@ package Hydra::View::NARInfo;
|
|||
|
||||
use strict;
|
||||
use base qw/Catalyst::View/;
|
||||
use Hydra::View::NixNAR;
|
||||
use File::Basename;
|
||||
use Nix::Store;
|
||||
|
||||
|
@ -17,7 +18,7 @@ sub process {
|
|||
my $info;
|
||||
$info .= "StorePath: $storePath\n";
|
||||
$info .= "URL: nar/" . basename $storePath. "\n";
|
||||
$info .= "Compression: bzip2\n";
|
||||
$info .= "Compression: " . file_compression $storePath . "\n";
|
||||
$info .= "NarHash: $narHash\n";
|
||||
$info .= "NarSize: $narSize\n";
|
||||
$info .= "References: " . join(" ", map { basename $_ } @{$refs}) . "\n";
|
||||
|
|
|
@ -3,16 +3,30 @@ package Hydra::View::NixNAR;
|
|||
use strict;
|
||||
use base qw/Catalyst::View/;
|
||||
|
||||
sub file_compression {
|
||||
my ($file) = $@_;
|
||||
|
||||
if /\\.(gz|bz2|xz|lz|zip)/
|
||||
return "none";
|
||||
else
|
||||
return "bzip2";
|
||||
}
|
||||
|
||||
sub process {
|
||||
my ($self, $c) = @_;
|
||||
|
||||
my $storePath = $c->stash->{storePath};
|
||||
my $compression = file_compression($storePath);
|
||||
|
||||
$c->response->content_type('application/x-nix-archive'); # !!! check MIME type
|
||||
$c->response->content_length(-s $storePath) if ($compression == "none");
|
||||
|
||||
my $fh = new IO::Handle;
|
||||
|
||||
open $fh, "nix-store --dump '$storePath' | bzip2 |";
|
||||
if ($compression == "none")
|
||||
open $fh, "nix-store --dump '$storePath' |";
|
||||
else
|
||||
open $fh, "nix-store --dump '$storePath' | bzip2 |";
|
||||
|
||||
$c->response->body($fh);
|
||||
|
||||
|
|
Loading…
Reference in a new issue