Sympa::LockedFile(3Sympa) | sympa 6.2.70 | Sympa::LockedFile(3Sympa) |
Sympa::LockedFile - Filehandle with locking
use Sympa::LockedFile; # Create filehandle acquiring lock. my $fh = Sympa::LockedFile->new('/path/to/file', 20, '+<') or die; # or, my $fh = Sympa::LockedFile->new(); $fh->open('/path/to/file', 20, '+<') or die; # Operations... while (<$fh>) { ... } seek $fh, 0, 0; truncate $fh, 0; print $fh "blah blah\n"; # et cetera. # Close filehandle releasing lock. $fh->close;
This class implements a filehandle with locking.
Parameters:
See open().
Returns:
New object or, if something went wrong, false value.
Parameters:
None.
Returns:
String or, if recent operation was success, "undef".
Instances of Sympa::LockedFile support the methods provided by IO::File.
Parameters:
Default is 30.
However, if existing lock is older than 1200 seconds i.e. 20 minutes, lock will be stolen.
Default is '<'.
Additionally, a special mode '+' will acquire exclusive lock without opening file. In this case the file does not have to exist.
The numeric modes used for sysopen() (e.g. "O_CREAT") are not supported.
Returns:
New filehandle. If acquiring lock failed, won't open file. If opening file failed, releases acquired lock. In both cases returns false value.
Note that destruction of instance will safely close filehandle and release lock.
Parameters:
None.
Returns:
If close succeeded, returns true value, otherwise false value.
If filehandle had not been locked by current process, this method will safely close it and die.
Following methods are specific to this module.
Parameters:
None.
Returns:
If extension succeeded, returns true value, otherwise false value.
If filehandle had not been locked by current process, this method will die doing nothing.
Parameter:
Returns:
If renaming succeeded, returns true value, otherwise false value and does not release lock. In both cases filehandle is closed anyway.
If filehandle had not been locked by current process, this method will die doing nothing.
Parameters:
None.
Returns:
If unlink succeeded, returns true value, otherwise false value and does not release lock.
If filehandle had not been locked by current process, this method will die without deleting file.
"Functions for filehandles, files or directories" in perlfunc, "I/O Operators" in perlop, IO::File, File::NFSLock.
Lock module written by Olivier Salauen appeared on Sympa 5.3.
Support for NFS was added by Kazuo Moriwaka.
Rewritten Sympa::LockedFile module was initially written by IKEDA Soji for Sympa 6.2.
2023-01-26 | 6.2.70 |