From 824cb0bf7f05fba9ce05a1f73cb507f72396642b Mon Sep 17 00:00:00 2001 From: Raphael Hertzog Date: Sat, 15 Mar 2008 15:31:02 +0100 Subject: [PATCH] Allow deletion of files by patches in Format: 3.0 (quilt) * scripts/Dpkg/Source/Patch.pm (add_diff_directory): New option to be able to generate a diff for a removed file (instead of ignoring its deletion). * scripts/Dpkg/Source/Patch.pm (apply): New option "add_options" to add some options to the default set of options. * scripts/Dpkg/Source/Package/V3_0/quilt.pm: Pass -E option to patch when applying patches without quilt. This will remove patched files which end up being empty. --- scripts/Dpkg/Source/Package/V3_0/quilt.pm | 3 ++- scripts/Dpkg/Source/Patch.pm | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/scripts/Dpkg/Source/Package/V3_0/quilt.pm b/scripts/Dpkg/Source/Package/V3_0/quilt.pm index c9db0727..432174ab 100644 --- a/scripts/Dpkg/Source/Package/V3_0/quilt.pm +++ b/scripts/Dpkg/Source/Package/V3_0/quilt.pm @@ -114,7 +114,8 @@ sub apply_patches { } else { info(_g("applying %s"), $patch) unless $skip_auto; $patch_obj->apply($dir, timestamp => $now, - force_timestamp => 1, create_dirs => 1); + force_timestamp => 1, create_dirs => 1, + add_options => [ '-E' ]); } } } diff --git a/scripts/Dpkg/Source/Patch.pm b/scripts/Dpkg/Source/Patch.pm index c186212f..79e87b84 100644 --- a/scripts/Dpkg/Source/Patch.pm +++ b/scripts/Dpkg/Source/Patch.pm @@ -125,9 +125,9 @@ sub add_diff_file { sub add_diff_directory { my ($self, $old, $new, %opts) = @_; # TODO: make this function more configurable - # - offer diff generation for removed files # - offer to disable some checks my $basedir = $opts{"basedirname"} || basename($new); + my $inc_removal = $opts{"include_removal"} || 0; my $diff_ignore; if ($opts{"diff_ignore_func"}) { $diff_ignore = $opts{"diff_ignore_func"}; @@ -210,7 +210,14 @@ sub add_diff_directory { return if $files_in_new{$fn}; lstat("$old/$fn") || syserr(_g("cannot stat file %s"), "$old/$fn"); if (-f _) { - warning(_g("ignoring deletion of file %s"), $fn); + if ($inc_removal) { + $self->add_diff_file("$old/$fn", "/dev/null", + label_old => "$basedir.orig/$fn", + label_new => "/dev/null", + %opts); + } else { + warning(_g("ignoring deletion of file %s"), $fn); + } } elsif (-d _) { warning(_g("ignoring deletion of directory %s"), $fn); } elsif (-l _) { @@ -297,8 +304,7 @@ sub analyze { $diff, $.) if $_ eq '/dev/null'; $fn = "$destdir/$_"; } else { - unless ($_ eq substr($fn, length($destdir) + 1)) { - printf("$_ $fn $destdir %s", substr($fn, length($destdir) + 1)); + unless ($_ eq '/dev/null' or $_ eq substr($fn, length($destdir) + 1)) { error(_g("line after --- isn't as expected in diff `%s' (line %d)"), $diff, $.); } @@ -367,6 +373,8 @@ sub apply { $opts{"create_dirs"} = 1 unless exists $opts{"create_dirs"}; $opts{"options"} ||= [ '-s', '-t', '-F', '0', '-N', '-p1', '-u', '-V', 'never', '-g0', '-b', '-z', '.dpkg-orig']; + $opts{"add_options"} ||= []; + push @{$opts{"options"}}, @{$opts{"add_options"}}; # Check the diff and create missing directories my $analysis = $self->analyze($destdir, %opts); if ($opts{"create_dirs"}) { @@ -391,7 +399,7 @@ sub apply { my $now = $opts{"timestamp"} || time; foreach my $fn (keys %{$analysis->{'filepatched'}}) { if ($opts{"force_timestamp"}) { - utime($now, $now, $fn) || + utime($now, $now, $fn) || $! == ENOENT || syserr(_g("cannot change timestamp for %s"), $fn); } if ($opts{"remove_backup"}) { -- 2.39.5