Check for the group entry returned by getpwuid as well when testing
Abigail [Mon, 26 Jan 2009 12:54:48 +0000 (13:54 +0100)]
if a file belongs to the group the user is in.

lib/File/Copy.pm

index fc37ee6..620a2ea 100644 (file)
@@ -317,8 +317,10 @@ sub cp {
            my $ok = $fromstat[5] == $tostat[5];  # group must match
            if ($ok) {                            # and we must be in group
                my $uname = (getpwuid($>))[0] || '';
-               my(@members) = split /\s+/, (getgrgid($fromstat[5]))[3];
-               $ok = grep { $_ eq $uname } @members;
+                my $group = (getpwuid($>))[3];
+                $ok = $group && $group == $fromstat[5] ||
+                      grep { $_ eq $uname }
+                             split /\s+/, (getgrgid($fromstat[5]))[3];
            }
            $perm &= ~06000 unless $ok;
        }