From b63e0df73fc45dc35ebbdd1b64ef6b01951ac082 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 16 Jun 2013 08:31:05 +0530 Subject: [PATCH] DOCX Input: Fix image name generation DOCX Input: When converting docx files with large numbers of unnamed images, do not crash on windows. Fixes #1191354 [Word docx conversion](https://bugs.launchpad.net/calibre/+bug/1191354) --- src/calibre/ebooks/docx/images.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/calibre/ebooks/docx/images.py b/src/calibre/ebooks/docx/images.py index 76f43e7e0c..e24b550797 100644 --- a/src/calibre/ebooks/docx/images.py +++ b/src/calibre/ebooks/docx/images.py @@ -112,15 +112,16 @@ class Images(object): base += '.' + ext exists = frozenset(self.used.itervalues()) c = 1 - while base in exists: + name = base + while name in exists: n, e = base.rpartition('.')[0::2] - base = '%s-%d.%s' % (n, c, e) + name = '%s-%d.%s' % (n, c, e) c += 1 - self.used[rid] = base - with open(os.path.join(self.dest_dir, base), 'wb') as f: + self.used[rid] = name + with open(os.path.join(self.dest_dir, name), 'wb') as f: f.write(raw) - self.all_images.add('images/' + base) - return base + self.all_images.add('images/' + name) + return name def pic_to_img(self, pic, alt=None): name = None