diff --git a/src/calibre/ebooks/oeb/polish/container.py b/src/calibre/ebooks/oeb/polish/container.py index b1a873782c..21c7b445db 100644 --- a/src/calibre/ebooks/oeb/polish/container.py +++ b/src/calibre/ebooks/oeb/polish/container.py @@ -232,6 +232,12 @@ class Container(object): # {{{ self.dirty(self.opf_name) return item_id + def manifest_has_name(self, name): + ''' Return True if the manifest has an entry corresponding to name ''' + href = self.name_to_href(name, self.opf_name) + all_hrefs = {x.get('href') for x in self.opf_xpath('//opf:manifest/opf:item[@href]')} + return href in all_hrefs + def add_file(self, name, data, media_type=None, spine_index=None): ''' Add a file to this container. Entries for the file are automatically created in the OPF manifest and spine diff --git a/src/calibre/gui2/tweak_book/boss.py b/src/calibre/gui2/tweak_book/boss.py index 8e029b071e..fb50e79854 100644 --- a/src/calibre/gui2/tweak_book/boss.py +++ b/src/calibre/gui2/tweak_book/boss.py @@ -432,7 +432,7 @@ class Boss(QObject): c = current_container() for path, name in files.iteritems(): i = 0 - while c.exists(name): + while c.exists(name) or c.manifest_has_name(name): i += 1 name, ext = name.rpartition('.')[0::2] name = '%s_%d.%s' % (name, i, ext)