This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
version bump for File::Copy and add change to delta
[perl5.git] / lib / File / Copy.pm
index cfa74ba..8382565 100644 (file)
@@ -22,7 +22,7 @@ sub syscopy;
 sub cp;
 sub mv;
 
-$VERSION = '2.16';
+$VERSION = '2.19';
 
 require Exporter;
 @ISA = qw(Exporter);
@@ -150,7 +150,7 @@ sub copy {
        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;
            }
@@ -242,8 +242,7 @@ sub copy {
     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;
@@ -313,14 +312,10 @@ sub cp {
            $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;
        }
@@ -504,6 +499,12 @@ be opened for reading. Likewise, the second argument will be
 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