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

Commit 77fb4cb

Browse files
committed
Use F_FULLSYNC on OS X
Fix #6
1 parent b03cda5 commit 77fb4cb

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

atomicwrites/__init__.py

Lines changed: 17 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

@@ -17,12 +22,22 @@ def _path_to_unicode(x):
1722
return x
1823

1924

25+
_proper_fsync = os.fsync
26+
27+
2028
if sys.platform != 'win32':
29+
if hasattr(fcntl, 'F_FULLFSYNC'):
30+
def _proper_fsync(fd):
31+
# https://lists.apple.com/archives/darwin-dev/2005/Feb/msg00072.html
32+
# https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/fsync.2.html
33+
# https://github.com/untitaker/python-atomicwrites/issues/6
34+
fcntl.fcntl(fd, fcntl.F_FULLFSYNC)
35+
2136
def _sync_directory(directory):
2237
# Ensure that filenames are written to disk
2338
fd = os.open(directory, 0)
2439
try:
25-
os.fsync(fd)
40+
_proper_fsync(fd)
2641
finally:
2742
os.close(fd)
2843

@@ -154,7 +169,7 @@ def sync(self, f):
154169
'''responsible for clearing as many file caches as possible before
155170
commit'''
156171
f.flush()
157-
os.fsync(f.fileno())
172+
_proper_fsync(f.fileno())
158173

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

0 commit comments

Comments
 (0)