From 3bf65b261e1b22603c80193a3822a2d5a267f316 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 21 Oct 2019 08:43:37 +0530 Subject: [PATCH] Make icon theme cover file writing atomic --- src/calibre/gui2/icon_theme.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/icon_theme.py b/src/calibre/gui2/icon_theme.py index e1bb2b3e52..533bf6f292 100644 --- a/src/calibre/gui2/icon_theme.py +++ b/src/calibre/gui2/icon_theme.py @@ -475,8 +475,10 @@ def get_cover(metadata): etag = etag.decode('utf-8') cached, etag = download_cover(metadata['cover-url'], etag, cached) if cached: - with open(cover_file, 'wb') as f: + aname = cover_file + '.atomic' + with open(aname, 'wb') as f: f.write(cached) + atomic_rename(aname, cover_file) if etag: with open(etag_file, 'wb') as f: f.write(as_bytes(etag))