Skip to content

Commit 16f708c

Browse files
ntynitsee
authored andcommitted
Fix File::Copy::copy with pipes on GNU/kFreeBSD
Quoting Petr Salinger in http://bugs.debian.org/537555: The Copy tries to detect whether source and dest are the same files. Unfortunately, on the GNU/kFreeBSD the kernel returns for all pipes as device and inode numbers just zero. See pipe_stat() in http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/kern/sys_pipe.c Patch by Petr Salinger, tests by Niko Tyni.
1 parent bb74b0e commit 16f708c

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

lib/File/Copy.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ sub syscopy;
2222
sub cp;
2323
sub mv;
2424

25-
$VERSION = '2.15';
25+
$VERSION = '2.16';
2626

2727
require Exporter;
2828
@ISA = qw(Exporter);
@@ -150,7 +150,7 @@ sub copy {
150150
my @fs = stat($from);
151151
if (@fs) {
152152
my @ts = stat($to);
153-
if (@ts && $fs[0] == $ts[0] && $fs[1] == $ts[1]) {
153+
if (@ts && $fs[0] == $ts[0] && $fs[1] == $ts[1] && !-p $from) {
154154
carp("'$from' and '$to' are identical (not copied)");
155155
return 0;
156156
}

lib/File/Copy.t

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use Test::More;
1414

1515
my $TB = Test::More->builder;
1616

17-
plan tests => 459;
17+
plan tests => 461;
1818

1919
# We're going to override rename() later on but Perl has to see an override
2020
# at compile time to honor it.
@@ -435,6 +435,19 @@ SKIP: {
435435
}
436436
}
437437

438+
SKIP: {
439+
skip("fork required to test pipe copying", 2)
440+
if (!$Config{'d_fork'});
441+
442+
open(my $IN, "-|") || exec $^X, '-e', 'print "Hello, world!\n"';
443+
open(my $OUT, "|-") || exec $^X, '-ne', 'exit(/Hello/ ? 55 : 0)';
444+
445+
ok(copy($IN, $OUT), "copy pipe to another");
446+
close($OUT);
447+
is($? >> 8, 55, "content copied through the pipes");
448+
close($IN);
449+
}
450+
438451
END {
439452
1 while unlink "file-$$";
440453
1 while unlink "lib/file-$$";

0 commit comments

Comments
 (0)