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

Commit

Permalink
Browse files Browse the repository at this point in the history
Use F_FULLSYNC on OS X (#16)
Fix #6
  • Loading branch information
untitaker committed Jul 26, 2016
1 parent 76fba0a commit 2bdd9da
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions atomicwrites/__init__.py
Expand Up @@ -3,6 +3,11 @@
import sys
import tempfile

try:
import fcntl
except ImportError:
fcntl = None

__version__ = '1.0.0'


Expand All @@ -17,12 +22,22 @@ def _path_to_unicode(x):
return x


_proper_fsync = os.fsync


if sys.platform != 'win32':
if hasattr(fcntl, 'F_FULLFSYNC'):
def _proper_fsync(fd):
# https://lists.apple.com/archives/darwin-dev/2005/Feb/msg00072.html
# https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/fsync.2.html
# https://github.com/untitaker/python-atomicwrites/issues/6
fcntl.fcntl(fd, fcntl.F_FULLFSYNC)

def _sync_directory(directory):
# Ensure that filenames are written to disk
fd = os.open(directory, 0)
try:
os.fsync(fd)
_proper_fsync(fd)
finally:
os.close(fd)

Expand Down Expand Up @@ -154,7 +169,7 @@ def sync(self, f):
'''responsible for clearing as many file caches as possible before
commit'''
f.flush()
os.fsync(f.fileno())
_proper_fsync(f.fileno())

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

0 comments on commit 2bdd9da

Please sign in to comment.