" pkgid TEXT,\n" \
" lang TEXT,\n" \
" name TEXT,\n" \
- " icon TEXT);"
+ " icon TEXT);\n" \
+ "CREATE TABLE IF NOT EXISTS version (\n" \
+ " version INTEGER);"
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)
{
if (strcmp(argv[0], "ok") != 0) {
- SHORTCUT_ERR("db integrity result : %s" , argv[0]);
+ SHORTCUT_ERR("db integrity result : %s", argv[0]);
is_db_corrupted = true;
return -1;
}
- SHORTCUT_INFO("db integrity result : %s" , argv[0]);
+ SHORTCUT_INFO("db integrity result : %s", argv[0]);
return 0;
}
+/* LCOV_EXCL_STOP */
-static int __recover_corrupted_db(sqlite3 *db)
+/* LCOV_EXCL_START */
+static int __recover_corrupted_db()
{
int ret = SHORTCUT_ERROR_NONE;
int sql_ret;
char *errmsg = NULL;
+ sqlite3 *db = NULL;
SHORTCUT_INFO("DB is corrupted, start to recover corrupted db");
- if (db)
- sqlite3_close(db);
- unlink(DB_PATH);
- sql_ret = sqlite3_open_v2(DB_PATH, &db,
- SQLITE_OPEN_CREATE |SQLITE_OPEN_READWRITE,
+ unlink(_db_path);
+ 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;
}
out:
if (errmsg)
sqlite3_free(errmsg);
+ if (db)
+ sqlite3_close_v2(db);
return ret;
}
+/* LCOV_EXCL_STOP */
-EAPI int shortcut_db_init()
+/* LCOV_EXCL_START */
+EAPI int shortcut_db_init(void)
{
int ret = SHORTCUT_ERROR_NONE;
int sql_ret;
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);
}
out:
- if (sql_ret == SQLITE_CORRUPT || sql_ret == SQLITE_NOTADB || is_db_corrupted)
- ret = __recover_corrupted_db(db);
if (errmsg)
sqlite3_free(errmsg);
if (db)
- sqlite3_close(db);
+ sqlite3_close_v2(db);
+ if (sql_ret == SQLITE_CORRUPT || sql_ret == SQLITE_NOTADB || is_db_corrupted)
+ ret = __recover_corrupted_db();
return ret;
}
+/* LCOV_EXCL_STOP */
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 */
}