kepubify: Handle long file internal paths on windows

This commit is contained in:
Kovid Goyal 2025-07-06 09:19:44 +05:30
parent c3d35d2733
commit 4bffaa147a
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 5 additions and 4 deletions

View File

@ -50,7 +50,7 @@ from calibre.ebooks.oeb.polish.parsing import decode_xml
from calibre.ebooks.oeb.polish.parsing import parse as parse_html_tweak
from calibre.ebooks.oeb.polish.utils import OEB_FONTS, CommentFinder, PositionFinder, adjust_mime_for_epub, guess_type, insert_self_closing, parse_css
from calibre.ptempfile import PersistentTemporaryDirectory, PersistentTemporaryFile, TemporaryDirectory
from calibre.utils.filenames import hardlink_file, nlinks_file, retry_on_fail
from calibre.utils.filenames import hardlink_file, make_long_path_useable, nlinks_file, retry_on_fail
from calibre.utils.ipc.simple_worker import WorkerError, fork_job
from calibre.utils.logging import default_log
from calibre.utils.xml_parse import safe_xml_fromstring
@ -1076,7 +1076,7 @@ class Container(ContainerBase): # {{{
this will commit the file if it is dirtied and remove it from the parse
cache. You must finish with this file before accessing the parsed
version of it again, or bad things will happen. '''
return open(self.get_file_path_for_processing(name, mode not in {'r', 'rb'}), mode)
return open(make_long_path_useable(self.get_file_path_for_processing(name, mode not in {'r', 'rb'})), mode)
def commit(self, outpath=None, keep_parsed=False):
'''

View File

@ -34,6 +34,7 @@ from calibre.ebooks.oeb.polish.tts import lang_for_elem
from calibre.ebooks.oeb.polish.utils import extract, insert_self_closing
from calibre.spell.break_iterator import sentence_positions
from calibre.srv.render_book import Profiler, calculate_number_of_workers
from calibre.utils.filenames import make_long_path_useable
from calibre.utils.localization import canonicalize_lang, get_lang
from calibre.utils.short_uuid import uuid4
@ -371,7 +372,7 @@ def kepubify_html_data(raw: str | bytes, kobo_js_href: str = KOBO_JS_NAME, opts:
def kepubify_html_path(path: str, kobo_js_href: str = KOBO_JS_NAME, metadata_lang: str = 'en', opts: Options = Options()):
with open(path, 'r+b') as f:
with open(make_long_path_useable(path), 'r+b') as f:
raw = f.read()
root = kepubify_html_data(raw, kobo_js_href, opts, metadata_lang)
raw = serialize_html(root)
@ -461,7 +462,7 @@ def first_spine_item_is_probably_title_page(container: Container) -> bool:
def process_stylesheet_path(path: str, opts: Options) -> None:
if opts.needs_stylesheet_processing:
with open(path, 'r+b') as f:
with open(make_long_path_useable(path), 'r+b') as f:
css = f.read().decode()
ncss = process_stylesheet(css, opts)
if ncss is not css: