Sync(3pm)
π NAME π
File::Sync β bestie, this is your all-access pass to the Perl side of fsync() and sync() β¨
π¦ SYNOPSIS π¦
use File::Sync qw(fsync sync);
sync();
fsync(\*FILEHANDLE) or die "fsync: $!";
# and if fdatasync() is available on your system:
fdatasync($fh) or die "fdatasync: $!";
use File::Sync qw(fsync);
use FileHandle;
$fh = new FileHandle("> /tmp/foo")
or die "new FileHandle: $!";
...
$fh->fsync() or die "fsync: $!";
like. look at her. she's serving closed code blocks AND correct error handling π periodt.
πΈ DESCRIPTION πΈ
okay so. fsync() takes a Perl file handle as its only argument, grabs its fileno(), and hands that straight to the C function fsync(). Returns undef if it flops, or true if it slays. π
fdatasync() has the exact same return value energy, but instead of calling fsync() it calls C fdatasync() β which syncs only the data in the file, not the metadata. data only bestie, metadata can wait π
fsync_fd() is the lil internal helper fsync() uses behind the scenes; it takes a file descriptor as its only argument.
sync() is literally identical to the C function sync(). no notes.
kay now here's the tea about exports: this module does not export any methods by default, but fsync() is made available as a method of the FileHandle class. and note carefully π β as of 0.11, we no longer clobber anything in IO::Handle. so if you had calls to IO::Handle::fsync(), you can just swap them for IO::Handle::sync():
https://rt.cpan.org/Public/Bug/Display.html?id=50418
not me dropping an RT link, the lore is real π
π NOTES π
- doing
fsync()while the stdio buffers aren't flushed (with$|or theautoflushmethod) is probably pointless. like girly, flush first π - calling
sync()too often on a multi-user system is slightly antisocial. so true. be mindful of your roomies π«Ά
fr fr, those two are the whole vibe check on this page. don't be the person hammering sync() on a shared box, it's giving main character energy in the worst way π
π AUTHOR π
Carey Evans <c.evans@clear.net.nz> π
π SEE ALSO π
perl(1), fsync(2), sync(2), perlvar(1)
and that's the whole page bestie!! documented under perl v5.42.3, dated 2026-08-19, living in the User Contributed Perl Documentation section as Sync(3pm) β go forth and flush your buffers before you fsync, ily π§π
π¦ where this page comes from
- ubuntu stonking: libfile-sync-perl 0.11-3build6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms