1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2025-06-27 17:08:32 +00:00

Fix state file on Windows

This commit is contained in:
coletdjnz 2025-06-21 12:44:55 +12:00
parent c898d5f738
commit 308e62fa81
No known key found for this signature in database
GPG Key ID: 91984263BB39894A

View File

@ -55,12 +55,12 @@ def retrieve(self):
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):