summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjiyong.min <jiyong.min@samsung.com>2018-12-18 10:54:39 +0900
committerjiyong.min <jiyong.min@samsung.com>2018-12-18 14:26:04 +0900
commite5baed8bc8de8e94ba7c39a581961a228c255394 (patch)
tree9747a595121b51704a397bc36fc3a2abc065da75
parent8feb88ba089010789171779bcc4d2e938180d200 (diff)
downloadmedia-controller-e5baed8bc8de8e94ba7c39a581961a228c255394.tar.gz
media-controller-e5baed8bc8de8e94ba7c39a581961a228c255394.tar.bz2
media-controller-e5baed8bc8de8e94ba7c39a581961a228c255394.zip
Change to check the database when the database existssubmit/tizen/20181217.011957accepted/tizen/unified/20181219.154848
Change-Id: Ifa274df8caa20a3afecded0bf5eb220143e0df47
-rwxr-xr-xsvc/include/media_controller_db_util.h2
-rwxr-xr-xsvc/media_controller_db_util.c27
-rwxr-xr-xsvc/media_controller_svc.c37
3 files changed, 35 insertions, 31 deletions
diff --git a/svc/include/media_controller_db_util.h b/svc/include/media_controller_db_util.h
index edc2e18..de03b57 100755
--- a/svc/include/media_controller_db_util.h
+++ b/svc/include/media_controller_db_util.h
@@ -21,7 +21,7 @@
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);
diff --git a/svc/media_controller_db_util.c b/svc/media_controller_db_util.c
index 363960b..5b97536 100755
--- a/svc/media_controller_db_util.c
+++ b/svc/media_controller_db_util.c
@@ -22,7 +22,6 @@
#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"
@@ -333,32 +332,16 @@ int mc_db_util_disconnect(void *handle)
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)
@@ -406,7 +389,7 @@ int mc_db_util_remove_db(uid_t uid)
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");
diff --git a/svc/media_controller_svc.c b/svc/media_controller_svc.c
index c8dba7b..36e4833 100755
--- a/svc/media_controller_svc.c
+++ b/svc/media_controller_svc.c
@@ -17,6 +17,8 @@
#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"
@@ -199,13 +201,34 @@ static int _mc_service_check_db(uid_t uid)
{
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) {
@@ -665,12 +688,10 @@ gboolean mc_svc_thread(void *data)
/* 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");
}
}