mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Browser viewer: Fix inability to open books that contain zero-byte stylesheets/images
This commit is contained in:
parent
079af7acf9
commit
86d58a2539
@ -525,6 +525,11 @@ class Container(ContainerBase): # {{{
|
|||||||
''' Return True iff a file with the same canonical name as that specified exists. Unlike :meth:`exists` this method is always case-sensitive. '''
|
''' Return True iff a file with the same canonical name as that specified exists. Unlike :meth:`exists` this method is always case-sensitive. '''
|
||||||
return name and name in self.name_path_map
|
return name and name in self.name_path_map
|
||||||
|
|
||||||
|
def has_name_and_is_not_empty(self, name):
|
||||||
|
if not self.has_name(name):
|
||||||
|
return False
|
||||||
|
return os.path.getsize(self.name_path_map[name]) > 0
|
||||||
|
|
||||||
def has_name_case_insensitive(self, name):
|
def has_name_case_insensitive(self, name):
|
||||||
if not name:
|
if not name:
|
||||||
return False
|
return False
|
||||||
|
@ -176,11 +176,13 @@ class Container(ContainerBase):
|
|||||||
log = log or default_log
|
log = log or default_log
|
||||||
book_fmt, opfpath, input_fmt = extract_book(path_to_ebook, tdir, log=log)
|
book_fmt, opfpath, input_fmt = extract_book(path_to_ebook, tdir, log=log)
|
||||||
ContainerBase.__init__(self, tdir, opfpath, log)
|
ContainerBase.__init__(self, tdir, opfpath, log)
|
||||||
|
# We do not add zero byte sized files as the IndexedDB API in the
|
||||||
|
# browser has no good way to distinguish between zero byte files and
|
||||||
|
# load failures.
|
||||||
excluded_names = {
|
excluded_names = {
|
||||||
name for name, mt in self.mime_map.iteritems() if
|
name for name, mt in self.mime_map.iteritems() if
|
||||||
name == self.opf_name or mt == guess_type('a.ncx') or name.startswith('META-INF/') or
|
name == self.opf_name or mt == guess_type('a.ncx') or name.startswith('META-INF/') or
|
||||||
name == 'mimetype'
|
name == 'mimetype' or not self.has_name_and_is_not_empty(name)}
|
||||||
}
|
|
||||||
raster_cover_name, titlepage_name = self.create_cover_page(input_fmt.lower())
|
raster_cover_name, titlepage_name = self.create_cover_page(input_fmt.lower())
|
||||||
toc = get_toc(self).to_dict(count())
|
toc = get_toc(self).to_dict(count())
|
||||||
spine = [name for name, is_linear in self.spine_names]
|
spine = [name for name, is_linear in self.spine_names]
|
||||||
@ -319,7 +321,7 @@ class Container(ContainerBase):
|
|||||||
url, frag = purl.path, purl.fragment
|
url, frag = purl.path, purl.fragment
|
||||||
name = self.href_to_name(url, base)
|
name = self.href_to_name(url, base)
|
||||||
if name:
|
if name:
|
||||||
if self.has_name(name):
|
if self.has_name_and_is_not_empty(name):
|
||||||
frag = urlunquote(frag)
|
frag = urlunquote(frag)
|
||||||
url = resource_template.format(encode_url(name, frag))
|
url = resource_template.format(encode_url(name, frag))
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user