Skip to content

Commit c8682ab

Browse files
committed
Add section about fsync
1 parent 68c2fa6 commit c8682ab

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

README.rst

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ that the temporary file resides on the same filesystem.
4242

4343
The temporary file will then be atomically moved to the target location: On
4444
POSIX, it will use ``rename`` if files should be overwritten, otherwise a
45-
combination of ``link`` and ``unlink``. On Windows, it uses ``MoveFileEx`` (see
46-
MSDN_) through stdlib's ``ctypes`` with the appropriate flags.
45+
combination of ``link`` and ``unlink``. On Windows, it uses MoveFileEx_ through
46+
stdlib's ``ctypes`` with the appropriate flags.
4747

4848
Note that with ``link`` and ``unlink``, there's a timewindow where the file
4949
might be available under two entries in the filesystem: The name of the
@@ -53,7 +53,21 @@ Also note that the permissions of the target file may change this way. In some
5353
situations a ``chmod`` can be issued without any concurrency problems, but
5454
since that is not always the case, this library doesn't do it by itself.
5555

56-
.. _MSDN: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365240%28v=vs.85%29.aspx
56+
.. _MoveFileEx: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365240%28v=vs.85%29.aspx
57+
58+
fsync
59+
-----
60+
61+
On POSIX, ``fsync`` is invoked on the temporary file after it is written (to
62+
flush file content and metadata), and on the parent directory after the file is
63+
moved (to flush filename).
64+
65+
``fsync`` does not take care of disks' internal buffers, but there don't seem
66+
to be any standard POSIX APIs for that. On OS X, ``fcntl`` is used with
67+
``F_FULLFSYNC`` instead of ``fsync`` for that reason.
68+
69+
On Windows, `_commit <https://msdn.microsoft.com/en-us/library/17618685.aspx>`_
70+
is used, but there are no guarantees about disk internal buffers.
5771

5872
Alternatives and Credit
5973
=======================

0 commit comments

Comments
 (0)