File-Ownership-Unix
view release on metacpan or search on metacpan
lib/File/Ownership/Unix.pm view on Meta::CPAN
=head1 SYNOPSIS
use File::Ownership::Unix;
my $foo=File::Ownership::Unix->new( 1001, 1001 );
#gets the ownership info for a file
$foo->setFromFile('/tmp/foo');
#chowns a file using the current [GU]ID
$foo->chown('/tmp/bar');
#copies the ownership info from one file to another
$foo->setFromFile('/tmp/foo');
$foo->chown('/tmp/bar');
=head1 METHODS
=head2 new
This initiates the object.
There are two optional arguments taken. The first
one is the UID and the second is the GID.
lib/File/Ownership/Unix.pm view on Meta::CPAN
if( $self->{uid} !~ /[0123456789]*/ ){
$self->{perror}=1;
$self->{error}=1;
$self->{errorString}='"'.$self->{uid}.'" is not a valid value for the UID';
return $self;
}
return $self;
}
=head2 chown
This chowns the specified file.
$foo->chown('/tmp/foo');
if( $foo->error ){
warn('error:'.$foo->error.': '.$foo->errorString);
}
=cut
sub chown{
my $self=$_[0];
my $file=$_[1];
$self->errorblank;
if($self->error){
return undef;
}
if(!defined($file)){
$self->{error}=2;
$self->{errorString}='No file specified';
return undef;
}
if (! -e $file){
$self->{error}=3;
$self->{errorString}='"'.$file.'" does not exist';
return undef;
}
if(!chown( $self->{uid}, $self->{gid}, $file )){
$self->{error}=4;
$self->{errorString}='Failed to chown "'.$file.'" to "'.$self->{uid}.':'.$self->{gid}.'"';
return undef;
}
return 1;
}
=head2 getGID
This returns the currently set GID.
( run in 0.903 second using v1.01-cache-2.11-cpan-5511b514fd6 )