Fix #1487949 ["Cross-contamination" of modified user template functions when copying books between libraries](https://bugs.launchpad.net/calibre/+bug/1487949)

This commit is contained in:
Kovid Goyal 2015-08-24 14:42:34 +05:30
commit 0b6b854b3d
3 changed files with 13 additions and 7 deletions

View File

@ -310,7 +310,8 @@ class DB(object):
# Initialize database {{{
def __init__(self, library_path, default_prefs=None, read_only=False,
restore_all_prefs=False, progress_callback=lambda x, y:True):
restore_all_prefs=False, progress_callback=lambda x, y:True,
load_user_formatter_functions=True):
try:
if isbytestring(library_path):
library_path = library_path.decode(filesystem_encoding)
@ -386,6 +387,7 @@ class DB(object):
self.initialize_prefs(default_prefs, restore_all_prefs, progress_callback)
self.initialize_custom_columns()
self.initialize_tables()
if load_user_formatter_functions:
load_user_template_functions(self.library_id,
self.prefs.get('user_template_functions', []))

View File

@ -38,10 +38,12 @@ def cleanup_tags(tags):
def create_backend(
library_path, default_prefs=None, read_only=False,
progress_callback=lambda x, y:True, restore_all_prefs=False):
progress_callback=lambda x, y:True, restore_all_prefs=False,
load_user_formatter_functions=True):
return DB(library_path, default_prefs=default_prefs,
read_only=read_only, restore_all_prefs=restore_all_prefs,
progress_callback=progress_callback)
progress_callback=progress_callback,
load_user_formatter_functions=load_user_formatter_functions)
class LibraryDatabase(object):
@ -67,7 +69,8 @@ class LibraryDatabase(object):
backend = self.backend = create_backend(library_path, default_prefs=default_prefs,
read_only=read_only, restore_all_prefs=restore_all_prefs,
progress_callback=progress_callback)
progress_callback=progress_callback,
load_user_formatter_functions=not is_second_db)
cache = self.new_api = Cache(backend)
cache.init()
self.data = View(cache)

View File

@ -396,11 +396,12 @@ class CopyToLibraryAction(InterfaceAction):
# Open the new db so we can check the custom columns. We use only the
# backend since we only need the custom column definitions, not the
# rest of the data in the db.
# rest of the data in the db. We also do not want the user defined
# formatter functions because loading them can poison the template cache
global libraries_with_checked_columns
from calibre.db.legacy import create_backend
newdb = create_backend(loc)
newdb = create_backend(loc, load_user_formatter_functions=False)
continue_processing = True
with closing(newdb):