From fb4654bd911ec7ad15aae2d12e237950db140500 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 21 Jun 2025 08:09:27 +0530 Subject: [PATCH] Windows: Generate catalog: Workaround for systems where a broken antivirus or similar holds open files in the catalog library causing a permission denied error. Fixes #2115084 [Create Catalog fails](https://bugs.launchpad.net/calibre/+bug/2115084) --- src/calibre/gui2/convert/gui_conversion.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/convert/gui_conversion.py b/src/calibre/gui2/convert/gui_conversion.py index ce21d3f4ee..818a10a480 100644 --- a/src/calibre/gui2/convert/gui_conversion.py +++ b/src/calibre/gui2/convert/gui_conversion.py @@ -5,6 +5,7 @@ __docformat__ = 'restructuredtext en' import os from optparse import OptionParser +from calibre.constants import iswindows from calibre.customize.conversion import DummyReporter, OptionRecommendation from calibre.customize.ui import plugin_for_catalog_format from calibre.ebooks.conversion.plumber import Plumber @@ -80,6 +81,10 @@ def gui_catalog(library_path, temp_db_path, fmt, title, dbspec, ids, out_file_na plugin = plugin_for_catalog_format(fmt) return plugin.run(out_file_name, opts, db, notification=notification) finally: - import shutil db.close() - shutil.rmtree(os.path.dirname(temp_db_path)) + from calibre.db.backend import rmtree_with_retry + try: + rmtree_with_retry(temp_db_path) + except PermissionError: + if not iswindows: # probably some antivirus holding a file open, the folder will be deleted on exit anyway + raise