mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-05-08 19:54:18 +02:00
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.
This commit is contained in:
parent
4cfcad0024
commit
18bd7879ed
1 changed files with 5 additions and 6 deletions
|
|
@ -29,18 +29,17 @@
|
|||
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
|
||||
# }}}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue