static bool is_db_corrupted = false;
+static const char* _db_path = DB_PATH;
+
+int shortcut_set_db_path(const char *db_path)
+{
+ _db_path = db_path;
+ return 0;
+}
+
/* LCOV_EXCL_START */
static int __check_integrity_cb(void *pid, int argc, char **argv, char **notUsed)
{
SHORTCUT_INFO("DB is corrupted, start to recover corrupted db");
if (db)
sqlite3_close(db);
- unlink(DB_PATH);
+ unlink(_db_path);
- sql_ret = sqlite3_open_v2(DB_PATH, &db,
+ sql_ret = sqlite3_open_v2(_db_path, &db,
SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE,
NULL);
if (sql_ret != SQLITE_OK) {
SHORTCUT_ERR("Failed to open db[%d]", sql_ret);
- unlink(DB_PATH);
+ unlink(_db_path);
ret = SHORTCUT_ERROR_IO_ERROR;
goto out;
}
sqlite3 *db = NULL;
char *errmsg = NULL;
- sql_ret = sqlite3_open_v2(DB_PATH, &db,
+ sql_ret = sqlite3_open_v2(_db_path, &db,
SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, NULL);
if (sql_ret != SQLITE_OK) {
SHORTCUT_ERR("Failed to open db[%d]", sql_ret);
static sqlite3 *_open_db(void)
{
int ret;
- const char *dbfile = DB_PATH;
+ const char *dbfile = _db_path;
sqlite3 *db = NULL;
ret = db_util_open(dbfile, &db, 0);
if (!*icon) {
SHORTCUT_ERR("strdup: %d\n", errno);
ret = -ENOMEM;
- if (name && *name)
+ if (name && *name) {
free(*name);
+ *name = NULL;
+ }
goto out;
}
shortcut->extra_data = strdup((char *)extra_data);
*shortcut_list = g_list_append(*shortcut_list, shortcut);
- free(i18n_name);
- i18n_name = NULL;
+ if (i18n_name) {
+ free(i18n_name);
+ i18n_name = NULL;
+ }
- free(i18n_icon);
- i18n_icon = NULL;
+ if (i18n_icon) {
+ free(i18n_icon);
+ i18n_icon = NULL;
+ }
/* LCOV_EXCL_STOP */
}