mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
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:
commit
0b6b854b3d
@ -310,7 +310,8 @@ class DB(object):
|
|||||||
# Initialize database {{{
|
# Initialize database {{{
|
||||||
|
|
||||||
def __init__(self, library_path, default_prefs=None, read_only=False,
|
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:
|
try:
|
||||||
if isbytestring(library_path):
|
if isbytestring(library_path):
|
||||||
library_path = library_path.decode(filesystem_encoding)
|
library_path = library_path.decode(filesystem_encoding)
|
||||||
@ -386,7 +387,8 @@ class DB(object):
|
|||||||
self.initialize_prefs(default_prefs, restore_all_prefs, progress_callback)
|
self.initialize_prefs(default_prefs, restore_all_prefs, progress_callback)
|
||||||
self.initialize_custom_columns()
|
self.initialize_custom_columns()
|
||||||
self.initialize_tables()
|
self.initialize_tables()
|
||||||
load_user_template_functions(self.library_id,
|
if load_user_formatter_functions:
|
||||||
|
load_user_template_functions(self.library_id,
|
||||||
self.prefs.get('user_template_functions', []))
|
self.prefs.get('user_template_functions', []))
|
||||||
|
|
||||||
def initialize_prefs(self, default_prefs, restore_all_prefs, progress_callback): # {{{
|
def initialize_prefs(self, default_prefs, restore_all_prefs, progress_callback): # {{{
|
||||||
|
@ -38,10 +38,12 @@ def cleanup_tags(tags):
|
|||||||
|
|
||||||
def create_backend(
|
def create_backend(
|
||||||
library_path, default_prefs=None, read_only=False,
|
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,
|
return DB(library_path, default_prefs=default_prefs,
|
||||||
read_only=read_only, restore_all_prefs=restore_all_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):
|
class LibraryDatabase(object):
|
||||||
|
|
||||||
@ -67,7 +69,8 @@ class LibraryDatabase(object):
|
|||||||
|
|
||||||
backend = self.backend = create_backend(library_path, default_prefs=default_prefs,
|
backend = self.backend = create_backend(library_path, default_prefs=default_prefs,
|
||||||
read_only=read_only, restore_all_prefs=restore_all_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 = self.new_api = Cache(backend)
|
||||||
cache.init()
|
cache.init()
|
||||||
self.data = View(cache)
|
self.data = View(cache)
|
||||||
|
@ -396,11 +396,12 @@ class CopyToLibraryAction(InterfaceAction):
|
|||||||
|
|
||||||
# Open the new db so we can check the custom columns. We use only the
|
# 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
|
# 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
|
global libraries_with_checked_columns
|
||||||
|
|
||||||
from calibre.db.legacy import create_backend
|
from calibre.db.legacy import create_backend
|
||||||
newdb = create_backend(loc)
|
newdb = create_backend(loc, load_user_formatter_functions=False)
|
||||||
|
|
||||||
continue_processing = True
|
continue_processing = True
|
||||||
with closing(newdb):
|
with closing(newdb):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user