diff --git a/src/calibre/ebooks/conversion/plugins/html_input.py b/src/calibre/ebooks/conversion/plugins/html_input.py index 5bc4f2577c..9119698b61 100644 --- a/src/calibre/ebooks/conversion/plugins/html_input.py +++ b/src/calibre/ebooks/conversion/plugins/html_input.py @@ -13,7 +13,7 @@ from urllib.parse import quote from calibre.constants import isbsd, islinux from calibre.customize.conversion import InputFormatPlugin, OptionRecommendation -from calibre.utils.filenames import ascii_filename +from calibre.utils.filenames import ascii_filename, get_long_path_name from calibre.utils.imghdr import what from calibre.utils.localization import __, get_lang from polyglot.builtins import as_unicode @@ -86,7 +86,7 @@ class HTMLInput(InputFormatPlugin): if hasattr(stream, 'name'): basedir = os.path.dirname(stream.name) fname = os.path.basename(stream.name) - self.root_dir_of_input = os.path.normcase(os.path.abspath(basedir) + os.sep) + self.root_dir_of_input = os.path.normcase(get_long_path_name(os.path.abspath(basedir)) + os.sep) if file_ext != 'opf': if opts.dont_package: @@ -262,9 +262,10 @@ class HTMLInput(InputFormatPlugin): if not link: return None, None link = os.path.abspath(os.path.realpath(link)) - if not os.path.normcase(link).startswith(self.root_dir_of_input): + q = os.path.normcase(get_long_path_name(link)) + if not q.startswith(self.root_dir_of_input): if not self.opts.allow_local_files_outside_root: - self.log.warn('Not adding {} as it is outside the document root: {}'.format(link, self.root_dir_of_input)) + self.log.warn('Not adding {} as it is outside the document root: {}'.format(q, self.root_dir_of_input)) return None, None return link, frag diff --git a/src/calibre/ebooks/oeb/polish/tests/base.py b/src/calibre/ebooks/oeb/polish/tests/base.py index 91be668ef9..dd78065d52 100644 --- a/src/calibre/ebooks/oeb/polish/tests/base.py +++ b/src/calibre/ebooks/oeb/polish/tests/base.py @@ -24,7 +24,14 @@ def get_cache(): return cache +once_per_run = set() + + def needs_recompile(obj, srcs): + is_ci = os.environ.get('CI', '').lower() == 'true' + if is_ci and obj not in once_per_run: + once_per_run.add(obj) + return True if isinstance(srcs, str): srcs = [srcs] try: @@ -39,7 +46,7 @@ def needs_recompile(obj, srcs): def build_book(src, dest, args=()): from calibre.ebooks.conversion.cli import main - main(['ebook-convert', src, dest] + list(args)) + main(['ebook-convert', src, dest, '-vv'] + list(args)) def add_resources(raw, rmap): @@ -55,22 +62,21 @@ def get_simple_book(fmt='epub'): ans = os.path.join(cache, 'simple.'+fmt) src = os.path.join(os.path.dirname(__file__), 'simple.html') if needs_recompile(ans, src): - with TemporaryDirectory('bpt') as tdir: - with CurrentDir(tdir): - with open(src, 'rb') as sf: - raw = sf.read().decode('utf-8') - raw = add_resources(raw, { - 'LMONOI': P('fonts/liberation/LiberationMono-Italic.ttf'), - 'LMONOR': P('fonts/liberation/LiberationMono-Regular.ttf'), - 'IMAGE1': I('marked.png'), - 'IMAGE2': I('textures/light_wood.png'), - }) - shutil.copy2(I('lt.png'), '.') - x = 'index.html' - with open(x, 'wb') as f: - f.write(raw.encode('utf-8')) - build_book(x, ans, args=[ - '--level1-toc=//h:h2', '--language=en', '--authors=Kovid Goyal', '--cover=lt.png', '--allow-local-files-outside-root']) + with TemporaryDirectory('bpt') as tdir, CurrentDir(tdir): + with open(src, 'rb') as sf: + raw = sf.read().decode('utf-8') + raw = add_resources(raw, { + 'LMONOI': P('fonts/liberation/LiberationMono-Italic.ttf'), + 'LMONOR': P('fonts/liberation/LiberationMono-Regular.ttf'), + 'IMAGE1': I('marked.png'), + 'IMAGE2': I('textures/light_wood.png'), + }) + shutil.copy2(I('lt.png'), '.') + x = 'index.html' + with open(x, 'wb') as f: + f.write(raw.encode('utf-8')) + build_book(x, ans, args=[ + '--level1-toc=//h:h2', '--language=en', '--authors=Kovid Goyal', '--cover=lt.png']) return ans @@ -85,7 +91,7 @@ def get_split_book(fmt='epub'): with open(x, 'wb') as f: f.write(raw.encode('utf-8')) build_book(x, ans, args=['--level1-toc=//h:h2', '--language=en', '--authors=Kovid Goyal', - '--cover=' + I('lt.png'), '--allow-local-files-outside-root']) + '--cover=' + I('lt.png')]) finally: os.remove(x) return ans diff --git a/src/calibre/utils/filenames.py b/src/calibre/utils/filenames.py index 90a6fb9cd8..897b0a47f3 100644 --- a/src/calibre/utils/filenames.py +++ b/src/calibre/utils/filenames.py @@ -620,10 +620,20 @@ if iswindows: return False # Values I have seen: FAT32, exFAT, NTFS return tn.upper().startswith('FAT') + + def get_long_path_name(path): + from calibre_extensions.winutil import get_long_path_name + if os.path.isabs(path) and not path.startswith(long_path_prefix): + path = long_path_prefix + path + return get_long_path_name(path) + else: def make_long_path_useable(path): return path + def get_long_path_name(path): + return path + def is_fat_filesystem(path): # TODO: Implement for Linux and macOS return False diff --git a/src/calibre/utils/run_tests.py b/src/calibre/utils/run_tests.py index 65c432a518..58421598e6 100644 --- a/src/calibre/utils/run_tests.py +++ b/src/calibre/utils/run_tests.py @@ -6,6 +6,9 @@ import unittest, functools, importlib, importlib.resources, os from calibre.utils.monotonic import monotonic +is_ci = os.environ.get('CI', '').lower() == 'true' + + def no_endl(f): @functools.wraps(f) def func(*args, **kwargs): @@ -329,6 +332,6 @@ def run_cli(suite, verbosity=4, buffer=True): r = unittest.TextTestRunner r.resultclass = unittest.TextTestResult if verbosity < 2 else TestResult init_env() - result = r(verbosity=verbosity, buffer=buffer).run(suite) + result = r(verbosity=verbosity, buffer=buffer and not is_ci).run(suite) if not result.wasSuccessful(): raise SystemExit(1)