Fix state file on Windows

pull/13515/head
coletdjnz 2 months ago
parent c898d5f738
commit 308e62fa81
No known key found for this signature in database
GPG Key ID: 91984263BB39894A

@ -55,12 +55,12 @@ class SabrStateFile:
def update(self, sabr_document):
# Attempt to write progress document somewhat atomically to avoid corruption
tf = tempfile.NamedTemporaryFile(delete=False, dir=os.path.dirname(self.filename))
with tempfile.NamedTemporaryFile('wb', delete=False, dir=os.path.dirname(self.filename)) as tf:
tf.write(self.serialize(sabr_document))
tf.flush()
os.fsync(tf.fileno())
try:
with open(tf.name, 'wb') as f:
f.write(self.serialize(sabr_document))
f.flush()
os.fsync(f.fileno())
os.replace(tf.name, self.filename)
finally:
if os.path.exists(tf.name):

Loading…
Cancel
Save