po: Update German man pages translation
[dpkg.git] / scripts / Dpkg / Source / Patch.pm
blob57468fc4e6cfa02479efe895f6efd0b17bcc2209
1 # Copyright © 2008 Raphaël Hertzog <hertzog@debian.org>
2 # Copyright © 2008-2010, 2012-2015 Guillem Jover <guillem@debian.org>
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
17 =encoding utf8
19 =head1 NAME
21 Dpkg::Source::Patch - represent a patch file
23 =head1 DESCRIPTION
25 This module provides a class to handle patch files.
27 B<Note>: This is a private module, its API can change at any time.
29 =cut
31 package Dpkg::Source::Patch 0.01;
33 use strict;
34 use warnings;
36 use POSIX qw(:errno_h :sys_wait_h);
37 use File::Find;
38 use File::Basename;
39 use File::Spec;
40 use File::Path qw(make_path);
41 use File::Compare;
42 use Fcntl qw(:mode);
43 use Time::HiRes qw(stat);
45 use Dpkg;
46 use Dpkg::Gettext;
47 use Dpkg::ErrorHandling;
48 use Dpkg::IPC;
49 use Dpkg::Source::Functions qw(fs_time);
51 use parent qw(Dpkg::Compression::FileHandle);
53 sub create {
54 my ($self, %opts) = @_;
55 $self->ensure_open('w'); # Creates the file
56 *$self->{errors} = 0;
57 *$self->{empty} = 1;
58 if ($opts{old} and $opts{new} and $opts{filename}) {
59 $opts{old} = '/dev/null' unless -e $opts{old};
60 $opts{new} = '/dev/null' unless -e $opts{new};
61 if (-d $opts{old} and -d $opts{new}) {
62 $self->add_diff_directory($opts{old}, $opts{new}, %opts);
63 } elsif (-f $opts{old} and -f $opts{new}) {
64 $self->add_diff_file($opts{old}, $opts{new}, %opts);
65 } else {
66 $self->_fail_not_same_type($opts{old}, $opts{new}, $opts{filename});
68 $self->finish() unless $opts{nofinish};
72 sub set_header {
73 my ($self, $header) = @_;
74 *$self->{header} = $header;
77 sub get_header {
78 my $self = shift;
80 if (ref *$self->{header} eq 'CODE') {
81 return *$self->{header}->();
82 } else {
83 return *$self->{header};
87 sub add_diff_file {
88 my ($self, $old, $new, %opts) = @_;
89 $opts{include_timestamp} //= 0;
90 my $handle_binary = $opts{handle_binary_func} // sub {
91 my ($self, $old, $new, %opts) = @_;
92 my $file = $opts{filename};
93 $self->_fail_with_msg($file, g_('binary file contents changed'));
95 # Optimization to avoid forking diff if unnecessary
96 return 1 if compare($old, $new, 4096) == 0;
97 # Default diff options
98 my @options;
99 if ($opts{options}) {
100 push @options, @{$opts{options}};
101 } else {
102 push @options, '-p';
104 # Add labels
105 if ($opts{label_old} and $opts{label_new}) {
106 if ($opts{include_timestamp}) {
107 my $ts = (stat($old))[9];
108 my $t = POSIX::strftime('%Y-%m-%d %H:%M:%S', gmtime($ts));
109 $opts{label_old} .= sprintf("\t%s.%09d +0000", $t,
110 ($ts - int($ts)) * 1_000_000_000);
111 $ts = (stat($new))[9];
112 $t = POSIX::strftime('%Y-%m-%d %H:%M:%S', gmtime($ts));
113 $opts{label_new} .= sprintf("\t%s.%09d +0000", $t,
114 ($ts - int($ts)) * 1_000_000_000);
115 } else {
116 # Space in filenames need special treatment
117 $opts{label_old} .= "\t" if $opts{label_old} =~ / /;
118 $opts{label_new} .= "\t" if $opts{label_new} =~ / /;
120 push @options, '-L', $opts{label_old},
121 '-L', $opts{label_new};
123 # Generate diff
124 my $diffgen;
125 my $diff_pid = spawn(
126 exec => [ 'diff', '-u', @options, '--', $old, $new ],
127 env => { LC_ALL => 'C', TZ => 'UTC0' },
128 to_pipe => \$diffgen,
130 # Check diff and write it in patch file
131 my $difflinefound = 0;
132 my $binary = 0;
133 local $_;
135 while (<$diffgen>) {
136 if (m/^(?:binary|[^-+\@ ].*\bdiffer\b)/i) {
137 $binary = 1;
138 $handle_binary->($self, $old, $new, %opts);
139 last;
140 } elsif (m/^[-+\@ ]/) {
141 $difflinefound++;
142 } elsif (m/^\\ /) {
143 warning(g_('file %s has no final newline (either ' .
144 'original or modified version)'), $new);
145 } else {
146 chomp;
147 error(g_("unknown line from diff -u on %s: '%s'"), $new, $_);
149 if (*$self->{empty} and defined(*$self->{header})) {
150 $self->print($self->get_header()) or syserr(g_('failed to write'));
151 *$self->{empty} = 0;
153 print { $self } $_ or syserr(g_('failed to write'));
155 close($diffgen) or syserr('close on diff pipe');
156 wait_child($diff_pid, nocheck => 1,
157 cmdline => "diff -u @options -- $old $new");
158 # Verify diff process ended successfully
159 # Exit code of diff: 0 => no difference, 1 => diff ok, 2 => error
160 # Ignore error if binary content detected
161 my $exit = WEXITSTATUS($?);
162 unless (WIFEXITED($?) && ($exit == 0 || $exit == 1 || $binary)) {
163 subprocerr(g_('diff on %s'), $new);
165 return ($exit == 0 || $exit == 1);
168 sub add_diff_directory {
169 my ($self, $old, $new, %opts) = @_;
170 # TODO: make this function more configurable
171 # - offer to disable some checks
172 my $basedir = $opts{basedirname} || basename($new);
173 my $diff_ignore;
174 if ($opts{diff_ignore_func}) {
175 $diff_ignore = $opts{diff_ignore_func};
176 } elsif ($opts{diff_ignore_regex}) {
177 $diff_ignore = sub { return $_[0] =~ /$opts{diff_ignore_regex}/o };
178 } else {
179 $diff_ignore = sub { return 0 };
182 my @diff_files;
183 my %files_in_new;
184 my $scan_new = sub {
185 my $fn = (length > length($new)) ? substr($_, length($new) + 1) : '.';
186 return if $diff_ignore->($fn);
187 $files_in_new{$fn} = 1;
188 lstat("$new/$fn") or syserr(g_('cannot stat file %s'), "$new/$fn");
189 my $mode = S_IMODE((lstat(_))[2]);
190 my $size = (lstat(_))[7];
191 if (-l _) {
192 unless (-l "$old/$fn") {
193 $self->_fail_not_same_type("$old/$fn", "$new/$fn", $fn);
194 return;
196 my $n = readlink("$new/$fn");
197 unless (defined $n) {
198 syserr(g_('cannot read link %s'), "$new/$fn");
200 my $n2 = readlink("$old/$fn");
201 unless (defined $n2) {
202 syserr(g_('cannot read link %s'), "$old/$fn");
204 unless ($n eq $n2) {
205 $self->_fail_not_same_type("$old/$fn", "$new/$fn", $fn);
207 } elsif (-f _) {
208 my $old_file = "$old/$fn";
209 if (not lstat("$old/$fn")) {
210 if ($! != ENOENT) {
211 syserr(g_('cannot stat file %s'), "$old/$fn");
213 $old_file = '/dev/null';
214 } elsif (not -f _) {
215 $self->_fail_not_same_type("$old/$fn", "$new/$fn", $fn);
216 return;
219 my $label_old = "$basedir.orig/$fn";
220 if ($opts{use_dev_null}) {
221 $label_old = $old_file if $old_file eq '/dev/null';
223 push @diff_files, [$fn, $mode, $size, $old_file, "$new/$fn",
224 $label_old, "$basedir/$fn"];
225 } elsif (-p _) {
226 unless (-p "$old/$fn") {
227 $self->_fail_not_same_type("$old/$fn", "$new/$fn", $fn);
229 } elsif (-b _ || -c _ || -S _) {
230 $self->_fail_with_msg("$new/$fn",
231 g_('device or socket is not allowed'));
232 } elsif (-d _) {
233 if (not lstat("$old/$fn")) {
234 if ($! != ENOENT) {
235 syserr(g_('cannot stat file %s'), "$old/$fn");
237 } elsif (not -d _) {
238 $self->_fail_not_same_type("$old/$fn", "$new/$fn", $fn);
240 } else {
241 $self->_fail_with_msg("$new/$fn", g_('unknown file type'));
244 my $scan_old = sub {
245 my $fn = (length > length($old)) ? substr($_, length($old) + 1) : '.';
246 return if $diff_ignore->($fn);
247 return if $files_in_new{$fn};
248 lstat("$old/$fn") or syserr(g_('cannot stat file %s'), "$old/$fn");
249 if (-f _) {
250 if (not defined $opts{include_removal}) {
251 warning(g_('ignoring deletion of file %s'), $fn);
252 } elsif (not $opts{include_removal}) {
253 warning(g_('ignoring deletion of file %s, use --include-removal to override'), $fn);
254 } else {
255 push @diff_files, [$fn, 0, 0, "$old/$fn", '/dev/null',
256 "$basedir.orig/$fn", '/dev/null'];
258 } elsif (-d _) {
259 warning(g_('ignoring deletion of directory %s'), $fn);
260 } elsif (-l _) {
261 warning(g_('ignoring deletion of symlink %s'), $fn);
262 } else {
263 $self->_fail_not_same_type("$old/$fn", "$new/$fn", $fn);
267 find({ wanted => $scan_new, no_chdir => 1 }, $new);
268 find({ wanted => $scan_old, no_chdir => 1 }, $old);
270 if ($opts{order_from} and -e $opts{order_from}) {
271 my $order_from = Dpkg::Source::Patch->new(
272 filename => $opts{order_from});
273 my $analysis = $order_from->analyze($basedir, verbose => 0);
274 my %patchorder;
275 my $i = 0;
276 foreach my $fn (@{$analysis->{patchorder}}) {
277 $fn =~ s{^[^/]+/}{};
278 $patchorder{$fn} = $i++;
280 # 'quilt refresh' sorts files as follows:
281 # - Any files in the existing patch come first, in the order in
282 # which they appear in the existing patch.
283 # - New files follow, sorted lexicographically.
284 # This seems a reasonable policy to follow, and avoids autopatches
285 # being shuffled when they are regenerated.
286 foreach my $diff_file (sort { $a->[0] cmp $b->[0] } @diff_files) {
287 my $fn = $diff_file->[0];
288 $patchorder{$fn} //= $i++;
290 @diff_files = sort { $patchorder{$a->[0]} <=> $patchorder{$b->[0]} }
291 @diff_files;
292 } else {
293 @diff_files = sort { $a->[0] cmp $b->[0] } @diff_files;
296 foreach my $diff_file (@diff_files) {
297 my ($fn, $mode, $size,
298 $old_file, $new_file, $label_old, $label_new) = @$diff_file;
299 my $success = $self->add_diff_file($old_file, $new_file,
300 filename => $fn,
301 label_old => $label_old,
302 label_new => $label_new, %opts);
303 if ($success and
304 $old_file eq '/dev/null' and $new_file ne '/dev/null') {
305 if (not $size) {
306 warning(g_("newly created empty file '%s' will not " .
307 'be represented in diff'), $fn);
308 } else {
309 if ($mode & (S_IXUSR | S_IXGRP | S_IXOTH)) {
310 warning(g_("executable mode %04o of '%s' will " .
311 'not be represented in diff'), $mode, $fn)
312 unless $fn eq 'debian/rules';
314 if ($mode & (S_ISUID | S_ISGID | S_ISVTX)) {
315 warning(g_("special mode %04o of '%s' will not " .
316 'be represented in diff'), $mode, $fn);
323 sub finish {
324 my $self = shift;
325 close($self) or syserr(g_('cannot close %s'), $self->get_filename());
326 return not *$self->{errors};
329 sub register_error {
330 my $self = shift;
331 *$self->{errors}++;
333 sub _fail_with_msg {
334 my ($self, $file, $msg) = @_;
335 errormsg(g_('cannot represent change to %s: %s'), $file, $msg);
336 $self->register_error();
338 sub _fail_not_same_type {
339 my ($self, $old, $new, $file) = @_;
340 my $old_type = get_type($old);
341 my $new_type = get_type($new);
342 errormsg(g_('cannot represent change to %s:'), $file);
343 errormsg(g_(' new version is %s'), $new_type);
344 errormsg(g_(' old version is %s'), $old_type);
345 $self->register_error();
348 sub _getline {
349 my $handle = shift;
351 my $line = <$handle>;
352 if (defined $line) {
353 # Strip end-of-line chars
354 chomp($line);
355 $line =~ s/\r$//;
357 return $line;
360 # Fetch the header filename ignoring the optional timestamp
361 sub _fetch_filename {
362 my ($diff, $header) = @_;
364 # Strip any leading spaces.
365 $header =~ s/^\s+//;
367 # Is it a C-style string?
368 if ($header =~ m/^"/) {
369 error(g_('diff %s patches file with C-style encoded filename'), $diff);
370 } else {
371 # Tab is the official separator, it's always used when
372 # filename contain spaces. Try it first, otherwise strip on space
373 # if there's no tab
374 $header =~ s/\s.*// unless $header =~ s/\t.*//;
377 return $header;
380 sub _intuit_file_patched {
381 my ($old, $new) = @_;
383 return $new unless defined $old;
384 return $old unless defined $new;
385 return $new if -e $new and not -e $old;
386 return $old if -e $old and not -e $new;
388 # We don't consider the case where both files are non-existent and
389 # where patch picks the one with the fewest directories to create
390 # since dpkg-source will pre-create the required directories
392 # Precalculate metrics used by patch
393 my ($tmp_o, $tmp_n) = ($old, $new);
394 my ($len_o, $len_n) = (length($old), length($new));
395 $tmp_o =~ s{[/\\]+}{/}g;
396 $tmp_n =~ s{[/\\]+}{/}g;
397 my $nb_comp_o = ($tmp_o =~ tr{/}{/});
398 my $nb_comp_n = ($tmp_n =~ tr{/}{/});
399 $tmp_o =~ s{^.*/}{};
400 $tmp_n =~ s{^.*/}{};
401 my ($blen_o, $blen_n) = (length($tmp_o), length($tmp_n));
403 # Decide like patch would
404 if ($nb_comp_o != $nb_comp_n) {
405 return ($nb_comp_o < $nb_comp_n) ? $old : $new;
406 } elsif ($blen_o != $blen_n) {
407 return ($blen_o < $blen_n) ? $old : $new;
408 } elsif ($len_o != $len_n) {
409 return ($len_o < $len_n) ? $old : $new;
411 return $old;
414 # check diff for sanity, find directories to create as a side effect
415 sub analyze {
416 my ($self, $destdir, %opts) = @_;
418 $opts{verbose} //= 1;
419 my $diff = $self->get_filename();
420 my %filepatched;
421 my %dirtocreate;
422 my @patchorder;
423 my $patch_header = '';
424 my $diff_count = 0;
426 my $line = _getline($self);
428 HUNK:
429 while (defined $line or not eof $self) {
430 my (%path, %fn);
432 # Skip comments leading up to the patch (if any). Although we do not
433 # look for an Index: pseudo-header in the comments, because we would
434 # not use it anyway, as we require both ---/+++ filename headers.
435 while (1) {
436 if ($line =~ /^(?:--- |\+\+\+ |@@ -)/) {
437 last;
438 } else {
439 $patch_header .= "$line\n";
441 $line = _getline($self);
442 last HUNK if not defined $line;
444 $diff_count++;
445 # read file header (---/+++ pair)
446 unless ($line =~ s/^--- //) {
447 error(g_("expected ^--- in line %d of diff '%s'"), $., $diff);
449 $path{old} = $line = _fetch_filename($diff, $line);
450 if ($line ne '/dev/null' and $line =~ s{^[^/]*/+}{$destdir/}) {
451 $fn{old} = $line;
453 if ($line =~ /\.dpkg-orig$/) {
454 error(g_("diff '%s' patches file with name ending in .dpkg-orig"),
455 $diff);
458 $line = _getline($self);
459 unless (defined $line) {
460 error(g_("diff '%s' finishes in middle of ---/+++ (line %d)"),
461 $diff, $.);
463 unless ($line =~ s/^\+\+\+ //) {
464 error(g_("line after --- isn't as expected in diff '%s' (line %d)"),
465 $diff, $.);
467 $path{new} = $line = _fetch_filename($diff, $line);
468 if ($line ne '/dev/null' and $line =~ s{^[^/]*/+}{$destdir/}) {
469 $fn{new} = $line;
472 unless (defined $fn{old} or defined $fn{new}) {
473 error(g_("none of the filenames in ---/+++ are valid in diff '%s' (line %d)"),
474 $diff, $.);
477 # Safety checks on both filenames that patch could use
478 foreach my $key ('old', 'new') {
479 next unless defined $fn{$key};
480 if ($path{$key} =~ m{/\.\./}) {
481 error(g_('%s contains an insecure path: %s'), $diff, $path{$key});
483 my $path = $fn{$key};
484 while (1) {
485 if (-l $path) {
486 error(g_('diff %s modifies file %s through a symlink: %s'),
487 $diff, $fn{$key}, $path);
489 last unless $path =~ s{/+[^/]*$}{};
490 last if length($path) <= length($destdir); # $destdir is assumed safe
494 if ($path{old} eq '/dev/null' and $path{new} eq '/dev/null') {
495 error(g_("original and modified files are /dev/null in diff '%s' (line %d)"),
496 $diff, $.);
497 } elsif ($path{new} eq '/dev/null') {
498 error(g_("file removal without proper filename in diff '%s' (line %d)"),
499 $diff, $. - 1) unless defined $fn{old};
500 if ($opts{verbose}) {
501 warning(g_('diff %s removes a non-existing file %s (line %d)'),
502 $diff, $fn{old}, $.) unless -e $fn{old};
505 my $fn = _intuit_file_patched($fn{old}, $fn{new});
507 my $dirname = $fn;
508 if ($dirname =~ s{/[^/]+$}{} and not -d $dirname) {
509 $dirtocreate{$dirname} = 1;
512 if (-e $fn) {
513 if (not -f _) {
514 error(g_("diff '%s' patches something which is not a plain file"),
515 $diff);
517 # Note: We cannot use "stat _" due to Time::HiRes.
518 my $nlink = (stat $fn)[3];
519 if ($nlink > 1) {
520 warning(g_("diff '%s' patches hard link %s which can have " .
521 'unintended consequences'), $diff, $fn);
525 if ($filepatched{$fn}) {
526 $filepatched{$fn}++;
528 if ($opts{fatal_dupes}) {
529 error(g_("diff '%s' patches files multiple times; split the " .
530 'diff in multiple files or merge the hunks into a ' .
531 'single one'), $diff);
532 } elsif ($opts{verbose} and $filepatched{$fn} == 2) {
533 warning(g_("diff '%s' patches file %s more than once"), $diff, $fn)
535 } else {
536 $filepatched{$fn} = 1;
537 push @patchorder, $fn;
540 # read hunks
541 my $hunk = 0;
542 while (defined($line = _getline($self))) {
543 # read hunk header (@@)
544 next if $line =~ /^\\ /;
545 last unless $line =~ /^@@ -\d+(,(\d+))? \+\d+(,(\d+))? @\@(?: .*)?$/;
546 my ($olines, $nlines) = ($1 ? $2 : 1, $3 ? $4 : 1);
547 # read hunk
548 while ($olines || $nlines) {
549 unless (defined($line = _getline($self))) {
550 if (($olines == $nlines) and ($olines < 3)) {
551 warning(g_("unexpected end of diff '%s'"), $diff)
552 if $opts{verbose};
553 last;
554 } else {
555 error(g_("unexpected end of diff '%s'"), $diff);
558 next if $line =~ /^\\ /;
559 # Check stats
560 if ($line =~ /^ / or length $line == 0) {
561 --$olines;
562 --$nlines;
563 } elsif ($line =~ /^-/) {
564 --$olines;
565 } elsif ($line =~ /^\+/) {
566 --$nlines;
567 } else {
568 error(g_("expected [ +-] at start of line %d of diff '%s'"),
569 $., $diff);
572 $hunk++;
574 unless ($hunk) {
575 error(g_("expected ^\@\@ at line %d of diff '%s'"), $., $diff);
578 close($self);
579 unless ($diff_count) {
580 warning(g_("diff '%s' doesn't contain any patch"), $diff)
581 if $opts{verbose};
583 *$self->{analysis}{$destdir}{dirtocreate} = \%dirtocreate;
584 *$self->{analysis}{$destdir}{filepatched} = \%filepatched;
585 *$self->{analysis}{$destdir}{patchorder} = \@patchorder;
586 *$self->{analysis}{$destdir}{patchheader} = $patch_header;
587 return *$self->{analysis}{$destdir};
590 sub prepare_apply {
591 my ($self, $analysis, %opts) = @_;
592 if ($opts{create_dirs}) {
593 foreach my $dir (keys %{$analysis->{dirtocreate}}) {
594 eval { make_path($dir, { mode => 0777 }) };
595 syserr(g_('cannot create directory %s'), $dir) if $@;
600 sub apply {
601 my ($self, $destdir, %opts) = @_;
602 # Set default values to options
603 $opts{force_timestamp} //= 1;
604 $opts{remove_backup} //= 1;
605 $opts{create_dirs} //= 1;
606 $opts{options} ||= [
607 '-t',
608 '-F', '0',
609 '-N',
610 '-p1',
611 '-u',
612 '-V', 'never',
613 '-b',
614 '-z', '.dpkg-orig',
616 $opts{add_options} //= [];
617 push @{$opts{options}}, @{$opts{add_options}};
618 # Check the diff and create missing directories
619 my $analysis = $self->analyze($destdir, %opts);
620 $self->prepare_apply($analysis, %opts);
621 # Apply the patch
622 $self->ensure_open('r');
623 my ($stdout, $stderr) = ('', '');
624 spawn(
625 exec => [ $Dpkg::PROGPATCH, @{$opts{options}} ],
626 chdir => $destdir,
627 env => { LC_ALL => 'C', PATCH_GET => '0' },
628 delete_env => [ 'POSIXLY_CORRECT' ], # ensure expected patch behaviour
629 wait_child => 1,
630 nocheck => 1,
631 from_handle => $self->get_filehandle(),
632 to_string => \$stdout,
633 error_to_string => \$stderr,
635 if ($?) {
636 print { *STDOUT } $stdout;
637 print { *STDERR } $stderr;
638 subprocerr("LC_ALL=C $Dpkg::PROGPATCH " . join(' ', @{$opts{options}}) .
639 ' < ' . $self->get_filename());
641 $self->close();
642 # Reset the timestamp of all the patched files
643 # and remove .dpkg-orig files
644 my @files = keys %{$analysis->{filepatched}};
645 my $now = $opts{timestamp};
646 $now //= fs_time($files[0]) if $opts{force_timestamp} && scalar @files;
647 foreach my $fn (@files) {
648 if ($opts{force_timestamp}) {
649 utime($now, $now, $fn) or $! == ENOENT
650 or syserr(g_('cannot change timestamp for %s'), $fn);
652 if ($opts{remove_backup}) {
653 $fn .= '.dpkg-orig';
654 unlink($fn) or syserr(g_('remove patch backup file %s'), $fn);
657 return $analysis;
660 # Verify if check will work...
661 sub check_apply {
662 my ($self, $destdir, %opts) = @_;
663 # Set default values to options
664 $opts{create_dirs} //= 1;
665 $opts{options} ||= [
666 '--dry-run',
667 '-s',
668 '-t',
669 '-F', '0',
670 '-N',
671 '-p1',
672 '-u',
673 '-V', 'never',
674 '-b',
675 '-z', '.dpkg-orig',
677 $opts{add_options} //= [];
678 push @{$opts{options}}, @{$opts{add_options}};
679 # Check the diff and create missing directories
680 my $analysis = $self->analyze($destdir, %opts);
681 $self->prepare_apply($analysis, %opts);
682 # Apply the patch
683 $self->ensure_open('r');
684 my $patch_pid = spawn(
685 exec => [ $Dpkg::PROGPATCH, @{$opts{options}} ],
686 chdir => $destdir,
687 env => { LC_ALL => 'C', PATCH_GET => '0' },
688 delete_env => [ 'POSIXLY_CORRECT' ], # ensure expected patch behaviour
689 from_handle => $self->get_filehandle(),
690 to_file => '/dev/null',
691 error_to_file => '/dev/null',
693 wait_child($patch_pid, nocheck => 1);
694 my $exit = WEXITSTATUS($?);
695 subprocerr("$Dpkg::PROGPATCH --dry-run") unless WIFEXITED($?);
696 $self->close();
697 return ($exit == 0);
700 # Helper functions
701 sub get_type {
702 my $file = shift;
703 if (not lstat($file)) {
704 return g_('nonexistent') if $! == ENOENT;
705 syserr(g_('cannot stat %s'), $file);
706 } else {
707 -f _ && return g_('plain file');
708 -d _ && return g_('directory');
709 -l _ && return sprintf(g_('symlink to %s'), readlink($file));
710 -b _ && return g_('block device');
711 -c _ && return g_('character device');
712 -p _ && return g_('named pipe');
713 -S _ && return g_('named socket');
717 =head1 CHANGES
719 =head2 Version 0.xx
721 This is a private module.
723 =cut