From 5952c3fce3f989d86a21251ac44b500cea3549ba Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 19 Aug 2011 08:14:06 -0600 Subject: [PATCH] Fix #825987 (tag browser is blank) --- src/calibre/db/cache.py | 13 +++++++++---- src/calibre/library/database2.py | 20 ++++++++++++++++---- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/calibre/db/cache.py b/src/calibre/db/cache.py index f5d2814bb0..ea3766ad87 100644 --- a/src/calibre/db/cache.py +++ b/src/calibre/db/cache.py @@ -122,12 +122,17 @@ class Cache(object): formats = self._field_for('formats', book_id) mi.format_metadata = {} if not formats: - formats = None + good_formats = None else: + good_formats = [] for f in formats: - mi.format_metadata[f] = self._format_metadata(book_id, f) - formats = ','.join(formats) - mi.formats = formats + try: + mi.format_metadata[f] = self._format_metadata(book_id, f) + except: + pass + else: + good_formats.append(f) + mi.formats = good_formats mi.has_cover = _('Yes') if self._field_for('cover', book_id, default_value=False) else '' mi.tags = list(self._field_for('tags', book_id, default_value=())) diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index 79a441298f..669094c697 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -925,12 +925,18 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): formats = row[fm['formats']] mi.format_metadata = {} if not formats: - formats = None + good_formats = None else: formats = formats.split(',') + good_formats = [] for f in formats: - mi.format_metadata[f] = self.format_metadata(id, f) - mi.formats = formats + try: + mi.format_metadata[f] = self.format_metadata(id, f) + except: + pass + else: + good_formats.append(f) + mi.formats = good_formats tags = row[fm['tags']] if tags: mi.tags = [i.strip() for i in tags.split(',')] @@ -1213,7 +1219,13 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): except: # If path contains strange characters this throws an exc candidates = [] if format and candidates and os.path.exists(candidates[0]): - shutil.copyfile(candidates[0], fmt_path) + try: + shutil.copyfile(candidates[0], fmt_path) + except: + # This can happen if candidates[0] or fmt_path is too long, + # which can happen if the user copied the library from a + # non windows machine to a windows machine. + return None return fmt_path def copy_format_to(self, index, fmt, dest, index_is_id=False):