mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-04-21 17:13:41 +02:00
Delete temp file used for atomic writes even if renaming fails
This commit is contained in:
parent
007099dd60
commit
0012b7cd64
1 changed files with 7 additions and 3 deletions
|
|
@ -367,9 +367,13 @@ def commit_data(file_path, data):
|
|||
from calibre.utils.filenames import atomic_rename
|
||||
bdir = os.path.dirname(file_path)
|
||||
os.makedirs(bdir, exist_ok=True, mode=CONFIG_DIR_MODE)
|
||||
with tempfile.NamedTemporaryFile(dir=bdir, delete=False) as f:
|
||||
f.write(data)
|
||||
atomic_rename(f.name, file_path)
|
||||
try:
|
||||
with tempfile.NamedTemporaryFile(dir=bdir, delete=False) as f:
|
||||
f.write(data)
|
||||
atomic_rename(f.name, file_path)
|
||||
finally:
|
||||
with suppress(FileNotFoundError, NameError):
|
||||
os.remove(f.name)
|
||||
|
||||
|
||||
class Config(ConfigInterface):
|
||||
|
|
|
|||
Loading…
Reference in a new issue