fix(memory): also fsync directory for rename durability
This commit is contained in:
@@ -369,6 +369,19 @@ class MemoryStore:
|
|||||||
f.flush()
|
f.flush()
|
||||||
os.fsync(f.fileno())
|
os.fsync(f.fileno())
|
||||||
os.replace(tmp_path, self.history_file)
|
os.replace(tmp_path, self.history_file)
|
||||||
|
|
||||||
|
# fsync the directory so the rename is durable.
|
||||||
|
# On Windows, opening a directory with O_RDONLY raises
|
||||||
|
# PermissionError — skip the dir sync there (NTFS
|
||||||
|
# journals metadata synchronously).
|
||||||
|
try:
|
||||||
|
fd = os.open(str(self.history_file.parent), os.O_RDONLY)
|
||||||
|
try:
|
||||||
|
os.fsync(fd)
|
||||||
|
finally:
|
||||||
|
os.close(fd)
|
||||||
|
except PermissionError:
|
||||||
|
pass # Windows — directory fsync not supported
|
||||||
except BaseException:
|
except BaseException:
|
||||||
tmp_path.unlink(missing_ok=True)
|
tmp_path.unlink(missing_ok=True)
|
||||||
raise
|
raise
|
||||||
|
|||||||
Reference in New Issue
Block a user