X-Git-Url: https://git.p6c8.net/devedit.git/blobdiff_plain/7cf8cb75f44d1e189cec159cf5c50fb14a13e85c..c1339294a28926ba7593adbd3d48ef9f1bcf6dfa:/modules/File/UseList.pm diff --git a/modules/File/UseList.pm b/modules/File/UseList.pm index 33ef12c..29db298 100644 --- a/modules/File/UseList.pm +++ b/modules/File/UseList.pm @@ -1,20 +1,19 @@ package File::UseList; # -# File::UseList +# File::UseList 1.3 # # Run a list with files that are currently in use -# (bases upon Filing::UseList by Roland Bluethgen ) +# (bases on Filing::UseList by Roland Bluethgen ) # -# Author: Patrick Canterino -# Last modified: 09-26-2003 +# Author: Patrick Canterino +# Last modified: 2004-12-03 # use strict; use Carp qw(croak); - -our $VERSION = '1.1'; +use Fcntl; # new() # @@ -24,7 +23,7 @@ our $VERSION = '1.1'; # lockfile => Lock file (Default: List file + .lock) # timeout => Lock timeout in seconds (Default: 10) # -# Return: File::UseList object +# Return: File::UseList object (Blessed Reference) sub new(%) { @@ -32,17 +31,16 @@ sub new(%) # Check if we got all the necessary information - croak "Missing path of list file" unless($args{'listfile'}); - $args{'lockfile'} = $args{'listfile'}.".lock" unless($args{'lockfile'}); # Default filename of lock file - $args{'timeout'} = 10 unless($args{'timeout'}); # Default timeout + croak "Missing path to list file" unless($args{'listfile'}); + $args{'lockfile'} = $args{'listfile'}.".lock" unless($args{'lockfile'}); # Default filename of lock file + $args{'timeout'} = 10 unless($args{'timeout'}); # Default timeout - # Create $self + # Add some other information - my $self = \%args; - $self->{'files'} = []; - $self->{'locked'} = 0; + $args{'files'} = []; + $args{'locked'} = 0; - return bless($self,$class); + return bless(\%args,$class); } # lock() @@ -98,24 +96,21 @@ sub unlock if($self->{'locked'}) { - return 1 if(-f $lockfile); # Hmmm... - - open(LOCKFILE,">",$lockfile) or return; - close(LOCKFILE) or return; + sysopen(LOCKFILE,$lockfile,O_WRONLY | O_CREAT | O_TRUNC) or return; + close(LOCKFILE) or return; $self->{'locked'} = 0; - return 1; } - # The list wasn't lock by ourselves + # The list wasn't lock by us or it isn't locked at all return; } # load() # -# Load the list with files +# Load the list with files from the list file # # Params: -nothing- # @@ -129,9 +124,9 @@ sub load # Read out the file and split the content line-per-line - open(FILE,"<".$file) or return; + sysopen(FILE,$file,O_RDONLY) or return; read(FILE, my $content, -s $file); - close(FILE) or return; + close(FILE) or return; my @files = split(/\015\012|\012|\015/,$content); @@ -152,7 +147,7 @@ sub load # save() # -# Save the list with files +# Write the list with files back to the list file # # Params: -nothing- # @@ -168,15 +163,13 @@ sub save my $data = (@$files) ? join("\n",@$files) : ''; - open(FILE,">",$temp) or return; - print FILE $data or do { close(FILE); return }; - close(FILE) or return; + sysopen(FILE,$temp,O_WRONLY | O_CREAT | O_TRUNC) or return; + print FILE $data or do { close(FILE); return }; + close(FILE) or return; - rename($temp,$file) and return 1; + rename($temp,$file) or return; - # Rubbish - - return; + return 1; } # add_file() @@ -184,6 +177,8 @@ sub save # Add a file to the list # # Params: File +# +# Return: Status code (Boolean) sub add_file($) { @@ -195,6 +190,7 @@ sub add_file($) return if($self->in_use($file)); push(@$files,$file); + return 1; } # remove_file() @@ -202,6 +198,8 @@ sub add_file($) # Remove a file from the list # # Params: File +# +# Return: Status code (Boolean) sub remove_file($) { @@ -219,11 +217,28 @@ sub remove_file($) if($files->[$x] eq $file) { splice(@$files,$x,1); - last; + return 1; } } } +# remove_all() +# +# Remove all files from the list +# +# Params: -nothing- +# +# Return: -nothing- + +sub remove_all +{ + my $self = shift; + + $self->{'files'} = []; + + return; +} + # in_use() # # Check if a file is in the list @@ -263,4 +278,4 @@ sub unused($) 1; # -### Ende ### \ No newline at end of file +### End ### \ No newline at end of file