From f7c49d16091fadfafb405226c812ca52430bdf00 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 23 Nov 2010 12:30:27 -0700 Subject: [PATCH] Add check for has_cover cache consistency to check db integrity --- src/calibre/gui2/actions/choose_library.py | 4 ++-- src/calibre/library/database2.py | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/calibre/gui2/actions/choose_library.py b/src/calibre/gui2/actions/choose_library.py index 01babc8e67..eb5902be48 100644 --- a/src/calibre/gui2/actions/choose_library.py +++ b/src/calibre/gui2/actions/choose_library.py @@ -132,9 +132,9 @@ class CheckIntegrity(QProgressDialog): titles = [self.db.title(x, index_is_id=True) for x in bad] det_msg = '\n'.join(titles) warning_dialog(self, _('Some inconsistencies found'), - _('The following books had formats listed in the ' + _('The following books had formats or covers listed in the ' 'database that are not actually available. ' - 'The entries for the formats have been removed. ' + 'The entries for the formats/covers have been removed. ' 'You should check them manually. This can ' 'happen if you manipulate the files in the ' 'library folder directly.'), det_msg=det_msg, show=True) diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index 18161d2230..d1d11a70ba 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -2509,11 +2509,20 @@ books_series_link feeds if id not in bad: bad[id] = [] bad[id].append(fmt) + has_cover = self.data.get(id, self.FIELD_MAP['cover'], + row_is_id=True) + if has_cover and self.cover(id, index_is_id=True, as_path=True) is None: + if id not in bad: + bad[id] = [] + bad[id].append('COVER') callback(0.1+0.9*(1+i)/total, _('Checked id') + ' %d'%id) for id in bad: for fmt in bad[id]: - self.conn.execute('DELETE FROM data WHERE book=? AND format=?', (id, fmt.upper())) + if fmt != 'COVER': + self.conn.execute('DELETE FROM data WHERE book=? AND format=?', (id, fmt.upper())) + else: + self.conn.execute('UPDATE books SET has_cover=0 WHERE id=?', (id,)) self.conn.commit() self.refresh_ids(list(bad.keys()))