From 308e62fa813e3e152c197152873a6fe7ddafa25c Mon Sep 17 00:00:00 2001 From: coletdjnz Date: Sat, 21 Jun 2025 12:44:55 +1200 Subject: [PATCH] Fix state file on Windows --- yt_dlp/downloader/sabr/_state.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/yt_dlp/downloader/sabr/_state.py b/yt_dlp/downloader/sabr/_state.py index 5663c58bf..9e39e71fc 100644 --- a/yt_dlp/downloader/sabr/_state.py +++ b/yt_dlp/downloader/sabr/_state.py @@ -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):