FlockDir - override perl flock()
for network or portability
purposes
use File::FlockDir qw (open close flock);
open (FH, ``>$path'');
flock(FH,
2);
close FH;
A flock module for Windows9x and other systems lacking a good perl
flock()
function (not platform specific)
Usage:
use File::FlockDir qw (open close flock);
OR (careful)
use File::FlockDir qw (GLOBAL_open GLOBAL_close GLOBAL_flock);
Rationale: flock on Win95/98 is badly broken but perl code needs to be
portable. One way to do this is to override perl's open(),
flock(),
and close().
We then get an absolute
file specification for all opened files and and use it in a hash to create
a unique lock for the file using the File::LockDir module from Perl Cookbook, by Christiansen and Torkington (O'Reilly, 1998). This module may be
included in the CPAN distribution but belongs to those authors. New code is
deliberately kept at a minimum. As with nflock(),
this will
allow flock()
to work over a network (usually).
May be slow compared to unix flock().
Abnormal termination may leave File::LockDir entries still on the drive. This means the directory locks set by File::LockDir will have to be removed after a system crash to prevent the module from assuming that files locked at the time of the crash are still locked later.
Since the implementation creates a subdirectory in the directory containing
the file that you flock(),
you must have permission to create
a directory where the file is located in order to flock()
that
file over the network.
Perl Cookbook, by Tom Christiansen and Nathan Torkington.
This module is an extension of Perl Cookbook's nflock(),
in chapter 7, section 21 (7.21, pp 264-266).
William Herrera <wherrera@lynxview.com>