Просмотр исходного кода

Dpkg::Source::Package: replace register_autopatch() with register_patch()

While register_autopatch() is only able to register a patch as the
automatic patch, register_patch() can register a patch under any
desired patch name.

Also it doesn't not drop the input patch file, leaving that responsibility
to whoever called it. However if the input patch file is empty, it will
remove the target patch from the debian source package.
Raphaël Hertzog лет назад: 15
Родитель
Сommit
b8407b1dbd
2 измененных файлов с 42 добавлено и 34 удалено
  1. 19 21
      scripts/Dpkg/Source/Package/V2.pm
  2. 23 13
      scripts/Dpkg/Source/Package/V3/quilt.pm

+ 19 - 21
scripts/Dpkg/Source/Package/V2.pm

@@ -40,6 +40,7 @@ use File::Temp qw(tempfile tempdir);
 use File::Path;
 use File::Spec;
 use File::Find;
+use File::Copy;
 
 our $CURRENT_MINOR_VERSION = "0";
 
@@ -471,31 +472,22 @@ sub do_build {
             %{$self->{'diff_options'}}, handle_binary_func => $handle_binary,
             order_from => $autopatch);
     error(_g("unrepresentable changes to source")) if not $diff->finish();
-    # The previous auto-patch must be removed, it has not been used and it
-    # will be recreated if it's still needed
-    if (-e $autopatch) {
-        unlink($autopatch) || syserr(_g("cannot remove %s"), $autopatch);
-    }
     # Install the diff as the new autopatch
-    if (not -s $tmpdiff) {
-        unlink($tmpdiff) || syserr(_g("cannot remove %s"), $tmpdiff);
-    } else {
-        mkpath(File::Spec->catdir($dir, "debian", "patches"));
+    mkpath(File::Spec->catdir($dir, "debian", "patches"));
+    $autopatch = $self->register_patch($dir, $tmpdiff,
+                                       $self->get_autopatch_name());
+    if (-s $autopatch) {
         info(_g("local changes stored in %s, the modified files are:"), $autopatch);
         my $analysis = $diff->analyze($dir, verbose => 0);
         foreach my $fn (sort keys %{$analysis->{'filepatched'}}) {
             print " $fn\n";
         }
-        rename($tmpdiff, $autopatch) ||
-                syserr(_g("cannot rename %s to %s"), $tmpdiff, $autopatch);
-        chmod(0666 & ~ umask(), $autopatch) ||
-                syserr(_g("unable to change permission of `%s'"), $autopatch);
     }
-    $self->register_autopatch($dir);
     if (-e $autopatch and $self->{'options'}{'abort_on_upstream_changes'}) {
         error(_g("aborting due to --abort-on-upstream-changes"));
     }
     rmdir(File::Spec->catdir($dir, "debian", "patches")); # No check on purpose
+    unlink($tmpdiff) || syserr(_g("cannot remove %s"), $tmpdiff);
     pop @Dpkg::Exit::handlers;
 
     # Remove the temporary directory
@@ -571,16 +563,22 @@ Last-Update: <YYYY-MM-DD>\n\n";
     return $text;
 }
 
