Fix non pruned databases being closed in library_moved()

This commit is contained in:
Kovid Goyal 2017-04-10 22:53:26 +05:30
parent c8737737ef
commit 7acc25fcbc
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 13 additions and 7 deletions

View File

@ -685,9 +685,7 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
self.rebuild_vl_tabs()
for action in self.iactions.values():
action.library_changed(db)
self.library_broker.gui_library_changed(db)
if olddb is not None:
olddb.close(), olddb.break_cycles()
self.library_broker.gui_library_changed(db, olddb)
if self.device_connected:
self.set_books_in_library(self.booklists(), reset=True)
self.refresh_ondevice()

View File

@ -11,10 +11,17 @@ from threading import Lock
from calibre import filesystem_encoding
from calibre.db.cache import Cache
from calibre.db.legacy import LibraryDatabase, create_backend, set_global_state
from calibre.utils.filenames import samefile
from calibre.utils.filenames import samefile as _samefile
from calibre.utils.monotonic import monotonic
def samefile(a, b):
a, b = canonicalize_path(a), canonicalize_path(b)
if a == b:
return True
return _samefile(a, b)
def init_library(library_path, is_default_library):
db = Cache(
create_backend(
@ -156,7 +163,7 @@ class GuiLibraryBroker(LibraryBroker):
set_global_state(db)
return db
def gui_library_changed(self, db, prune=True):
def gui_library_changed(self, db, olddb=None):
# Must be called with lock held
newloc = canonicalize_path(db.backend.library_path)
for library_id, path in self.lmap.iteritems():
@ -169,8 +176,9 @@ class GuiLibraryBroker(LibraryBroker):
self.lmap[library_id] = newloc
self.loaded_dbs[library_id] = db
db.new_api.server_library_id = library_id
if prune:
self._prune_loaded_dbs()
if olddb is not None and samefile(olddb.backend.library_path, db.backend.library_path):
olddb.close(), olddb.break_cycles()
self._prune_loaded_dbs()
def _prune_loaded_dbs(self):
now = monotonic()