Edit Book: When importing files and the book has an orphaned entry in the manifest for that file, but the file itself is not present, rename the file instead of erroring out. Fixes #1407860 [cannot replace missing PDF](https://bugs.launchpad.net/calibre/+bug/1407860)

This commit is contained in:
Kovid Goyal 2015-01-09 16:20:27 +05:30
parent 88ee7c4855
commit db3f5cb134
2 changed files with 7 additions and 1 deletions

View File

@ -232,6 +232,12 @@ class Container(object): # {{{
self.dirty(self.opf_name) self.dirty(self.opf_name)
return item_id 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): def add_file(self, name, data, media_type=None, spine_index=None):
''' Add a file to this container. Entries for the file are ''' Add a file to this container. Entries for the file are
automatically created in the OPF manifest and spine automatically created in the OPF manifest and spine

View File

@ -432,7 +432,7 @@ class Boss(QObject):
c = current_container() c = current_container()
for path, name in files.iteritems(): for path, name in files.iteritems():
i = 0 i = 0
while c.exists(name): while c.exists(name) or c.manifest_has_name(name):
i += 1 i += 1
name, ext = name.rpartition('.')[0::2] name, ext = name.rpartition('.')[0::2]
name = '%s_%d.%s' % (name, i, ext) name = '%s_%d.%s' % (name, i, ext)