From e7a2bd2691a5361b06e10ccdc607ac00a87eb013 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 14 Sep 2014 10:37:54 +0530 Subject: [PATCH] Ensure there is never a double space after the title when creating file/folder names in the calibre library --- src/calibre/db/backend.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/calibre/db/backend.py b/src/calibre/db/backend.py index 0afc2bac72..5598c13380 100644 --- a/src/calibre/db/backend.py +++ b/src/calibre/db/backend.py @@ -1111,7 +1111,9 @@ class DB(object): book_id = ' (%d)' % book_id l = self.PATH_LIMIT - (len(book_id) // 2) - 2 author = ascii_filename(author)[:l].decode('ascii', 'replace') - title = ascii_filename(title)[:l].decode('ascii', 'replace') + title = ascii_filename(title.lstrip())[:l].decode('ascii', 'replace').rstrip() + if not title: + title = 'Unknown'[:l] try: while author[-1] in (' ', '.'): author = author[:-1] @@ -1135,7 +1137,9 @@ class DB(object): if l < 5: raise ValueError('Extension length too long: %d' % extlen) author = ascii_filename(author)[:l].decode('ascii', 'replace') - title = ascii_filename(title)[:l].decode('ascii', 'replace') + title = ascii_filename(title.lstrip())[:l].decode('ascii', 'replace').rstrip() + if not title: + title = 'Unknown'[:l] name = title + ' - ' + author while name.endswith('.'): name = name[:-1]