develooper Front page | perl.beginners | Postings from February 2002

Re: How to copy and keep file permissions

Thread Previous
From:
zentara
Date:
February 21, 2002 08:45
Subject:
Re: How to copy and keep file permissions
Message ID:
qm8a7ugj615k6dqbcsnake5nf78bcf4851@4ax.com
On Thu, 21 Feb 2002 11:09:59 -0500, zentara@highstream.net (Zentara) wrote:

Ooops, made a dumb error. Corrected below.

>The 33261 is file permissions and file type in decimal.
>Under linux, chmod accepts this value, maybe under solaris
>you have to to have the octal value?  
>
>Try this instead:
>
>#!/usr/bin/perl
>use warnings;
>use File::Copy;
>use strict;
>my $mode = (stat $ARGV[0])[2]; #decimal unmasked 
>my $mode = sprintf("%04o", $mode & 07777) ; #octal masked off
>print $mode,"\n";
>copy( "$ARGV[0]", "$ARGV[0]\.bak" );
chmod (oct($mode), "$ARGV[0]\.bak");
>print "Backup completed.\n";
>exit 0;
>

#!/usr/bin/perl
use warnings;
use File::Copy;
use strict;

my $mode = (stat $ARGV[0])[2]; #decimal unmasked 
my $mode = sprintf("%04o", $mode & 07777) ; #octal masked off
print $mode,"\n";
copy( "$ARGV[0]", "$ARGV[0]\.bak" );
chmod (oct($mode), "$ARGV[0]\.bak");
print "Backup completed.\n";
exit 0;



Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About