From 4751aa1286041f9e6a8a9b479fe7fa93e6c8921c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 27 Aug 2013 09:38:37 +0530 Subject: [PATCH] newdb: Fix temp duplicate catalog entries in book list Creating a catalog with an already existing catalog in the library would cause a temporary duplicate entry in the book list (the entry would go away on restart. Also fix the author sort for catalogs generated in the AZW3 format not being correct. --- src/calibre/db/adding.py | 5 ++++- src/calibre/db/legacy.py | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/calibre/db/adding.py b/src/calibre/db/adding.py index 0ca8c611d8..2377d4b02a 100644 --- a/src/calibre/db/adding.py +++ b/src/calibre/db/adding.py @@ -106,6 +106,7 @@ def add_catalog(cache, path, title): from calibre.utils.date import utcnow fmt = os.path.splitext(path)[1][1:].lower() + new_book_added = False with lopen(path, 'rb') as stream: with cache.write_lock: matches = cache._search('title:="%s" and tags:="%s"' % (title.replace('"', '\\"'), _('Catalog')), None) @@ -118,17 +119,19 @@ def add_catalog(cache, path, title): except: mi = Metadata(title, ['calibre']) mi.title, mi.authors = title, ['calibre'] + mi.author_sort = 'calibre' # The MOBI/AZW3 format sets author sort to date mi.tags = [_('Catalog')] mi.pubdate = mi.timestamp = utcnow() if fmt == 'mobi': mi.cover, mi.cover_data = None, (None, None) if db_id is None: db_id = cache._create_book_entry(mi, apply_import_tags=False) + new_book_added = True else: cache._set_metadata(db_id, mi) cache.add_format(db_id, fmt, stream) # Cant keep write lock since post-import hooks might run - return db_id + return db_id, new_book_added def add_news(cache, path, arg): from calibre.ebooks.metadata.meta import get_metadata diff --git a/src/calibre/db/legacy.py b/src/calibre/db/legacy.py index b794d2c14c..384c75d71b 100644 --- a/src/calibre/db/legacy.py +++ b/src/calibre/db/legacy.py @@ -252,8 +252,8 @@ class LibraryDatabase(object): return recursive_import(self, root, single_book_per_directory=single_book_per_directory, callback=callback, added_ids=added_ids) def add_catalog(self, path, title): - book_id = add_catalog(self.new_api, path, title) - if book_id is not None: + book_id, new_book_added = add_catalog(self.new_api, path, title) + if book_id is not None and new_book_added: self.data.books_added((book_id,)) return book_id