This repository was archived by the owner on Jul 16, 2022. It is now read-only.
File tree 1 file changed +17
-2
lines changed 1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change 3
3
import sys
4
4
import tempfile
5
5
6
+ try :
7
+ import fcntl
8
+ except ImportError :
9
+ fcntl = None
10
+
6
11
__version__ = '1.0.0'
7
12
8
13
@@ -17,12 +22,22 @@ def _path_to_unicode(x):
17
22
return x
18
23
19
24
25
+ _proper_fsync = os .fsync
26
+
27
+
20
28
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
+
21
36
def _sync_directory (directory ):
22
37
# Ensure that filenames are written to disk
23
38
fd = os .open (directory , 0 )
24
39
try :
25
- os . fsync (fd )
40
+ _proper_fsync (fd )
26
41
finally :
27
42
os .close (fd )
28
43
@@ -154,7 +169,7 @@ def sync(self, f):
154
169
'''responsible for clearing as many file caches as possible before
155
170
commit'''
156
171
f .flush ()
157
- os . fsync (f .fileno ())
172
+ _proper_fsync (f .fileno ())
158
173
159
174
def commit (self , f ):
160
175
'''Move the temporary file to the target location.'''
You can’t perform that action at this time.
0 commit comments