From 56807d7b3e269f1812326d7e2db3b2f39858ea92 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 27 Jan 2014 08:00:33 +0530 Subject: [PATCH] Edit Book: Add check for links that point to directories in the book instead of files. Fixes #1272769 [Check Book in Edit Book end with Unhandled exception](https://bugs.launchpad.net/calibre/+bug/1272769) --- src/calibre/ebooks/oeb/polish/check/links.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/calibre/ebooks/oeb/polish/check/links.py b/src/calibre/ebooks/oeb/polish/check/links.py index a8627b7685..a8e7954488 100644 --- a/src/calibre/ebooks/oeb/polish/check/links.py +++ b/src/calibre/ebooks/oeb/polish/check/links.py @@ -123,7 +123,10 @@ def check_links(container): tname = container.href_to_name(href, name) if tname is not None: if container.exists(tname): - links_map[name].add(tname) + if tname in container.mime_map: + links_map[name].add(tname) + else: + a(BadLink(_('The linked resource %s is a directory') % fl(href), name, lnum, col)) else: a(BadLink(_('The linked resource %s does not exist') % fl(href), name, lnum, col)) else: @@ -134,12 +137,12 @@ def check_links(container): a(LocalLink(_('The link %s points to a file outside the book') % fl(href), name, lnum, col)) spine_docs = {name for name, linear in container.spine_names} - spine_styles = {tname for name in spine_docs for tname in links_map[name] if container.mime_map[tname] in OEB_STYLES} + spine_styles = {tname for name in spine_docs for tname in links_map[name] if container.mime_map.get(tname, None) in OEB_STYLES} num = -1 while len(spine_styles) > num: # Handle import rules in stylesheets num = len(spine_styles) - spine_styles |= {tname for name in spine_styles for tname in links_map[name] if container.mime_map[tname] in OEB_STYLES} + spine_styles |= {tname for name in spine_styles for tname in links_map[name] if container.mime_map.get(tname, None) in OEB_STYLES} seen = set(OEB_DOCS) | set(OEB_STYLES) spine_resources = {tname for name in spine_docs | spine_styles for tname in links_map[name] if container.mime_map[tname] not in seen} unreferenced = set()