Skip to content
This repository was archived by the owner on Jul 16, 2022. It is now read-only.

Commit 13b6caf

Browse files
committed
Use F_FULLSYNC on OS X
Fix #6
1 parent 4dae2ae commit 13b6caf

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

atomicwrites/__init__.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
import sys
44
import tempfile
55

6+
try:
7+
import fcntl
8+
except ImportError:
9+
fcntl = None
10+
611
__version__ = '1.0.0'
712

813

@@ -18,11 +23,17 @@ def _path_to_unicode(x):
1823

1924

2025
if sys.platform != 'win32':
26+
_proper_fsync = os.fsync
27+
28+
if hasattr(fcntl, 'F_FULLFSYNC'):
29+
def _proper_fsync(fd):
30+
fcntl.fcntl(fd, fcntl.F_FULLFSYNC)
31+
2132
def _sync_directory(directory):
2233
# Ensure that filenames are written to disk
2334
fd = os.open(directory, 0)
2435
try:
25-
os.fsync(fd)
36+
_proper_fsync(fd)
2637
finally:
2738
os.close(fd)
2839

@@ -154,7 +165,7 @@ def sync(self, f):
154165
'''responsible for clearing as many file caches as possible before
155166
commit'''
156167
f.flush()
157-
os.fsync(f.fileno())
168+
_proper_fsync(f.fileno())
158169

159170
def commit(self, f):
160171
'''Move the temporary file to the target location.'''

0 commit comments

Comments
 (0)