From 56d32f6f9c4cb89e2f7e72d1995fbe4a1f54c455 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 4 Aug 2017 14:41:12 +0530 Subject: [PATCH] Fix custom columns copied to a library via the Copy to library action not showing up until a calibre restart if the destination library was accessed via the Content Server recently --- src/calibre/gui2/actions/copy_to_library.py | 11 ++++++++++- src/calibre/srv/library_broker.py | 13 +++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/actions/copy_to_library.py b/src/calibre/gui2/actions/copy_to_library.py index 25b673033e..796989e517 100644 --- a/src/calibre/gui2/actions/copy_to_library.py +++ b/src/calibre/gui2/actions/copy_to_library.py @@ -31,7 +31,8 @@ from calibre.utils.icu import sort_key, numeric_sort_key def ask_about_cc_mismatch(gui, db, newdb, missing_cols, incompatible_cols): # {{{ source_metadata = db.field_metadata.custom_field_metadata(include_composites=True) - ndbname = os.path.basename(newdb.library_path) + dest_library_path = newdb.library_path + ndbname = os.path.basename(dest_library_path) d = QDialog(gui) d.setWindowTitle(_('Different custom columns')) @@ -83,6 +84,7 @@ def ask_about_cc_mismatch(gui, db, newdb, missing_cols, incompatible_cols): # { d.bb.rejected.connect(d.reject) d.resize(d.sizeHint()) if d.exec_() == d.Accepted: + changes_made = False for k, cb in missing_widgets: if cb.isChecked(): col_meta = source_metadata[k] @@ -90,6 +92,13 @@ def ask_about_cc_mismatch(gui, db, newdb, missing_cols, incompatible_cols): # { col_meta['label'], col_meta['name'], col_meta['datatype'], len(col_meta['is_multiple']) > 0, col_meta['is_editable'], col_meta['display']) + changes_made = True + if changes_made: + # Unload the db so that the changes are available + # when it is next accessed + from calibre.gui2.ui import get_gui + library_broker = get_gui().library_broker + library_broker.unload_library(dest_library_path) return True return False # }}} diff --git a/src/calibre/srv/library_broker.py b/src/calibre/srv/library_broker.py index def734a068..24f5e5938b 100644 --- a/src/calibre/srv/library_broker.py +++ b/src/calibre/srv/library_broker.py @@ -253,6 +253,19 @@ class GuiLibraryBroker(LibraryBroker): with self: self._prune_loaded_dbs() + def unload_library(self, library_path): + with self: + path = canonicalize_path(library_path) + for library_id, q in self.lmap.iteritems(): + if samefile(path, q): + break + else: + return + db = self.loaded_dbs.pop(library_id, None) + if db is not None: + db.close() + db.break_cycles() + def remove_library(self, path): with self: path = canonicalize_path(path)