test: Move test_data_file() to test.h
[dpkg.git] / scripts / Dpkg / Source / Patch.pm
blob0da35b9e5adb38658772931318588c22ddfa5133
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 ':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 and not -f _) {
513 error(g_("diff '%s' patches something which is not a plain file"),
514 $diff);
517 if ($filepatched{$fn}) {
518 $filepatched{$fn}++;
520 if ($opts{fatal_dupes}) {
521 error(g_("diff '%s' patches files multiple times; split the " .
522 'diff in multiple files or merge the hunks into a ' .
523 'single one'), $diff);
524 } elsif ($opts{verbose} and $filepatched{$fn} == 2) {
525 warning(g_("diff '%s' patches file %s more than once"), $diff, $fn)
527 } else {
528 $filepatched{$fn} = 1;
529 push @patchorder, $fn;
532 # read hunks
533 my $hunk = 0;
534 while (defined($line = _getline($self))) {
535 # read hunk header (@@)
536 next if $line =~ /^\\ /;
537 last unless $line =~ /^@@ -\d+(,(\d+))? \+\d+(,(\d+))? @\@(?: .*)?$/;
538 my ($olines, $nlines) = ($1 ? $2 : 1, $3 ? $4 : 1);
539 # read hunk
540 while ($olines || $nlines) {
541 unless (defined($line = _getline($self))) {
542 if (($olines == $nlines) and ($olines < 3)) {
543 warning(g_("unexpected end of diff '%s'"), $diff)
544 if $opts{verbose};
545 last;
546 } else {
547 error(g_("unexpected end of diff '%s'"), $diff);
550 next if $line =~ /^\\ /;
551 # Check stats
552 if ($line =~ /^ / or length $line == 0) {
553 --$olines;
554 --$nlines;
555 } elsif ($line =~ /^-/) {
556 --$olines;
557 } elsif ($line =~ /^\+/) {
558 --$nlines;
559 } else {
560 error(g_("expected [ +-] at start of line %d of diff '%s'"),
561 $., $diff);
564 $hunk++;
566 unless ($hunk) {
567 error(g_("expected ^\@\@ at line %d of diff '%s'"), $., $diff);
570 close($self);
571 unless ($diff_count) {
572 warning(g_("diff '%s' doesn't contain any patch"), $diff)
573 if $opts{verbose};
575 *$self->{analysis}{$destdir}{dirtocreate} = \%dirtocreate;
576 *$self->{analysis}{$destdir}{filepatched} = \%filepatched;
577 *$self->{analysis}{$destdir}{patchorder} = \@patchorder;
578 *$self->{analysis}{$destdir}{patchheader} = $patch_header;
579 return *$self->{analysis}{$destdir};
582 sub prepare_apply {
583 my ($self, $analysis, %opts) = @_;
584 if ($opts{create_dirs}) {
585 foreach my $dir (keys %{$analysis->{dirtocreate}}) {
586 eval { make_path($dir, { mode => 0777 }) };
587 syserr(g_('cannot create directory %s'), $dir) if $@;
592 sub apply {
593 my ($self, $destdir, %opts) = @_;
594 # Set default values to options
595 $opts{force_timestamp} //= 1;
596 $opts{remove_backup} //= 1;
597 $opts{create_dirs} //= 1;
598 $opts{options} ||= [
599 '-t',
600 '-F', '0',
601 '-N',
602 '-p1',
603 '-u',
604 '-V', 'never',
605 '-b',
606 '-z', '.dpkg-orig',
608 $opts{add_options} //= [];
609 push @{$opts{options}}, @{$opts{add_options}};
610 # Check the diff and create missing directories
611 my $analysis = $self->analyze($destdir, %opts);
612 $self->prepare_apply($analysis, %opts);
613 # Apply the patch
614 $self->ensure_open('r');
615 my ($stdout, $stderr) = ('', '');
616 spawn(
617 exec => [ $Dpkg::PROGPATCH, @{$opts{options}} ],
618 chdir => $destdir,
619 env => { LC_ALL => 'C', PATCH_GET => '0' },
620 delete_env => [ 'POSIXLY_CORRECT' ], # ensure expected patch behaviour
621 wait_child => 1,
622 nocheck => 1,
623 from_handle => $self->get_filehandle(),
624 to_string => \$stdout,
625 error_to_string => \$stderr,
627 if ($?) {
628 print { *STDOUT } $stdout;
629 print { *STDERR } $stderr;
630 subprocerr("LC_ALL=C $Dpkg::PROGPATCH " . join(' ', @{$opts{options}}) .
631 ' < ' . $self->get_filename());
633 $self->close();
634 # Reset the timestamp of all the patched files
635 # and remove .dpkg-orig files
636 my @files = keys %{$analysis->{filepatched}};
637 my $now = $opts{timestamp};
638 $now //= fs_time($files[0]) if $opts{force_timestamp} && scalar @files;
639 foreach my $fn (@files) {
640 if ($opts{force_timestamp}) {
641 utime($now, $now, $fn) or $! == ENOENT
642 or syserr(g_('cannot change timestamp for %s'), $fn);
644 if ($opts{remove_backup}) {
645 $fn .= '.dpkg-orig';
646 unlink($fn) or syserr(g_('remove patch backup file %s'), $fn);
649 return $analysis;
652 # Verify if check will work...
653 sub check_apply {
654 my ($self, $destdir, %opts) = @_;
655 # Set default values to options
656 $opts{create_dirs} //= 1;
657 $opts{options} ||= [
658 '--dry-run',
659 '-s',
660 '-t',
661 '-F', '0',
662 '-N',
663 '-p1',
664 '-u',
665 '-V', 'never',
666 '-b',
667 '-z', '.dpkg-orig',
669 $opts{add_options} //= [];
670 push @{$opts{options}}, @{$opts{add_options}};
671 # Check the diff and create missing directories
672 my $analysis = $self->analyze($destdir, %opts);
673 $self->prepare_apply($analysis, %opts);
674 # Apply the patch
675 $self->ensure_open('r');
676 my $patch_pid = spawn(
677 exec => [ $Dpkg::PROGPATCH, @{$opts{options}} ],
678 chdir => $destdir,
679 env => { LC_ALL => 'C', PATCH_GET => '0' },
680 delete_env => [ 'POSIXLY_CORRECT' ], # ensure expected patch behaviour
681 from_handle => $self->get_filehandle(),
682 to_file => '/dev/null',
683 error_to_file => '/dev/null',
685 wait_child($patch_pid, nocheck => 1);
686 my $exit = WEXITSTATUS($?);
687 subprocerr("$Dpkg::PROGPATCH --dry-run") unless WIFEXITED($?);
688 $self->close();
689 return ($exit == 0);
692 # Helper functions
693 sub get_type {
694 my $file = shift;
695 if (not lstat($file)) {
696 return g_('nonexistent') if $! == ENOENT;
697 syserr(g_('cannot stat %s'), $file);
698 } else {
699 -f _ && return g_('plain file');
700 -d _ && return g_('directory');
701 -l _ && return sprintf(g_('symlink to %s'), readlink($file));
702 -b _ && return g_('block device');
703 -c _ && return g_('character device');
704 -p _ && return g_('named pipe');
705 -S _ && return g_('named socket');
709 =head1 CHANGES
711 =head2 Version 0.xx
713 This is a private module.
715 =cut