From: Raphael Hertzog Date: Thu, 28 Feb 2008 22:04:22 +0000 (+0100) Subject: Dpkg::Source::Package: Fix extract() and build() to clean up by default X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c9e1c6223fa73854e74d2e3a530946d769aa968b;p=dpkg Dpkg::Source::Package: Fix extract() and build() to clean up by default * scripts/Dpkg/Source/Package.pm (extract, build): Change those methods to delegate the real work to do_extract() and do_build() and catch critical failures to clean up any temporary files/directories before re-raising the error. * scripts/Dpkg/Source/Package/V1_0.pm: Rename build() into do_build() and extract() into do_extract(). --- diff --git a/scripts/Dpkg/Source/Package.pm b/scripts/Dpkg/Source/Package.pm index 8ba2f69a..d13cae85 100644 --- a/scripts/Dpkg/Source/Package.pm +++ b/scripts/Dpkg/Source/Package.pm @@ -27,6 +27,7 @@ use Dpkg::Checksums; use Dpkg::Version qw(parseversion); use Dpkg::Deps qw(@src_dep_fields); use Dpkg::Compression; +use Dpkg::Exit; use File::Basename; @@ -216,12 +217,30 @@ sub check_signature { } sub extract { + my $self = shift; + eval { $self->do_extract(@_) }; + if ($@) { + &$_() foreach reverse @Dpkg::Exit::handlers; + die $@; + } +} + +sub do_extract { error("Dpkg::Source::Package doesn't know how to unpack a source package. Use one of the subclass."); } # Function used specifically during creation of a source package sub build { + my $self = shift; + eval { $self->do_build(@_) }; + if ($@) { + &$_() foreach reverse @Dpkg::Exit::handlers; + die $@; + } +} + +sub do_build { error("Dpkg::Source::Package doesn't know how to build a source package. Use one of the subclass."); } diff --git a/scripts/Dpkg/Source/Package/V1_0.pm b/scripts/Dpkg/Source/Package/V1_0.pm index affbbb7a..9e0c5234 100644 --- a/scripts/Dpkg/Source/Package/V1_0.pm +++ b/scripts/Dpkg/Source/Package/V1_0.pm @@ -35,7 +35,7 @@ use POSIX; use File::Basename; use File::Temp qw(tempfile); -sub extract { +sub do_extract { my ($self, $newdirectory) = @_; my $sourcestyle = $self->{'options'}{'sourcestyle'}; my $fields = $self->{'fields'}; @@ -152,7 +152,7 @@ sub extract { } } -sub build { +sub do_build { my ($self, $dir) = @_; my $sourcestyle = $self->{'options'}{'sourcestyle'}; my @argv = @{$self->{'options'}{'ARGV'}};