summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMyungki Lee <mk5004.lee@samsung.com>2017-10-31 02:55:41 (GMT)
committerMyungki Lee <mk5004.lee@samsung.com>2017-10-31 02:55:41 (GMT)
commitdd9aa717faa5f17100c2a1e1e475d73bc58e9b27 (patch)
tree0df694f1ff4169466cbd671b1296121dd5033e49
parent958265b67903d308457457bc3d7a92728fdc375b (diff)
downloadbadge-dd9aa717faa5f17100c2a1e1e475d73bc58e9b27.zip
badge-dd9aa717faa5f17100c2a1e1e475d73bc58e9b27.tar.gz
badge-dd9aa717faa5f17100c2a1e1e475d73bc58e9b27.tar.bz2
Add DB validation check when db initrefs/changes/00/158300/1
- Added integrity check related logic to db init process to check if db integrity is broken due to file system error and initialize db. Change-Id: I61168c628dc55384d25949d196b320111ece1176 Signed-off-by: Myungki Lee <mk5004.lee@samsung.com>
-rwxr-xr-xsrc/badge_db.c51
1 files changed, 49 insertions, 2 deletions
diff --git a/src/badge_db.c b/src/badge_db.c
index 9830c43..693903e 100755
--- a/src/badge_db.c
+++ b/src/badge_db.c
@@ -64,15 +64,62 @@ int badge_db_init()
SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, NULL);
if (sql_ret != SQLITE_OK) {
ERR("Failed to open badge db[%d]", sql_ret);
- return BADGE_ERROR_FROM_DB;
+
+ if (sqlite3_errcode(db) == SQLITE_CORRUPT) {
+ if (db)
+ sqlite3_close(db);
+ unlink(BADGE_DB_PATH);
+
+ sql_ret = sqlite3_open_v2(BADGE_DB_PATH, &db,
+ SQLITE_OPEN_CREATE |SQLITE_OPEN_READWRITE,
+ NULL);
+ if (sql_ret != SQLITE_OK) {
+ ERR("Failed to open badge db[%d]", sql_ret);
+ unlink(BADGE_DB_PATH);
+ ret = BADGE_ERROR_FROM_DB;
+ goto out;
+ }
+ } else {
+ ret = BADGE_ERROR_FROM_DB;
+ goto out;
+ }
}
sql_ret = sqlite3_exec(db, CREATE_BADGE_TABLE, NULL, NULL, &errmsg);
if (sql_ret != SQLITE_OK) {
ERR("Failed to exec query[%d][%s]", sql_ret, errmsg);
- ret = BADGE_ERROR_FROM_DB;
+
+ if (sql_ret == SQLITE_CORRUPT || sql_ret == SQLITE_NOTADB) {
+ sqlite3_close(db);
+ unlink(BADGE_DB_PATH);
+
+ sql_ret = sqlite3_open_v2(BADGE_DB_PATH, &db,
+ SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE,
+ NULL);
+ if (sql_ret != SQLITE_OK) {
+ ERR("Failed to open db[%d]", sql_ret);
+ unlink(BADGE_DB_PATH);
+ ret = BADGE_ERROR_FROM_DB;
+ goto out;
+ }
+
+ sqlite3_free(errmsg);
+ sql_ret = sqlite3_exec(db, CREATE_BADGE_TABLE, NULL,
+ NULL, &errmsg);
+ if (sql_ret != SQLITE_OK) {
+ ERR("Failed to exec sqlite, again[%d][%s]",
+ sql_ret, errmsg);
+ unlink(BADGE_DB_PATH);
+ ret = BADGE_ERROR_FROM_DB;
+ goto out;
+ }
+ } else {
+ ret = BADGE_ERROR_FROM_DB;
+ goto out;
+ }
}
+out:
if (errmsg)
sqlite3_free(errmsg);