From 0c01357f8b4ba689b42ef7c0d04aa0cfcf02f18e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 29 Dec 2017 11:25:20 +0530 Subject: [PATCH] Edit Book: Use the cache directory rather than the temp directory to store working files. Hopefully prevents temp file cleaners from destroying books. See #1740460 (Edit Book feature results in error after previously editing successfully) --- src/calibre/gui2/tweak_book/boss.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/tweak_book/boss.py b/src/calibre/gui2/tweak_book/boss.py index e10a96f3b9..c1187ffb5f 100644 --- a/src/calibre/gui2/tweak_book/boss.py +++ b/src/calibre/gui2/tweak_book/boss.py @@ -296,7 +296,9 @@ class Boss(QObject): self.container_count = -1 if self.tdir: shutil.rmtree(self.tdir, ignore_errors=True) - self.tdir = PersistentTemporaryDirectory() + # We use the cache dir rather than the temporary dir to try and prevent + # temp file cleaners from nuking ebooks. See https://bugs.launchpad.net/bugs/1740460 + self.tdir = PersistentTemporaryDirectory(prefix='calibre-ew-', dir=cache_dir()) self._edit_file_on_open = edit_file self._clear_notify_data = clear_notify_data self.gui.blocking_job('open_book', _('Opening book, please wait...'), self.book_opened, get_container, path, tdir=self.mkdtemp())