From 7dd79eee936b1b30312303251e5597febf298159 Mon Sep 17 00:00:00 2001 From: Luc Ritchie Date: Mon, 24 Apr 2023 00:01:51 -0400 Subject: [PATCH 1/2] save cookies to tempfile, then rename avoids wiping the cookies file if the disk is full --- gallery_dl/extractor/common.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gallery_dl/extractor/common.py b/gallery_dl/extractor/common.py index 9b010c59..18cf0e3a 100644 --- a/gallery_dl/extractor/common.py +++ b/gallery_dl/extractor/common.py @@ -431,8 +431,9 @@ class Extractor(): return try: - with open(path, "w") as fp: + with open(path + ".tmp", "w") as fp: util.cookiestxt_store(fp, self.cookies) + os.replace(path + ".tmp", path) except OSError as exc: self.log.warning("cookies: %s", exc) From 63ac06643fe12b28e89c0d261799b4ec31ef258a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sat, 13 Apr 2024 18:59:18 +0200 Subject: [PATCH 2/2] compute tempfile path only once --- gallery_dl/extractor/common.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gallery_dl/extractor/common.py b/gallery_dl/extractor/common.py index 18cf0e3a..30eae7f0 100644 --- a/gallery_dl/extractor/common.py +++ b/gallery_dl/extractor/common.py @@ -430,10 +430,11 @@ class Extractor(): if not path: return + path_tmp = path + ".tmp" try: - with open(path + ".tmp", "w") as fp: + with open(path_tmp, "w") as fp: util.cookiestxt_store(fp, self.cookies) - os.replace(path + ".tmp", path) + os.replace(path_tmp, path) except OSError as exc: self.log.warning("cookies: %s", exc)