mirror of
https://github.com/aljazceru/plugins.git
synced 2025-12-20 14:44:20 +01:00
backup: Remove duplicate call of initialize()
Before this change, backup backend was initialized twice - in on_init() and get_backend() functions. This change leaves only one call in get_backend() and adds a kwarg determining whether init failure should be fatal. Signed-off-by: Michal Rostecki <mrostecki@mailfence.com>
This commit is contained in:
committed by
Christian Decker
parent
ef31a4ac85
commit
e7c1ae60a1
@@ -235,14 +235,16 @@ def resolve_backend_class(backend_url):
|
|||||||
return backend_cl
|
return backend_cl
|
||||||
|
|
||||||
|
|
||||||
def get_backend(destination, create=False):
|
def get_backend(destination, create=False, require_init=False):
|
||||||
backend_cl = resolve_backend_class(destination)
|
backend_cl = resolve_backend_class(destination)
|
||||||
if backend_cl is None:
|
if backend_cl is None:
|
||||||
raise ValueError("No backend implementation found for {destination}".format(
|
raise ValueError("No backend implementation found for {destination}".format(
|
||||||
destination=destination,
|
destination=destination,
|
||||||
))
|
))
|
||||||
backend = backend_cl(destination, create=create)
|
backend = backend_cl(destination, create=create)
|
||||||
backend.initialize()
|
initialized = backend.initialize()
|
||||||
|
if require_init and not initialized:
|
||||||
|
abort("Could not initialize the backup {}, please use 'backup-cli' to initialize the backup first.".format(destination))
|
||||||
assert(backend.version is not None)
|
assert(backend.version is not None)
|
||||||
assert(backend.prev_version is not None)
|
assert(backend.prev_version is not None)
|
||||||
return backend
|
return backend
|
||||||
@@ -331,9 +333,7 @@ def on_init(options: Mapping[str, str], plugin: Plugin, **kwargs):
|
|||||||
if not plugin.db_path.startswith('sqlite3'):
|
if not plugin.db_path.startswith('sqlite3'):
|
||||||
abort("The backup plugin only works with the sqlite3 database.")
|
abort("The backup plugin only works with the sqlite3 database.")
|
||||||
|
|
||||||
plugin.backend = get_backend(destination)
|
plugin.backend = get_backend(destination, require_init=True)
|
||||||
if not plugin.backend.initialize():
|
|
||||||
abort("Could not initialize the backup {}, please use 'backup-cli' to initialize the backup first.".format(destination))
|
|
||||||
|
|
||||||
for c in plugin.early_writes:
|
for c in plugin.early_writes:
|
||||||
apply_write(plugin, c)
|
apply_write(plugin, c)
|
||||||
|
|||||||
Reference in New Issue
Block a user