about summary refs log tree commit diff
diff options
context:
space:
mode:
authordf <fieldhouse@gmx.net>2021-10-11 13:10:50 +0100
committerdf <fieldhouse@gmx.net>2021-10-11 13:10:50 +0100
commita941a68d5f9fa3d785713b73c854190a1b23d345 (patch)
tree06db49ed1dd3b963f320280791367a69e7369d74
parent74b53109ff5923df82498ee967c8c263c18f9721 (diff)
downloadyoutube-dl-a941a68d5f9fa3d785713b73c854190a1b23d345.tar.gz
youtube-dl-a941a68d5f9fa3d785713b73c854190a1b23d345.tar.xz
youtube-dl-a941a68d5f9fa3d785713b73c854190a1b23d345.zip
Avoid scrubbing supplied cookie file on failed update
-rw-r--r--youtube_dl/utils.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py
index 02631406c..fcb787570 100644
--- a/youtube_dl/utils.py
+++ b/youtube_dl/utils.py
@@ -2781,7 +2781,8 @@ class YoutubeDLCookieJar(compat_cookiejar.MozillaCookieJar):
             if cookie.expires is None:
                 cookie.expires = 0
 
-        with io.open(filename, 'w', encoding='utf-8') as f:
+        with io.open(filename, 'r+', encoding='utf-8') as f:
+            assert 0 == f.seek(0)
             f.write(self._HEADER)
             now = time.time()
             for cookie in self:
@@ -2813,6 +2814,7 @@ class YoutubeDLCookieJar(compat_cookiejar.MozillaCookieJar):
                 f.write(
                     '\t'.join([cookie.domain, initial_dot, cookie.path,
                                secure, expires, name, value]) + '\n')
+                assert f.tell() == f.truncate()
 
     def load(self, filename=None, ignore_discard=False, ignore_expires=False):
         """Load cookies from a file."""