From b8e6798ad3f45cb2c6ff2ed23185d55030605cd7 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 13 Dec 2024 07:01:44 +0530 Subject: [PATCH] Viewer: Fix some HTMLZ files not opening on some systems. Fixes #2091451 [HTMLZ Failing To Open With ebook-viewer](https://bugs.launchpad.net/calibre/+bug/2091451) The bug is triggered by different filesystem traversal orders. Sigh. --- .../ebooks/conversion/plugins/htmlz_input.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/calibre/ebooks/conversion/plugins/htmlz_input.py b/src/calibre/ebooks/conversion/plugins/htmlz_input.py index faa581d7bc..88a0edf03a 100644 --- a/src/calibre/ebooks/conversion/plugins/htmlz_input.py +++ b/src/calibre/ebooks/conversion/plugins/htmlz_input.py @@ -33,7 +33,7 @@ class HTMLZInput(InputFormatPlugin): # Find the HTML file in the archive. It needs to be # top level. index = '' - multiple_html = False + multiple_html = [] # Get a list of all top level files in the archive. for x in os.listdir('.'): if os.path.isfile(x): @@ -51,14 +51,16 @@ class HTMLZInput(InputFormatPlugin): # called index. if not index: index = x - else: - multiple_html = True + elif x != index: + if not multiple_html: + multiple_html = [index] + multiple_html.append(x) # Warn the user if there multiple HTML file in the archive. HTMLZ # supports a single HTML file. A conversion with a multiple HTML file # HTMLZ archive probably won't turn out as the user expects. With # Multiple HTML files ZIP input should be used in place of HTMLZ. if multiple_html: - log.warn(_('Multiple HTML files found in the archive. Only %s will be used.') % index) + log.warn(_('Multiple HTML files found in the archive {0}. Only {1} will be used.').format(', '.join(multiple_html), index)) if index: with open(index, 'rb') as tf: @@ -113,8 +115,9 @@ class HTMLZInput(InputFormatPlugin): opf = x break if opf: - opf = OPF(opf, basedir=os.getcwd()) - cover_path = opf.raster_cover or opf.cover + opf_parsed = OPF(opf, basedir=os.getcwd()) + cover_path = opf_parsed.raster_cover or opf_parsed.cover + os.remove(opf) # dont confuse code that searches for OPF files later on the oeb object will create its own OPF # Set the cover. if cover_path: cdata = None