From e7c1ae60a185bc55a5b0000c591a1f75e4a7dd13 Mon Sep 17 00:00:00 2001 From: Michal Rostecki Date: Wed, 15 Apr 2020 00:55:37 +0200 Subject: [PATCH] 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 --- backup/backup.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/backup/backup.py b/backup/backup.py index f47636b..555fa8a 100755 --- a/backup/backup.py +++ b/backup/backup.py @@ -235,14 +235,16 @@ def resolve_backend_class(backend_url): return backend_cl -def get_backend(destination, create=False): +def get_backend(destination, create=False, require_init=False): backend_cl = resolve_backend_class(destination) if backend_cl is None: raise ValueError("No backend implementation found for {destination}".format( destination=destination, )) 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.prev_version is not None) return backend @@ -331,9 +333,7 @@ def on_init(options: Mapping[str, str], plugin: Plugin, **kwargs): if not plugin.db_path.startswith('sqlite3'): abort("The backup plugin only works with the sqlite3 database.") - plugin.backend = get_backend(destination) - if not plugin.backend.initialize(): - abort("Could not initialize the backup {}, please use 'backup-cli' to initialize the backup first.".format(destination)) + plugin.backend = get_backend(destination, require_init=True) for c in plugin.early_writes: apply_write(plugin, c)