mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Edit book: Fix replacing a file with another file with exactly the same filename causing an error. Fixes #1260822 [Cover replacement in edit fails](https://bugs.launchpad.net/calibre/+bug/1260822)
This commit is contained in:
parent
798094ff19
commit
87dd29e97f
@ -137,10 +137,10 @@ def replace_file(container, name, path, basename, force_mt=None):
|
|||||||
nname = b + ('_%d.%s' % (count, e))
|
nname = b + ('_%d.%s' % (count, e))
|
||||||
rename_files(container, {name:nname})
|
rename_files(container, {name:nname})
|
||||||
mt = force_mt or container.guess_type(nname)
|
mt = force_mt or container.guess_type(nname)
|
||||||
for itemid, q in container.manifest_id_map.iteritems():
|
for itemid, q in container.manifest_id_map.iteritems():
|
||||||
if q == nname:
|
if q == nname:
|
||||||
for item in container.opf_xpath('//opf:manifest/opf:item[@href and @id="%s"]' % itemid):
|
for item in container.opf_xpath('//opf:manifest/opf:item[@href and @id="%s"]' % itemid):
|
||||||
item.set('media-type', mt)
|
item.set('media-type', mt)
|
||||||
container.dirty(container.opf_name)
|
container.dirty(container.opf_name)
|
||||||
with container.open(nname, 'wb') as dest:
|
with container.open(nname, 'wb') as dest:
|
||||||
shutil.copyfileobj(src, dest)
|
shutil.copyfileobj(src, dest)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user