int mc_db_util_connect(void **handle, uid_t uid);
int mc_db_util_disconnect(void *handle);
-int mc_db_util_check_size(uid_t uid);
+int mc_db_util_get_db_name(uid_t uid, char **db_name);
int mc_db_util_check_integrity(void *handle);
int mc_db_util_remove_db(uid_t uid);
int mc_db_util_create_tables(void *handle);
#include <sqlite3.h>
#include <tzplatform_config.h>
#include <gio/gio.h>
-#include <sys/stat.h>
#include "media_controller_private.h"
#include "media_controller_db_util.h"
return MEDIA_CONTROLLER_ERROR_NONE;
}
-int mc_db_util_check_size(uid_t uid)
+int mc_db_util_get_db_name(uid_t uid, char **db_name)
{
- int ret = MEDIA_CONTROLLER_ERROR_NONE;
- char * db_name = NULL;
- struct stat buf;
-
- db_name = __mc_get_db_name(uid);
+ *db_name = __mc_get_db_name(uid);
- if (db_name == NULL) {
+ if (*db_name == NULL) {
mc_error("error when get db path");
return MEDIA_CONTROLLER_ERROR_INVALID_OPERATION;
}
- if (stat(db_name, &buf) == 0) {
- if (buf.st_size == 0) {
- mc_stderror("The size of database failed");
- ret = MEDIA_CONTROLLER_ERROR_INVALID_OPERATION;
- }
- } else {
- mc_stderror("stat failed");
- ret = MEDIA_CONTROLLER_ERROR_INVALID_OPERATION;
- }
-
- MC_SAFE_FREE(db_name);
-
- return ret;
+ return MEDIA_CONTROLLER_ERROR_NONE;
}
int mc_db_util_check_integrity(void *handle)
db_name = __mc_get_db_name(uid);
- mc_warning("The db(%d) is abnormal. So it will be removed.", db_name);
+ mc_warning("The db is abnormal. So it will be removed.");
if (db_name == NULL) {
mc_error("error when get db path");
#include <string.h>
#include <systemd/sd-daemon.h>
#include <systemd/sd-login.h>
+#include <gio/gio.h>
+#include <sys/stat.h>
#include "media_controller_svc.h"
#include "media_controller_private.h"
{
int res = MEDIA_CONTROLLER_ERROR_NONE;
void *db_handle = NULL;
+ char *db_name = NULL;
+ struct stat buf;
- res = mc_db_util_check_size(uid);
- if (res != MEDIA_CONTROLLER_ERROR_NONE) {
- mc_error("Failed to check the size of DB");
- return res;
+ res = mc_db_util_get_db_name(uid, &db_name);
+ mc_retvm_if(res != MEDIA_CONTROLLER_ERROR_NONE, res, "Failed to get the db_name");
+
+ /* Check the database exists */
+ if (!g_file_test(db_name, G_FILE_TEST_EXISTS)) {
+ mc_error("[NO-ERROR] DB is not created yet, do not need to check DB");
+ MC_SAFE_FREE(db_name);
+ return MEDIA_CONTROLLER_ERROR_NONE;
+ }
+
+ /* Check the size of database */
+ if (stat(db_name, &buf) == 0) {
+ if (buf.st_size == 0) {
+ mc_warning("The size of database is error");
+ MC_SAFE_FREE(db_name);
+ return MEDIA_CONTROLLER_ERROR_INVALID_OPERATION;
+ }
+ } else {
+ mc_stderror("stat failed");
+ MC_SAFE_FREE(db_name);
+ return MEDIA_CONTROLLER_ERROR_INVALID_OPERATION;
}
+ MC_SAFE_FREE(db_name);
+
/* Connect media controller DB*/
res = mc_db_util_connect(&db_handle, uid);
if (res != MEDIA_CONTROLLER_ERROR_NONE) {
/* Check database */
ret = _mc_service_check_db(uid);
if (ret != MEDIA_CONTROLLER_ERROR_NONE) {
- mc_error("Failed to check database");
+ mc_error("DB is malformed. Start to remove");
ret = mc_db_util_remove_db(uid);
if (ret != MEDIA_CONTROLLER_ERROR_NONE) {
- mc_error("Failed to delete abnormal database file");
- _mc_service_deinit(mc_service_data);
- return FALSE;
+ mc_error("Failed to remove database");
}
}