Selaa lähdekoodia

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().
Raphael Hertzog 18 vuotta sitten
vanhempi
commit
c9e1c6223f
2 muutettua tiedostoa jossa 21 lisäystä ja 2 poistoa
  1. 19 0
      scripts/Dpkg/Source/Package.pm
  2. 2 2
      scripts/Dpkg/Source/Package/V1_0.pm

+ 19 - 0
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.");
 }
 

+ 2 - 2
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'}};