Skip to content

Commit cbb9264

Browse files
committed
use tempfile when updating input files (#8981)
0d72789
1 parent e37fe05 commit cbb9264

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

gallery_dl/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# -*- coding: utf-8 -*-
22

3-
# Copyright 2014-2025 Mike Fährmann
3+
# Copyright 2014-2026 Mike Fährmann
44
#
55
# This program is free software; you can redistribute it and/or modify
66
# it under the terms of the GNU General Public License version 2 as
77
# published by the Free Software Foundation.
88

9+
import os
910
import sys
1011
import logging
1112
from . import version, config, option, output, extractor, job, util, exception
@@ -542,11 +543,14 @@ def error(self):
542543

543544
def _rewrite(self):
544545
url, path, action, indicies = self._item
546+
path_tmp = path + ".tmp"
545547
lines = self.files[path]
546548
action(lines, indicies)
549+
547550
try:
548-
with open(path, "w", encoding="utf-8") as fp:
551+
with open(path_tmp, "w", encoding="utf-8") as fp:
549552
fp.writelines(lines)
553+
os.replace(path_tmp, path)
550554
except Exception as exc:
551555
self.log.warning(
552556
"Unable to update '%s' (%s: %s)",

0 commit comments

Comments
 (0)