Control: tag 683547 + patch

On Wed, 01 Aug 2012, Thomas Koch wrote:
> It might not be a good idea in the first place to have such a patch series. 
> But
> dpkg-source --after-build fails on it. It can not copy the original file 
> because
> the parent directory of the original file does not exist anymore.
> 
> I suspect, that the patch command deleted all empty parent directories as
> described for the -remove-empty-files option. I tried to provide a fix that
> calls make_path($target_dir) in scripts/Dpkg/Source/Quilt.pm but I failed 
> perl.

You diagnosed the problem correctly. This is effectively a regression
because we had no such problem when we used "patch -R" to unapply the
patches. Now that we use the quilt backup files instead, we're affected by
this issue.

I attach my suggested patch. Please try it.

I will certainly push this to master for inclusion in wheezy since
it's a regression introduced by my changes in dpkg 1.16.5.

Cheers,
-- 
Raphaël Hertzog ◈ Debian Developer

Get the Debian Administrator's Handbook:
→ http://debian-handbook.info/get/
>From 135833c9fe7c6c2f4dc90fd9eb41d75165fb4daa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rapha=C3=ABl=20Hertzog?= <hert...@debian.org>
Date: Wed, 1 Aug 2012 21:18:07 +0200
Subject: [PATCH] Dpkg::Source::Quilt: ensure the target directory exist
 before copying files

When we restore files in the pop operation, the target directory is
usually pre-existing, but in the case where the patch is removing all the
files in the directory, the usage of patch's --remove-empty-files lead to
the removal of the parent directories which are empty.

This caused a regression in dpkg-source's handling of "3.0 (quilt)" source
package since this case was not causing any problem when the patch
were unapplied with "patch -R" (patch creates the required directories).

Reported-by: Thomas Koch <tho...@koch.ro>
Closes: #683547
---
 debian/changelog             |    4 ++++
 scripts/Dpkg/Source/Quilt.pm |    3 +++
 2 files changed, 7 insertions(+)

diff --git a/debian/changelog b/debian/changelog
index 5e4245c..cf28bb5 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,5 +1,9 @@
 dpkg (1.16.9) UNRELEASED; urgency=low
 
+  [ Raphaël Hertzog ]
+  * Fix dpkg-source regression in "3.0 (quilt)" source packages while
+    unapplying patches that remove all files in a directory. Closes: #683547
+
   [ Updated programs translations ]
   * Czech (Miroslav Kure).
 
diff --git a/scripts/Dpkg/Source/Quilt.pm b/scripts/Dpkg/Source/Quilt.pm
index 25819df..5ca9fb7 100644
--- a/scripts/Dpkg/Source/Quilt.pm
+++ b/scripts/Dpkg/Source/Quilt.pm
@@ -29,6 +29,8 @@ use Dpkg::Vendor qw(get_current_vendor);
 use File::Spec;
 use File::Copy;
 use File::Find;
+use File::Path qw(make_path);
+use File::Basename;
 
 sub new {
     my ($this, $dir, %opts) = @_;
@@ -287,6 +289,7 @@ sub restore_quilt_backup_files {
             my $target = File::Spec->catfile($self->{'dir'}, $relpath_in_srcpkg);
             if (-s $_) {
                 unlink($target);
+                make_path(dirname($target));
                 unless (link($_, $target)) {
                     copy($_, $target) ||
                         syserr(_g("failed to copy %s to %s"), $_, $target);
-- 
1.7.10.4

Reply via email to