From cbb9264ddcce56e25ccde160c9ec6a3fc0edadbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Mon, 2 Feb 2026 19:15:26 +0100 Subject: [PATCH] use tempfile when updating input files (#8981) 0d72789aa37edbac31c49630eba645261204858c --- gallery_dl/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gallery_dl/__init__.py b/gallery_dl/__init__.py index 7c8c0f02..e018748b 100644 --- a/gallery_dl/__init__.py +++ b/gallery_dl/__init__.py @@ -1,11 +1,12 @@ # -*- coding: utf-8 -*- -# Copyright 2014-2025 Mike Fährmann +# Copyright 2014-2026 Mike Fährmann # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. +import os import sys import logging from . import version, config, option, output, extractor, job, util, exception @@ -542,11 +543,14 @@ class InputManager(): def _rewrite(self): url, path, action, indicies = self._item + path_tmp = path + ".tmp" lines = self.files[path] action(lines, indicies) + try: - with open(path, "w", encoding="utf-8") as fp: + with open(path_tmp, "w", encoding="utf-8") as fp: fp.writelines(lines) + os.replace(path_tmp, path) except Exception as exc: self.log.warning( "Unable to update '%s' (%s: %s)",