call fsync on saving
This commit is contained in:
parent
84df2716b5
commit
3489e4e2d1
|
@ -41,6 +41,9 @@ def safe_overwrite(fname, data, *, method='write', mode='w', encoding=None):
|
|||
# if not using "with", write can fail without exception
|
||||
with open(tmpname, mode, encoding=encoding) as f:
|
||||
getattr(f, method)(data)
|
||||
# see also: https://thunk.org/tytso/blog/2009/03/15/dont-fear-the-fsync/
|
||||
f.flush()
|
||||
os.fsync(f.fileno())
|
||||
# if the above write failed (because disk is full etc), the old data should be kept
|
||||
os.rename(tmpname, fname)
|
||||
|
||||
|
|
Loading…
Reference in New Issue