aboutsummaryrefslogtreecommitdiff
path: root/src/backenddb/merchantdb_plugin.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-09-14 09:01:00 +0200
committerChristian Grothoff <christian@grothoff.org>2020-09-14 09:01:00 +0200
commit5466b9471cc85ff5ad9719ed61aaa474ae5b4c23 (patch)
tree5253b9d525f9a4f9025221eb1847a28ac6833a4a /src/backenddb/merchantdb_plugin.c
parentb9e87dd137f74864809b405ddf6a4ff719a5fedb (diff)
fix
Diffstat (limited to 'src/backenddb/merchantdb_plugin.c')
-rw-r--r--src/backenddb/merchantdb_plugin.c36
1 files changed, 29 insertions, 7 deletions
diff --git a/src/backenddb/merchantdb_plugin.c b/src/backenddb/merchantdb_plugin.c
index a8e046e5..d548ab0a 100644
--- a/src/backenddb/merchantdb_plugin.c
+++ b/src/backenddb/merchantdb_plugin.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2015, 2016 GNUnet e.V. and INRIA
+ Copyright (C) 2015, 2016, 2020 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Lesser General Public License as published by the Free Software
@@ -22,6 +22,7 @@
#include "platform.h"
#include <taler/taler_util.h>
#include "taler_merchantdb_plugin.h"
+#include "taler_merchantdb_lib.h"
#include <ltdl.h>
@@ -29,10 +30,12 @@
* Initialize the plugin.
*
* @param[in,out] cfg configuration to use
+ * @param reset_db should the DB be reset on load?
* @return #GNUNET_OK on success
*/
struct TALER_MERCHANTDB_Plugin *
-TALER_MERCHANTDB_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg)
+TALER_MERCHANTDB_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ bool reset_db)
{
char *plugin_name;
char *lib_name;
@@ -55,10 +58,29 @@ TALER_MERCHANTDB_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg)
GNUNET_free (plugin_name);
plugin = GNUNET_PLUGIN_load (lib_name,
(void *) cfg);
- if (NULL != plugin)
- plugin->library_name = lib_name;
- else
+ if (NULL == plugin)
+ {
GNUNET_free (lib_name);
+ return NULL;
+ }
+ plugin->library_name = lib_name;
+ if (reset_db)
+ {
+ if (GNUNET_OK !=
+ plugin->connect (plugin->cls,
+ true))
+ {
+ TALER_MERCHANTDB_plugin_unload (plugin);
+ return NULL;
+ }
+ (void) plugin->drop_tables (plugin->cls);
+ }
+ if (GNUNET_OK !=plugin->connect (plugin->cls,
+ false))
+ {
+ TALER_MERCHANTDB_plugin_unload (plugin);
+ return NULL;
+ }
return plugin;
}
@@ -92,7 +114,7 @@ static char *old_dlsearchpath;
* Setup libtool paths.
*/
void __attribute__ ((constructor))
-plugin_init ()
+plugin_init (void)
{
int err;
const char *opath;
@@ -133,7 +155,7 @@ plugin_init ()
* Shutdown libtool.
*/
void __attribute__ ((destructor))
-plugin_fini ()
+plugin_fini (void)
{
lt_dlsetsearchpath (old_dlsearchpath);
if (NULL != old_dlsearchpath)