mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-06-28 01:18:30 +00:00
Fix state file on Windows
This commit is contained in:
parent
c898d5f738
commit
308e62fa81
@ -55,12 +55,12 @@ def retrieve(self):
|
|||||||
|
|
||||||
def update(self, sabr_document):
|
def update(self, sabr_document):
|
||||||
# Attempt to write progress document somewhat atomically to avoid corruption
|
# 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:
|
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)
|
os.replace(tf.name, self.filename)
|
||||||
finally:
|
finally:
|
||||||
if os.path.exists(tf.name):
|
if os.path.exists(tf.name):
|
||||||
|
Loading…
Reference in New Issue
Block a user