From 09fd203e87ff0518bec207405612a4f3e64b4cfe Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 31 Mar 2017 09:16:22 +0530 Subject: [PATCH] EPUB metadata: Fix deleting ISBN from EPUB file could result in an EPUB file without a package identifier if the ISBN was used as the package identifier. Fixes #1677383 [Embed Metadata plugin tool creating errors](https://bugs.launchpad.net/calibre/+bug/1677383) --- src/calibre/ebooks/metadata/opf2.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/calibre/ebooks/metadata/opf2.py b/src/calibre/ebooks/metadata/opf2.py index 50e3b35091..348fa78107 100644 --- a/src/calibre/ebooks/metadata/opf2.py +++ b/src/calibre/ebooks/metadata/opf2.py @@ -948,10 +948,24 @@ class OPF(object): # {{{ return self.get_text(match) or None def fset(self, val): + uuid_id = None + for attr in self.root.attrib: + if attr.endswith('unique-identifier'): + uuid_id = self.root.attrib[attr] + break + matches = self.isbn_path(self.metadata) if not val: for x in matches: - x.getparent().remove(x) + xid = x.get('id', None) + is_package_identifier = uuid_id is not None and uuid_id == xid + if is_package_identifier: + self.set_text(x, str(uuid.uuid4())) + for attr in x.attrib: + if attr.endswith('scheme'): + x.attrib[attr] = 'uuid' + else: + x.getparent().remove(x) return if not matches: attrib = {'{%s}scheme'%self.NAMESPACES['opf']: 'ISBN'}