Copy file/dir DOESN'T save permissions

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ofzer
    New Member
    • Sep 2006
    • 6

    Copy file/dir DOESN'T save permissions

    Hi,

    Suspiciously, perl does not save file's permission when coping it.

    In order to implement the copy , I use : use File::Copy; and File::Copy::Rec ursive.

    The BIG problem is that the file permissions wont be saved after coping it to another place.

    I found a clumsy way to keep the permission in copy();
    but I dont have any idea how to achive it in discopy() as well.

    Tnx for your patient ...
    Waiting for your reply

    Ofzer
  • miller
    Recognized Expert Top Contributor
    • Oct 2006
    • 1086

    #2
    I've never come by that issue before, but then again, I've always simply gone with default permissions. At the very least you can simply create a subroutine to mirror the permissions after copying as this is not a time intensive operation like the actual copying itself is.

    [CODE=perl]
    use Carp qw(croak);

    sub mirrorPermissio ns {
    my $oldfile = shift;
    my $newfile = shift;
    croak("Source and destination files must exist") unless -e $oldfile && -e $newfile;

    my $mode = (stat($oldfile) )[2] & 0777;
    return chmod $mode, $newfile;
    }
    [/CODE]

    perldoc chmod
    perldoc stat

    - Miller

    Comment

    Working...