From 18bd7879ed2d27c9a10ab20dc9015836c5908807 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 24 Jan 2015 22:47:12 +0530 Subject: [PATCH] Save to Disk: Fix a bug where when multiple books are being saved to disk, if the save to disk template results in identical filenames, the filenames were not being properly disambiguated. --- src/calibre/gui2/save.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/calibre/gui2/save.py b/src/calibre/gui2/save.py index a0362d6fd2..ce1cae14c0 100644 --- a/src/calibre/gui2/save.py +++ b/src/calibre/gui2/save.py @@ -29,18 +29,17 @@ from calibre.library.save_to_disk import sanitize_args, get_path_components, fin BookId = namedtuple('BookId', 'title authors') def ensure_unique_components(data): # {{{ - cmap = {} + cmap = defaultdict(set) + bid_map = {} for book_id, (mi, components, fmts) in data.iteritems(): - c = tuple(components) - if c in cmap: - cmap[c].add(book_id) - else: - cmap[c] = {book_id} + cmap[tuple(components)].add(book_id) + bid_map[book_id] = components for book_ids in cmap.itervalues(): if len(book_ids) > 1: for i, book_id in enumerate(sorted(book_ids)[1:]): suffix = ' (%d)' % (i + 1) + components = bid_map[book_id] components[-1] = components[-1] + suffix # }}}