Sympa::LockedFile(3Sympa)
π Sympa::LockedFile π
okay bestie, welcome to Sympa::LockedFile β the Filehandle with locking situation, straight out of sympa 6.2.80. it's giving β¨ main character filehandle β¨ and honestly? we're obsessed. π«Ά
β¨ SYNOPSIS β¨
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;
like look at that. create β lock acquired. read/write/seek/truncate β do literally whatever. $fh->close β lock released, we're done, periodt. π
πΈ DESCRIPTION πΈ
This class implements a filehandle with locking. that's the whole vibe: a filehandle that knows how to lock itself so your processes don't fight over the same file like it's the last slice of birthday cake. π
π Class Methods π
new ( [ $file, [ $blocking_timeout, [ $mode ] ] ] )β creates a new object. and if you pass in any of those optional parameters? it also opens a file and acquires the lock for you. two birds, one adorable stone. πͺ¨β¨
Parameters:
See open().
Returns:
A brand new object, or a false value if something went wrong. π
last_error ( )β get a string describing the most recent error. it's the receipts, bestie. π§Ύ
Parameters:
None.
Returns:
A string β or, if the recent operation was a success, undef. slay.
π¦ Instance Methods π¦
Instances of Sympa::LockedFile support the methods provided by IO::File. yes, all of them. we're a whole IO::File with extra β¨lockβ¨ energy, iykyk.
open ( $file, [ $blocking_timeout, [ $mode ] ] )β opens the file specified by$fileand acquires a lock on it. the moment. π
Parameters:
$fileβ the path of the file to be locked and opened. that's your target, bestie. π―$blocking_timeoutβ programs will block up to this many seconds before returningundef(meaning: could not get a lock, so sad π). but if you hand it a negative value, programs will not block β they'll fail immediately instead, a.k.a."LOCK_NB".
Default is 30.
β οΈ however!! if an existing lock is older than1200seconds (that's20minutes, fr fr), the lock will be stolen. yes, stolen. not even sorry. π
$modeβ the mode to open the file with. if it implies any writing operations ('>','>>','+<', ...), it tries to acquire an exclusive lock ("LOCK_EX"); otherwise it goes with a shared lock ("LOCK_SH").
Default is '<'.
plus there's a special little mode: '+' will acquire an exclusive lock without opening the file. in that case the file doesn't even have to exist. iconic behavior honestly. π
the numeric modes used for sysopen() (e.g. "O_CREAT") are not supported. nope. don't try it. π
Returns:
A new filehandle. if acquiring the lock failed, it won't open the file. if opening the file failed, it releases the acquired lock. either way? false value. π
close ( )β closes the filehandle and releases the lock on it.
ngl, even just destroying the instance will safely close the filehandle and release the lock. so you're covered either way. π«Ά
Parameters:
None.
Returns:
If close succeeded, true value β otherwise false value.
β οΈ if the filehandle had not been locked by the current process, this method will safely close it and then die. dramatic? maybe. necessary? absolutely. π
π§ Following methods are specific to this module. π§
basename ( [ $level ] )β gets the base name of the locked file. cute little name reveal. πΈextend ( )β extends the stale lock timeout. the lock will never be stolen in1200seconds again. take that, thief. π₯
Parameters:
None.
Returns:
If the extension succeeded, true value β otherwise false value.
β οΈ if the filehandle had not been locked by the current process, this method will die doing nothing. just. die. π
rename ( $destfile )β renames the file, closes the filehandle and releases the lock on it. the filehandle must have acquired an exclusive lock. no shared-lock girlies allowed on this one. π
Parameter:
$destfileβ the destination path of the renaming. where we're headed, bestie. π
Returns:
If renaming succeeded, true value. otherwise false value and it does not release the lock. in both cases, the filehandle is closed anyway. so like, closed either way β noted. π
β οΈ if the filehandle had not been locked by the current process, this method will die doing nothing. π
unlink ( )β deletes the file and releases the lock on it. gone. deleted. no cap. ποΈ
Parameters:
None.
Returns:
If unlink succeeded, true value. otherwise false value and it does not release the lock.
β οΈ if the filehandle had not been locked by the current process, this method will die without deleting the file. the file stays. the method does not. π
β SEE ALSO β
"Functions for filehandles, files or directories" in perlfunc, "I/O Operators" in perlop, IO::File, File::NFSLock. go read those too, bestie, they're the moment. ππ
π HISTORY π
- The Lock module was written by Olivier SalaΓΌn and appeared on Sympa
5.3. π - Support for NFS was added by Kazuo Moriwaka. π¦
- The rewritten
Sympa::LockedFilemodule was initially written by IKEDA Soji for Sympa6.2. π
π and that's the whole lore, bestie. filehandle, locked. vibe check: passed. periodt. π β¨
sympa 6.2.80 β dated 2026-10-19 β Sympa::LockedFile(3Sympa) π«ΆπΈπ
π¦ where this page comes from
- fedora 43: sympa-devel-doc 6.2.80-2.fc43 Β· GPL-2.0-or-later AND (OFL-1.1-RFN AND MIT) AND OFL-1.1-RFN AND MIT and (MIT OR GPL-2.0-only)
- fedora 44: sympa-devel-doc 6.2.80-2.fc44 Β· GPL-2.0-or-later AND (OFL-1.1-RFN AND MIT) AND OFL-1.1-RFN AND MIT and (MIT OR GPL-2.0-only)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms