[libhttp-entity-parser-perl] 02/03: new tempdir ondemand and clear parser on finalize

gregor herrmann gregoa at debian.org
Sun Oct 23 00:23:42 UTC 2016


This is an automated email from the git hooks/post-receive script.

gregoa pushed a commit to tag 0.13
in repository libhttp-entity-parser-perl.

commit 1a506bca43c9a972ccb83e24a078eb1b68e576a9
Author: Masahiro Nagano <kazeburo at gmail.com>
Date:   Sun Nov 15 15:19:13 2015 +0900

    new tempdir ondemand and clear parser on finalize
---
 lib/HTTP/Entity/Parser/MultiPart.pm | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/lib/HTTP/Entity/Parser/MultiPart.pm b/lib/HTTP/Entity/Parser/MultiPart.pm
index da9820d..d184494 100644
--- a/lib/HTTP/Entity/Parser/MultiPart.pm
+++ b/lib/HTTP/Entity/Parser/MultiPart.pm
@@ -23,11 +23,6 @@ sub new {
     }
     my $boundary = $1;
 
-    my $template = File::Spec->catdir(File::Spec->tmpdir, "HTTP-Entity-Parser-MultiPart-XXXXX");
-    my $dir = File::Temp->newdir($template, CLEANUP => 1);
-    # Temporary dir will remove after the request.
-    push @{$env->{'http.entity.parser.multipart.tempdir'}}, $dir;
-    $self->{tempdir} = "$dir";
 
     my $part;
     my $parser = HTTP::MultiPartParser->new(
@@ -57,6 +52,14 @@ sub new {
 
             if ( exists $disposition_param{filename}) {
                 $part->{filename} = $disposition_param{filename};
+                $self->{tempdir} ||= do {
+                    my $template = File::Spec->catdir(File::Spec->tmpdir, "HTTP-Entity-Parser-MultiPart-XXXXX");
+                    my $dir = File::Temp->newdir($template, CLEANUP => 1);
+                    # Temporary dirs will remove after the request.
+                    push @{$env->{'http.entity.parser.multipart.tempdir'}}, $dir;
+                    $dir;
+
+                };
                 my ($tempfh, $tempname) = tempfile(UNLINK => 0, DIR => $self->{tempdir});
                 $part->{fh} = $tempfh;
                 $part->{tempname} = $tempname;
@@ -107,11 +110,11 @@ sub add {
 
 sub finalize {
     my $self = shift;
-    $self->{parser}->finish();
-
+    (delete $self->{parser})->finish();
     return ($self->{params}, $self->{uploads});
 }
 
+
 1;
 
 __END__

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libhttp-entity-parser-perl.git



More information about the Pkg-perl-cvs-commits mailing list