Browser viewer: Fix inability to open books that contain zero-byte stylesheets/images

This commit is contained in:
Kovid Goyal 2018-07-21 11:04:00 +05:30
parent 079af7acf9
commit 86d58a2539
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 10 additions and 3 deletions

View File

@ -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 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):
if not name:
return False

View File

@ -176,11 +176,13 @@ class Container(ContainerBase):
log = log or default_log
book_fmt, opfpath, input_fmt = extract_book(path_to_ebook, tdir, log=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 = {
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 == '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())
toc = get_toc(self).to_dict(count())
spine = [name for name, is_linear in self.spine_names]
@ -319,7 +321,7 @@ class Container(ContainerBase):
url, frag = purl.path, purl.fragment
name = self.href_to_name(url, base)
if name:
if self.has_name(name):
if self.has_name_and_is_not_empty(name):
frag = urlunquote(frag)
url = resource_template.format(encode_url(name, frag))
else: