Explorar o código

dpkg-source: Add a new extraction --ignore-bad-version option

This allows to extract ancient source packages with broken versions,
that used to be accepted at some point in time by dpkg-source.

Closes: #740883
Guillem Jover %!s(int64=12) %!d(string=hai) anos
pai
achega
b916e61f0f

+ 2 - 0
debian/changelog

@@ -30,6 +30,8 @@ dpkg (1.17.7) UNRELEASED; urgency=low
   * Improve dpkg-source warning message when ignoring file removals,
   * Improve dpkg-source warning message when ignoring file removals,
     by adding a hint about the --include-removal option.
     by adding a hint about the --include-removal option.
     Thanks to Moritz Muehlenhoff <jmm@debian.org>. Closes: #738310
     Thanks to Moritz Muehlenhoff <jmm@debian.org>. Closes: #738310
+  * Add a new dpkg-source extraction --ignore-bad-version option.
+    Closes: #740883
 
 
   [ Updated dpkg translations ]
   [ Updated dpkg translations ]
   * German (Sven Joachim).
   * German (Sven Joachim).

+ 5 - 0
man/dpkg-source.1

@@ -250,6 +250,11 @@ signature that can be verified either with the user's
 of the official Debian keyrings
 of the official Debian keyrings
 (\fI/usr/share/keyrings/debian\-keyring.gpg\fP
 (\fI/usr/share/keyrings/debian\-keyring.gpg\fP
 and \fI/usr/share/keyrings/debian\-maintainers.gpg\fP).
 and \fI/usr/share/keyrings/debian\-maintainers.gpg\fP).
+.TP
+.B \-\-ignore\-bad\-version
+Turns the bad source package version check into a non-fatal warning.
+This option should only be necessary when extracting ancient source
+packages with broken versions, just for backwards compatibility.
 
 
 .SH SOURCE PACKAGE FORMATS
 .SH SOURCE PACKAGE FORMATS
 If you don't know what source format to use, you should probably pick
 If you don't know what source format to use, you should probably pick

+ 7 - 1
scripts/Dpkg/Source/Package.pm

@@ -463,7 +463,13 @@ sub extract {
     my $newdirectory = $_[0];
     my $newdirectory = $_[0];
 
 
     my ($ok, $error) = version_check($self->{fields}{'Version'});
     my ($ok, $error) = version_check($self->{fields}{'Version'});
-    error($error) unless $ok;
+    if (not $ok) {
+        if ($self->{options}{ignore_bad_version}) {
+            warning($error);
+        } else {
+            error($error);
+        }
+    }
 
 
     # Copy orig tarballs
     # Copy orig tarballs
     if ($self->{options}{copy_orig_tarballs}) {
     if ($self->{options}{copy_orig_tarballs}) {

+ 4 - 0
scripts/Dpkg/Source/Package/V1.pm

@@ -53,6 +53,7 @@ sub init_options {
          'debian/source/local-patch-header';
          'debian/source/local-patch-header';
     $self->{options}{sourcestyle} ||= 'X';
     $self->{options}{sourcestyle} ||= 'X';
     $self->{options}{skip_debianization} ||= 0;
     $self->{options}{skip_debianization} ||= 0;
+    $self->{options}{ignore_bad_version} ||= 0;
     $self->{options}{abort_on_upstream_changes} ||= 0;
     $self->{options}{abort_on_upstream_changes} ||= 0;
 
 
     # V1.0 only supports gzip compression.
     # V1.0 only supports gzip compression.
@@ -73,6 +74,9 @@ sub parse_cmdline_option {
     } elsif ($opt =~ m/^--skip-debianization$/) {
     } elsif ($opt =~ m/^--skip-debianization$/) {
         $o->{skip_debianization} = 1;
         $o->{skip_debianization} = 1;
         return 1;
         return 1;
+    } elsif ($opt =~ m/^--ignore-bad-version$/) {
+        $o->{ignore_bad_version} = 1;
+        return 1;
     } elsif ($opt =~ m/^--abort-on-upstream-changes$/) {
     } elsif ($opt =~ m/^--abort-on-upstream-changes$/) {
         $o->{abort_on_upstream_changes} = 1;
         $o->{abort_on_upstream_changes} = 1;
         return 1;
         return 1;

+ 5 - 0
scripts/Dpkg/Source/Package/V2.pm

@@ -67,6 +67,8 @@ sub init_options {
         unless exists $self->{options}{create_empty_orig};
         unless exists $self->{options}{create_empty_orig};
     $self->{options}{auto_commit} = 0
     $self->{options}{auto_commit} = 0
         unless exists $self->{options}{auto_commit};
         unless exists $self->{options}{auto_commit};
+    $self->{options}{ignore_bad_version} = 0
+        unless exists $self->{options}{ignore_bad_version};
 }
 }
 
 
 sub parse_cmdline_option {
 sub parse_cmdline_option {
@@ -104,6 +106,9 @@ sub parse_cmdline_option {
     } elsif ($opt =~ /^--auto-commit$/) {
     } elsif ($opt =~ /^--auto-commit$/) {
         $self->{options}{auto_commit} = 1;
         $self->{options}{auto_commit} = 1;
         return 1;
         return 1;
+    } elsif ($opt =~ /^--ignore-bad-version$/) {
+        $self->{options}{ignore_bad_version} = 1;
+        return 1;
     }
     }
     return 0;
     return 0;
 }
 }