|Welcome to the Monastery|
fsyncing directoriesby betterworld (Curate)
|on Apr 27, 2010 at 10:15 UTC||Need Help??|
betterworld has asked for the wisdom of the Perl Monks concerning the following question:
according to the Linux man page of fsync(2):
Calling fsync() does not necessarily ensure that the entry in the directory containing the file has also reached disk. For that an explicit fsync() on a file descriptor for the directory is also needed.
So, how do we fsync directories in Perl? perldoc POSIX says that fsync() should be done with the sync method in IO::Handle. So I tried this with a directory:
This bails out with "fsync: Invalid argument". According to strace, no fsync syscall is even tried.
I tried opendir too:
with the same result.
On the other hand, an equivalent C program succeeds and properly calls fsync according to strace:
My question: What is the proper way to do fsync with directories in Perl? Or is this just a bug in IO::Handle?
(All tests have been done on a current Debian Squeeze (testing) with perl 5.10.1-12.)