From: pcanterino <> Date: Fri, 21 Nov 2003 17:08:28 +0000 (+0000) Subject: Version 1.2: X-Git-Tag: version_1_2~8 X-Git-Url: https://git.p6c8.net/devedit.git/commitdiff_plain/7ffe3e6f2a95cf181424442055503714913a5e05?ds=sidebyside Version 1.2: - We don't use the FILEHANDLE,MODE,FILENAME version of open() any more, because it doesn't work everywhere - add_file() and remove_file() now return true if they succeed - unlock() doesn't check any more if the lock file already exists --- diff --git a/modules/File/UseList.pm b/modules/File/UseList.pm index 22d1bcc..6f7ff62 100644 --- a/modules/File/UseList.pm +++ b/modules/File/UseList.pm @@ -1,13 +1,13 @@ package File::UseList; # -# File::UseList 1.1.1 +# File::UseList 1.2 # # Run a list with files that are currently in use # (bases on Filing::UseList by Roland Bluethgen ) # # Author: Patrick Canterino -# Last modified: 2003-10-17 +# Last modified: 2003-11-21 # use strict; @@ -95,11 +95,8 @@ sub unlock if($self->{'locked'}) { - unless(-f $lockfile) - { - open(LOCKFILE,">",$lockfile) or return; - close(LOCKFILE) or return; - } + open(LOCKFILE,">$lockfile") or return; + close(LOCKFILE) or return; $self->{'locked'} = 0; return 1; @@ -126,9 +123,9 @@ sub load # Read out the file and split the content line-per-line - open(FILE,"<",$file) or return; + open(FILE,"<$file") or return; read(FILE, my $content, -s $file); - close(FILE) or return; + close(FILE) or return; my @files = split(/\015\012|\012|\015/,$content); @@ -165,11 +162,11 @@ 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; + open(FILE,">$temp") or return; + print FILE $data or do { close(FILE); return }; + close(FILE) or return; - rename($temp,$file) or return; + rename($temp,$file) or return; return 1; } @@ -179,6 +176,8 @@ sub save # Add a file to the list # # Params: File +# +# Return: Status code (Boolean) sub add_file($) { @@ -190,6 +189,7 @@ sub add_file($) return if($self->in_use($file)); push(@$files,$file); + return 1; } # remove_file() @@ -197,6 +197,8 @@ sub add_file($) # Remove a file from the list # # Params: File +# +# Return: Status code (Boolean) sub remove_file($) { @@ -214,7 +216,7 @@ sub remove_file($) if($files->[$x] eq $file) { splice(@$files,$x,1); - last; + return 1; } } }