Compare commits
3 Commits
Author | SHA1 | Date |
---|---|---|
vvelox | bed5656282 | |
vvelox | a88964c25c | |
vvelox | bc71165f06 |
|
@ -0,0 +1 @@
|
|||
File-Ownership-Unix/
|
|
@ -1,5 +1,4 @@
|
|||
Revision history for File-Ownership-Unix
|
||||
|
||||
0.01 Date/time
|
||||
First version, released on an unsuspecting world.
|
||||
|
||||
0.0.0 2011-08-14/06:50
|
||||
-Initial release.
|
||||
|
|
|
@ -8,12 +8,13 @@ WriteMakefile(
|
|||
VERSION_FROM => 'lib/File/Ownership/Unix.pm',
|
||||
ABSTRACT_FROM => 'lib/File/Ownership/Unix.pm',
|
||||
($ExtUtils::MakeMaker::VERSION >= 6.3002
|
||||
? ('LICENSE'=> 'perl')
|
||||
: ()),
|
||||
? ('LICENSE'=> 'perl')
|
||||
: ()),
|
||||
PL_FILES => {},
|
||||
PREREQ_PM => {
|
||||
'Test::More' => 0,
|
||||
'Error::Helper' => 0,
|
||||
},
|
||||
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
|
||||
clean => { FILES => 'File-Ownership-Unix-*' },
|
||||
);
|
||||
);
|
||||
|
|
|
@ -1,16 +1,7 @@
|
|||
File-Ownership-Unix
|
||||
|
||||
The README is used to introduce the module and provide instructions on
|
||||
how to install the module, any machine dependencies it may have (for
|
||||
example C compilers and installed libraries) and any other information
|
||||
that should be provided before the module is installed.
|
||||
|
||||
A README file is required for CPAN modules since CPAN extracts the README
|
||||
file from a module distribution so that people browsing the archive
|
||||
can use it to get an idea of the module's uses. It is usually a good idea
|
||||
to provide version information here so that people can decide whether
|
||||
fixes for the module are worth downloading.
|
||||
|
||||
Provides a easy to use object oriented system for working
|
||||
with file ownership.
|
||||
|
||||
INSTALLATION
|
||||
|
||||
|
|
|
@ -2,52 +2,288 @@ package File::Ownership::Unix;
|
|||
|
||||
use warnings;
|
||||
use strict;
|
||||
use base 'Error::Helper';
|
||||
|
||||
=head1 NAME
|
||||
|
||||
File::Ownership::Unix - The great new File::Ownership::Unix!
|
||||
File::Ownership::Unix - A object oriented system for working with file ownership under unix.
|
||||
|
||||
=head1 VERSION
|
||||
|
||||
Version 0.01
|
||||
Version 0.0.0
|
||||
|
||||
=cut
|
||||
|
||||
our $VERSION = '0.01';
|
||||
|
||||
our $VERSION = '0.0.0';
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
Quick summary of what the module does.
|
||||
|
||||
Perhaps a little code snippet.
|
||||
|
||||
use File::Ownership::Unix;
|
||||
|
||||
my $foo=File::Ownership::Unix->new( 1001, 1001 );
|
||||
|
||||
my $foo = File::Ownership::Unix->new();
|
||||
...
|
||||
#gets the ownership info for a file
|
||||
$foo->setFromFile('/tmp/foo');
|
||||
|
||||
=head1 EXPORT
|
||||
#chowns a file using the current [GU]ID
|
||||
$foo->chown('/tmp/bar');
|
||||
|
||||
A list of functions that can be exported. You can delete this section
|
||||
if you don't export anything, such as for a purely object-oriented module.
|
||||
#copies the ownership info from one file to another
|
||||
$foo->setFromFile('/tmp/foo');
|
||||
$foo->chown('/tmp/bar');
|
||||
|
||||
=head1 SUBROUTINES/METHODS
|
||||
=head1 METHODS
|
||||
|
||||
=head2 function1
|
||||
=head2 new
|
||||
|
||||
This initiates the object.
|
||||
|
||||
There are two optional arguments taken. The first
|
||||
one is the UID and the second is the GID.
|
||||
|
||||
Both default to zero.
|
||||
|
||||
my $foo=File::Ownership::Unix->new;
|
||||
if( $foo->error ){
|
||||
warn('error:'.$foo->error.': '.$foo->errorString);
|
||||
}
|
||||
|
||||
=cut
|
||||
|
||||
sub function1 {
|
||||
sub new{
|
||||
my $uid=$_[1];
|
||||
my $gid=$_[2];
|
||||
|
||||
my $self={
|
||||
perror=>undef,
|
||||
error=>undef,
|
||||
errorString=>'',
|
||||
uid=>0,
|
||||
gid=>0,
|
||||
};
|
||||
bless $self;
|
||||
|
||||
if(defined($uid)){
|
||||
$self->{uid}=$uid;
|
||||
}
|
||||
if(defined($gid)){
|
||||
$self->{gid}=$gid;
|
||||
}
|
||||
|
||||
if( $self->{gid} !~ /[0123456789]*/ ){
|
||||
$self->{perror}=1;
|
||||
$self->{error}=1;
|
||||
$self->{errorString}='"'.$self->{gid}.'" is not a valid value for GID';
|
||||
return $self;
|
||||
}
|
||||
|
||||
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 function2
|
||||
=head2 chown
|
||||
|
||||
This chowns the specified file.
|
||||
|
||||
$foo->chown('/tmp/foo');
|
||||
if( $foo->error ){
|
||||
warn('error:'.$foo->error.': '.$foo->errorString);
|
||||
}
|
||||
|
||||
=cut
|
||||
|
||||
sub function2 {
|
||||
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.
|
||||
|
||||
my $gid=$foo->getGID;
|
||||
|
||||
=cut
|
||||
|
||||
sub getGID{
|
||||
my $self=$_[0];
|
||||
|
||||
$self->errorblank;
|
||||
if($self->error){
|
||||
return undef;
|
||||
}
|
||||
|
||||
return $self->{gid};
|
||||
}
|
||||
|
||||
=head2 getUID
|
||||
|
||||
This returns the currently set UID.
|
||||
|
||||
my $gid=$foo->getGID;
|
||||
|
||||
=cut
|
||||
|
||||
sub getUID{
|
||||
my $self=$_[0];
|
||||
|
||||
$self->errorblank;
|
||||
if($self->error){
|
||||
return undef;
|
||||
}
|
||||
|
||||
return $self->{uid};
|
||||
}
|
||||
|
||||
=head2 setGID
|
||||
|
||||
This sets the current GID.
|
||||
|
||||
$foo->setGID('1001');
|
||||
if( $foo->error ){
|
||||
warn('error:'.$foo->error.': '.$foo->errorString);
|
||||
}
|
||||
|
||||
=cut
|
||||
|
||||
sub setGID{
|
||||
my $self=$_[0];
|
||||
my $gid=$_[1];
|
||||
|
||||
$self->errorblank;
|
||||
if($self->error){
|
||||
return undef;
|
||||
}
|
||||
|
||||
if( $gid !~ /[0123456789]*/ ){
|
||||
$self->{error}=1;
|
||||
$self->{errorString}='"'.$gid.'" is not a valid value for GID';
|
||||
return $self;
|
||||
}
|
||||
|
||||
$self->{gid}=$gid;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 setUID
|
||||
|
||||
This sets the current UID.
|
||||
|
||||
$foo->setUID('1001');
|
||||
if( $foo->error ){
|
||||
warn('error:'.$foo->error.': '.$foo->errorString);
|
||||
}
|
||||
|
||||
=cut
|
||||
|
||||
sub setUID{
|
||||
my $self=$_[0];
|
||||
my $uid=$_[1];
|
||||
|
||||
$self->errorblank;
|
||||
if($self->error){
|
||||
return undef;
|
||||
}
|
||||
|
||||
if( $uid !~ /[0123456789]*/ ){
|
||||
$self->{error}=1;
|
||||
$self->{errorString}='"'.$uid.'" is not a valid value for UID';
|
||||
return $self;
|
||||
}
|
||||
|
||||
$self->{uid}=$uid;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 setFromFile
|
||||
|
||||
This sets the current [GU]ID from the specified file.
|
||||
|
||||
$foo->setFromFile('/tmp/foo');
|
||||
if( $foo->error ){
|
||||
warn('error:'.$foo->error.': '.$foo->errorString);
|
||||
}
|
||||
|
||||
=cut
|
||||
|
||||
sub setFromFile{
|
||||
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;
|
||||
}
|
||||
|
||||
$self->{uid}=(stat($file))[4];
|
||||
$self->{gid}=(stat($file))[5];
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head1 ERROR CODES
|
||||
|
||||
=head2 1
|
||||
|
||||
Invalid value for a [GU]ID.
|
||||
|
||||
=head2 2
|
||||
|
||||
No file specified.
|
||||
|
||||
=head2 3
|
||||
|
||||
The specified file does not exist.
|
||||
|
||||
=head2 4
|
||||
|
||||
Failed to cown the specified file.
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
|
||||
|
|
Loading…
Reference in New Issue