From 8b752627a23cd359797e600db8c5e201c931b6f7 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 11 Mar 2009 14:44:34 +0000 Subject: [PATCH] * Use IO::Handles instead of old school filehandles. This ensures that the pipe gets closed, and the child process dies, if the HTTP connection is prematurely interrupted. --- src/lib/Hydra/View/NixClosure.pm | 5 ++--- src/lib/Hydra/View/NixDepGraph.pm | 5 ++--- src/lib/Hydra/View/NixNAR.pm | 7 ++----- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/lib/Hydra/View/NixClosure.pm b/src/lib/Hydra/View/NixClosure.pm index ec820b6d..bda483df 100644 --- a/src/lib/Hydra/View/NixClosure.pm +++ b/src/lib/Hydra/View/NixClosure.pm @@ -11,10 +11,9 @@ sub process { my @storePaths = @{$c->stash->{storePaths}}; - open(OUTPUT, "nix-store --export `nix-store -qR @storePaths` | gzip |"); - my $fh = new IO::Handle; - $fh->fdopen(fileno(OUTPUT), "r") or die; + + open $fh, "nix-store --export `nix-store -qR @storePaths` | gzip |"; $c->response->body($fh); diff --git a/src/lib/Hydra/View/NixDepGraph.pm b/src/lib/Hydra/View/NixDepGraph.pm index 03c9aa16..55af1d33 100644 --- a/src/lib/Hydra/View/NixDepGraph.pm +++ b/src/lib/Hydra/View/NixDepGraph.pm @@ -11,10 +11,9 @@ sub process { my @storePaths = @{$c->stash->{storePaths}}; - open(OUTPUT, "nix-store --query --graph @storePaths | dot -Tpng -Gbgcolor=transparent |"); - my $fh = new IO::Handle; - $fh->fdopen(fileno(OUTPUT), "r") or die; + + open $fh, "nix-store --query --graph @storePaths | dot -Tpng -Gbgcolor=transparent |"; $c->response->body($fh); diff --git a/src/lib/Hydra/View/NixNAR.pm b/src/lib/Hydra/View/NixNAR.pm index 4022431d..49bb27b6 100644 --- a/src/lib/Hydra/View/NixNAR.pm +++ b/src/lib/Hydra/View/NixNAR.pm @@ -10,15 +10,12 @@ sub process { $c->response->content_type('application/x-nix-archive'); # !!! check MIME type - open(OUTPUT, "nix-store --dump '$storePath' | bzip2 |"); - my $fh = new IO::Handle; - $fh->fdopen(fileno(OUTPUT), "r") or die; + + open $fh, "nix-store --dump '$storePath' | bzip2 |"; $c->response->body($fh); - undef $fh; - return 1; }