diff --git a/src/calibre/ebooks/metadata/opf2.py b/src/calibre/ebooks/metadata/opf2.py index c147c2b748..4571ac1d6f 100644 --- a/src/calibre/ebooks/metadata/opf2.py +++ b/src/calibre/ebooks/metadata/opf2.py @@ -452,9 +452,12 @@ class OPF(object): def __init__(self, stream, basedir=os.getcwdu(), unquote_urls=True): if not hasattr(stream, 'read'): stream = open(stream, 'rb') + raw = stream.read() + if not raw: + raise ValueError('Empty file: '+getattr(stream, 'name', 'stream')) self.basedir = self.base_dir = basedir self.path_to_html_toc = self.html_toc_fragment = None - raw, self.encoding = xml_to_unicode(stream.read(), strip_encoding_pats=True, resolve_entities=True) + raw, self.encoding = xml_to_unicode(raw, strip_encoding_pats=True, resolve_entities=True) raw = raw[raw.find('<'):] self.root = etree.fromstring(raw, self.PARSER) self.metadata = self.metadata_path(self.root) diff --git a/src/calibre/gui2/add.py b/src/calibre/gui2/add.py index ec253e5ae0..b5572e34d6 100644 --- a/src/calibre/gui2/add.py +++ b/src/calibre/gui2/add.py @@ -107,8 +107,6 @@ class Adder(QObject): self.callback(self.paths, self.names, self.infos) self.callback_called = True - - def update(self): if not self.ids: self.timer.stop() diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index a2d3d70edd..f7780aa2a6 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -631,6 +631,8 @@ class LibraryDatabase2(LibraryDatabase): author = sanitize_file_name(authors.split(',')[0][:self.PATH_LIMIT]).decode(filesystem_encoding, 'replace') title = sanitize_file_name(self.title(id, index_is_id=True)[:self.PATH_LIMIT]).decode(filesystem_encoding, 'replace') name = title + ' - ' + author + while name.endswith('.'): + name = name[:-1] return name def rmtree(self, path):