From: Vincent Pit Date: Sat, 17 Apr 2010 13:54:58 +0000 (+0200) Subject: Make sure the ebuild placeholder gets unlinked on failure X-Git-Tag: v0.10~1 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FCPANPLUS-Dist-Gentoo.git;a=commitdiff_plain;h=021ebeecfb5f92eae3591ec9563874833c6fe2b4 Make sure the ebuild placeholder gets unlinked on failure --- diff --git a/lib/CPANPLUS/Dist/Gentoo.pm b/lib/CPANPLUS/Dist/Gentoo.pm index 1616449..b844c77 100644 --- a/lib/CPANPLUS/Dist/Gentoo.pm +++ b/lib/CPANPLUS/Dist/Gentoo.pm @@ -17,6 +17,7 @@ use CPANPLUS::Error (); use base qw/CPANPLUS::Dist::Base/; use CPANPLUS::Dist::Gentoo::Atom; +use CPANPLUS::Dist::Gentoo::Guard; use CPANPLUS::Dist::Gentoo::Maps; =head1 NAME @@ -440,7 +441,24 @@ sub create { my $file; + my $guard = CPANPLUS::Dist::Gentoo::Guard->new(sub { + if (defined $file and -e $file and -w _) { + 1 while unlink $file; + } + }); + + my $SIG_INT = $SIG{INT}; + local $SIG{INT} = sub { + if ($SIG_INT) { + local $@; + eval { $SIG_INT->() }; + die $@ if $@; + } + die 'Caught SIGINT'; + }; + my $OK = sub { + $guard->unarm; $stat->created(1); $stat->dist($file) if defined $file; 1; @@ -450,9 +468,6 @@ sub create { $stat->created(0); $stat->dist(undef); $self->_abort(@_) if @_; - if (defined $file and -f $file) { - 1 while unlink $file; - } 0; };