-sub register_autopatch {
-    my ($self, $dir) = @_;
-    my $autopatch = File::Spec->catfile($dir, "debian", "patches",
-                                        $self->get_autopatch_name());
-    if (-e $autopatch) {
+sub register_patch {
+    my ($self, $dir, $patch_file, $patch_name) = @_;
+    my $patch = File::Spec->catfile($dir, "debian", "patches", $patch_name);
+    if (-s $patch_file) {
+        copy($patch_file, $patch) ||
+            syserr(_g("failed to copy %s to %s"), $patch_file, $patch);
+        chmod(0666 & ~ umask(), $patch) ||
+                syserr(_g("unable to change permission of `%s'"), $patch);
         my $applied = File::Spec->catfile($dir, "debian", "patches", ".dpkg-source-applied");
         open(APPLIED, '>>', $applied) || syserr(_g("cannot write %s"), $applied);
-        print APPLIED ($self->get_autopatch_name() . "\n");
-        close(APPLIED);
+        print APPLIED "$patch\n";
+        close(APPLIED) || syserr(_g("cannot close %s"), $applied);
+    } elsif (-e $patch) {
+        unlink($patch) || syserr(_g("cannot remove %s"), $patch);
     }
+    return $patch;
 }
 
 # vim:et:sw=4:ts=8

+ 23 - 13
scripts/Dpkg/Source/Package/V3/quilt.pm

@@ -35,6 +35,7 @@ use POSIX;
 use File::Basename;
 use File::Spec;
 use File::Path;
+use File::Copy;
 
 our $CURRENT_MINOR_VERSION = "0";
 
@@ -330,8 +331,8 @@ sub check_patches_applied {
     }
 }
 
-sub register_autopatch {
-    my ($self, $dir) = @_;
+sub register_patch {
+    my ($self, $dir, $tmpdiff, $patch_name) = @_;
 
     sub add_line {
         my ($file, $line) = @_;
@@ -350,38 +351,47 @@ sub register_autopatch {
         close(FILE);
     }
 
-    my $auto_patch = $self->get_autopatch_name();
     my @patches = $self->get_patches($dir);
-    my $has_patch = (grep { $_ eq $auto_patch } @patches) ? 1 : 0;
+    my $has_patch = (grep { $_ eq $patch_name } @patches) ? 1 : 0;
     my $series = $self->get_series_file($dir);
     $series ||= File::Spec->catfile($dir, "debian", "patches", "series");
     my $applied = File::Spec->catfile($dir, ".pc", "applied-patches");
-    my $patch = File::Spec->catfile($dir, "debian", "patches", $auto_patch);
+    my $patch = File::Spec->catfile($dir, "debian", "patches", $patch_name);
+
+    if (-s $tmpdiff) {
+        copy($tmpdiff, $patch) ||
+            syserr(_g("failed to copy %s to %s"), $tmpdiff, $patch);
+        chmod(0666 & ~ umask(), $patch) ||
+            syserr(_g("unable to change permission of `%s'"), $patch);
+    } elsif (-e $patch) {
+        unlink($patch) || syserr(_g("cannot remove %s"), $patch);
+    }
 
     if (-e $patch) {
         $self->create_quilt_db($dir);
-        # Add auto_patch to series file
+        # Add patch to series file
         if (not $has_patch) {
-            add_line($series, $auto_patch);
-            add_line($applied, $auto_patch);
+            add_line($series, $patch_name);
+            add_line($applied, $patch_name);
         }
         # Ensure quilt meta-data are created and in sync with some trickery:
         # reverse-apply the patch, drop .pc/$patch, re-apply it
         # with the correct options to recreate the backup files
         my $patch_obj = Dpkg::Source::Patch->new(filename => $patch);
         $patch_obj->apply($dir, add_options => ['-R', '-E'], verbose => 0);
-        erasedir(File::Spec->catdir($dir, ".pc", $auto_patch));
-        $self->apply_quilt_patch($dir, $auto_patch);
+        erasedir(File::Spec->catdir($dir, ".pc", $patch_name));
+        $self->apply_quilt_patch($dir, $patch_name);
     } else {
         # Remove auto_patch from series
         if ($has_patch) {
-            drop_line($series, $auto_patch);
-            drop_line($applied, $auto_patch);
-            erasedir(File::Spec->catdir($dir, ".pc", $auto_patch));
+            drop_line($series, $patch_name);
+            drop_line($applied, $patch_name);
+            erasedir(File::Spec->catdir($dir, ".pc", $patch_name));
         }
         # Clean up empty series
         unlink($series) if not -s $series;
     }
+    return $patch;
 }
 
 # vim:et:sw=4:ts=8