sub cp;
sub mv;
-$VERSION = '2.16';
+$VERSION = '2.19';
require Exporter;
@ISA = qw(Exporter);
my @fs = stat($from);
if (@fs) {
my @ts = stat($to);
- if (@ts && $fs[0] == $ts[0] && $fs[1] == $ts[1]) {
+ if (@ts && $fs[0] == $ts[0] && $fs[1] == $ts[1] && !-p $from) {
carp("'$from' and '$to' are identical (not copied)");
return 0;
}
if ($to_a_handle) {
$to_h = $to;
} else {
- $to = _protect($to) if $to =~ /^\s/s;
- $to_h = \do { local *FH };
+ $to_h = \do { local *FH }; # XXX is this line obsolete?
open $to_h, ">", $to or goto fail_open2;
binmode $to_h or die "($!,$^E)";
$closeto = 1;
$perm &= ~06000;
}
- if ($perm & 02000) { # setgid
+ if ($perm & 02000 && $> != 0) { # if not root, setgid
my $ok = $fromstat[5] == $tostat[5]; # group must match
if ($ok) { # and we must be in group
- my $uname = (getpwuid($>))[0] || '';
- my $group = (getpwuid($>))[3];
- $ok = $group && $group == $fromstat[5] ||
- grep { $_ eq $uname }
- split /\s+/, (getgrgid($fromstat[5]))[3];
+ $ok = grep { $_ == $fromstat[5] } split /\s+/, $)
}
$perm &= ~06000 unless $ok;
}
written to (and created if need be). Trying to copy a file on top
of itself is a fatal error.
+If the destination (second argument) already exists and is a directory,
+and the source (first argument) is not a filehandle, then the source
+file will be copied into the directory specified by the destination,
+using the same base name as the source file. It's a failure to have a
+filehandle as the source when the destination is a directory.
+
B<Note that passing in
files as handles instead of names may lead to loss of information
on some operating systems; it is recommended that you use file