media-server and scanner code cleanup 76/145676/9 accepted/tizen/unified/20170828.164040 submit/tizen/20170825.093836
authorMinje Ahn <minje.ahn@samsung.com>
Wed, 23 Aug 2017 08:21:02 +0000 (17:21 +0900)
committerhj kim <backto.kim@samsung.com>
Fri, 25 Aug 2017 01:27:59 +0000 (01:27 +0000)
1. Change opendir to g_dir_open(glib)
2. Block media db reset

Change-Id: If56b449dbaed39bc6d63c9c0d9561eb75a7465de
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
packaging/media-server.spec
src/common/include/media-common-utils.h
src/common/media-common-utils.c
src/scanner-v2/media-scanner-scan-v2.c
src/scanner/media-scanner-scan.c
src/scanner/media-scanner.c
src/server/media-server-main.c
src/server/media-server-scanner.c
src/server/media-server-socket.c

index ce6864e..0eb6216 100755 (executable)
@@ -86,7 +86,7 @@ cp po/* .
 %restore_fcommon
 %endif
 %if 0%{?product_tv}
-export CFLAGS="$CFLAGS -D_USE_SENIOR_MODE -D_USE_RECORDED_CONTENT -D_USE_SUSPEND_MODE -D_SET_VIP_PROCESS"
+export CFLAGS="$CFLAGS -D_USE_SENIOR_MODE -D_USE_RECORDED_CONTENT -D_USE_SUSPEND_MODE -D_SET_VIP_PROCESS -D_USE_TVPD_MODE"
 %else
 export CFLAGS="$CFLAGS -D_USE_MULTI_USER -D_USE_META_UPDATE -D_USE_DEVICED_DBUS"
 %endif
index bd93fe3..eb0950a 100755 (executable)
@@ -48,7 +48,6 @@ bool ms_storage_mount_status(const char* start_path);
 int ms_set_db_status(ms_db_status_type_t status, ms_storage_type_t storage_type);
 int ms_set_power_mode(ms_db_status_type_t status);
 void ms_trim_dir_path(char *dir_path);
-bool ms_check_folder_path(const char *folder_path);
 int ms_check_size_mediadb(uid_t uid, double *db_size);
 #ifdef _SET_VIP_PROCESS
 int ms_set_vip_process(void);
index 6a84597..88602d7 100755 (executable)
@@ -590,20 +590,6 @@ void ms_trim_dir_path(char *dir_path)
                dir_path[len -1] = '\0';
 }
 
-bool ms_check_folder_path(const char *folder_path)
-{
-       DIR *dp = NULL;
-
-       dp = opendir(folder_path);
-       if (dp == NULL) {
-               MS_DBG_ERR("Deleted folder path");
-               return false;
-       }
-       closedir(dp);
-
-       return true;
-}
-
 int ms_check_size_mediadb(uid_t uid, double *db_size)
 {
        int ret = MS_MEDIA_ERR_NONE;
index c06069b..fe5faf8 100755 (executable)
@@ -305,7 +305,7 @@ static int __msc_dir_scan_for_folder(void **handle, const char *storage_id, cons
                MS_DBG_ERR("set_folder_validity failed [%d] ", scan_type);
        }
 
-       if (ms_check_folder_path(new_start_path) == TRUE) {
+       if (g_file_test(new_start_path, G_FILE_TEST_IS_DIR)) {
                if (ms_insert_folder(handle, storage_id, new_start_path, uid) != MS_MEDIA_ERR_NONE) {
                        MS_DBG_ERR("insert folder failed");
                }
@@ -1156,7 +1156,7 @@ gboolean msc_directory_scan_thread(void *data)
 
                ms_trim_dir_path(scan_data->msg);
 
-               if (ms_check_folder_path(scan_data->msg)) {
+               if (g_file_test(scan_data->msg, G_FILE_TEST_IS_DIR)) {
                        is_recursive = (scan_type == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) ? false : true;
 
                        if (ms_check_folder_exist(handle, storage_id, scan_data->msg) == MS_MEDIA_ERR_NONE) {
index 7a73442..29c5693 100755 (executable)
 #include "media-scanner-socket.h"
 #include "media-scanner-scan.h"
 
-typedef struct msc_scan_data {
-       char *name;
-       struct msc_scan_data *next;
-} msc_scan_data;
-
 bool power_off;
 GAsyncQueue * storage_queue;
 GAsyncQueue *scan_queue;
@@ -52,8 +47,6 @@ GMutex blocked_mutex;
 char *g_cancel_path;
 char *g_blocked_path;
 bool g_directory_scan_processing;
-GArray *blocked_stg_list;
-
 int stg_scan_status;
 
 static int __msc_check_stop_status(ms_storage_type_t storage_type);
@@ -66,45 +59,11 @@ static int __msc_pop_register_request(GArray *register_array, ms_comm_msg_s **re
 static int __msc_clear_file_list(GArray *path_array);
 static void __msc_insert_register_request(GArray *register_array, ms_comm_msg_s *insert_data);
 static int __msc_set_storage_scan_status(ms_storage_scan_status_e status);
-//static int __msc_get_storage_scan_status(ms_storage_scan_status_e *status, uid_t uid);
-
-#if 0
-GCond data_cond;
-GMutex data_mutex;
-gpointer current_data = NULL;
-
-static int __msc_resume_scan()
-{
-       g_mutex_lock(&data_mutex);
-
-//     current_data = GINT_TO_POINTER(g_directory_scan_processing);
-       g_cond_signal(&data_cond);
-
-       g_mutex_unlock(&data_mutex);
-
-       return MS_MEDIA_ERR_NONE;
-}
-static int __msc_pause_scan()
-{
-       g_mutex_lock(&data_mutex);
-
-//     while (current_data)
-       while (g_directory_scan_processing)
-               g_cond_wait(&data_cond, &data_mutex);
-
-//     current_data = GPOINTER_TO_INT(g_directory_scan_processing);
-
-       g_mutex_unlock(&data_mutex);
-
-       return MS_MEDIA_ERR_NONE;
-}
-#endif
 
 static int __msc_check_stop_status(ms_storage_type_t storage_type)
 {
        int ret = MS_MEDIA_ERR_NONE;
 
-       /*check poweroff status*/
        if (power_off) {
                MS_DBG_ERR("Power off");
                ret = MS_MEDIA_ERR_SCANNER_FORCE_STOP;
@@ -113,39 +72,18 @@ static int __msc_check_stop_status(ms_storage_type_t storage_type)
        return ret;
 }
 
-static bool __msc_check_mount_storage(const char* start_path)
+static int __msc_read_dir(void **handle, const char *start_path, const char *storage_id, ms_storage_type_t storage_type, int scan_type, uid_t uid)
 {
-       bool ret = FALSE;
-       DIR *dp = NULL;
-
-       dp = opendir(start_path);
-
-       if (dp != NULL) {
-               ret = TRUE;
-               closedir(dp);
-               MS_DBG_WARN("STORAGE IS MOUNTED[%s]", start_path);
-       }
-
-       return ret;
-}
-
-static int __msc_read_dir(void **handle, GArray *dir_array, const char *start_path, const char *storage_id, ms_storage_type_t storage_type, int scan_type, uid_t uid)
-{
-       DIR *dp = NULL;
-       struct dirent entry;
-       struct dirent *result = NULL;
        int ret = MS_MEDIA_ERR_NONE;
+       GDir *dir = NULL;
+       GError *error = NULL;
+       const char *name;
+       GArray *dir_array = NULL;
        char *new_path = NULL;
        char *current_path = NULL;
        char path[MS_FILE_PATH_LEN_MAX] = { 0 };
        int (*scan_function)(void **, const char*, const char*, uid_t) = NULL;
 
-       if (dir_array != NULL) {
-               MS_DBG_ERR("dir_array is NULL");
-               return MS_MEDIA_ERR_INVALID_PARAMETER;
-       }
-
-       /* make new array for storing directory */
        dir_array = g_array_new(FALSE, FALSE, sizeof(char*));
        if (dir_array == NULL) {
                MS_DBG_ERR("g_array_new failed");
@@ -156,14 +94,12 @@ static int __msc_read_dir(void **handle, GArray *dir_array, const char *start_pa
 
        scan_function = (scan_type == MS_MSG_STORAGE_ALL) ? ms_insert_item_batch : ms_validate_item;
 
-       /*start db update. the number of element in the array , db update is complete.*/
        while (dir_array->len != 0) {
-               /*check poweroff status*/
                ret = __msc_check_stop_status(storage_type);
                if (ret != MS_MEDIA_ERR_NONE) {
                        goto STOP_DIR_SCAN;
                }
-               /* get the current path from directory array */
+
                current_path = g_array_index(dir_array , char*, 0);
                g_array_remove_index(dir_array, 0);
                MS_DBG_SLOG("%d", dir_array->len);
@@ -176,42 +112,33 @@ static int __msc_read_dir(void **handle, GArray *dir_array, const char *start_pa
 
                ms_insert_folder_start(handle);
 
-               dp = opendir(current_path);
-               if (dp != NULL) {
-                       /*insert current directory*/
+               dir = g_dir_open(current_path, 0, &error);
+               if (error == NULL && dir != NULL) {
                        if (ms_insert_folder(handle, storage_id, current_path, uid) != MS_MEDIA_ERR_NONE) {
                                MS_DBG_ERR("insert folder failed");
                        }
-
-                       while (!readdir_r(dp, &entry, &result)) {
-                               /*check poweroff status*/
+                       while ((name = g_dir_read_name(dir))) {
                                ret = __msc_check_stop_status(storage_type);
                                if (ret != MS_MEDIA_ERR_NONE) {
                                        ms_insert_folder_end(handle, uid);
                                        goto STOP_DIR_SCAN;
                                }
 
-                               if (result == NULL)
-                                       break;
-
-                               if (entry.d_name[0] == '.')
+                               if (name[0] == '.')
                                        continue;
 
-                               if (ms_strappend(path, sizeof(path), "%s/%s", current_path, entry.d_name) != MS_MEDIA_ERR_NONE) {
+                               if (ms_strappend(path, sizeof(path), "%s/%s", current_path, name) != MS_MEDIA_ERR_NONE) {
                                        MS_DBG_ERR("ms_strappend failed");
                                        continue;
                                }
 
-                               if (entry.d_type & DT_REG) {
-                                       /* insert into media DB */
+                               if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) {
                                        if (scan_function(handle, storage_id, path, uid) != MS_MEDIA_ERR_NONE) {
                                                MS_DBG_ERR("failed to update db : %d", scan_type);
                                                continue;
                                        }
-                               } else if (entry.d_type & DT_DIR) {
+                               } else if (g_file_test(path, G_FILE_TEST_IS_DIR)) {
                                        if (scan_type != MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) {
-                                               /* this request is recursive scanning */
-                                               /* add new directory to dir_array */
                                                new_path = strdup(path);
                                                if (new_path != NULL) {
                                                        g_array_append_val(dir_array, new_path);
@@ -220,8 +147,6 @@ static int __msc_read_dir(void **handle, GArray *dir_array, const char *start_pa
                                                        continue;
                                                }
                                        } else {
-                                               /* this request is recursive scanning */
-                                               /* don't add new directory to dir_array */
                                                if (ms_insert_folder(handle, storage_id, path, uid) != MS_MEDIA_ERR_NONE) {
                                                        MS_DBG_ERR("insert folder failed");
                                                }
@@ -229,10 +154,13 @@ static int __msc_read_dir(void **handle, GArray *dir_array, const char *start_pa
                                }
                        }
                } else {
-                       MS_DBG_ERR("%s folder opendir fails", current_path);
+                       MS_DBG_ERR("g_dir_open fails [%s]", current_path);
+               }
+
+               if (dir) {
+                       g_dir_close(dir);
+                       dir = NULL;
                }
-               if (dp) closedir(dp);
-               dp = NULL;
 
                ms_insert_folder_end(handle, uid);
 
@@ -240,39 +168,37 @@ static int __msc_read_dir(void **handle, GArray *dir_array, const char *start_pa
        }
 
 STOP_DIR_SCAN:
-       if (dp) closedir(dp);
+       if (dir) {
+               g_dir_close(dir);
+               dir = NULL;
+       }
+
        __msc_clear_file_list(dir_array);
 
        return ret;
-
 }
 
 static int __msc_dir_scan(void **handle, const char *storage_id, const char*start_path, ms_storage_type_t storage_type, int scan_type, bool is_recursive, uid_t uid)
 {
-       GArray *dir_array = NULL;
        int ret = MS_MEDIA_ERR_NONE;
 
-       /*call for bundle commit*/
        ms_bacth_commit_enable(handle, TRUE, TRUE, MS_NOTI_SWITCH_OFF, 0);
 
-       __msc_read_dir(handle, dir_array, start_path, storage_id, storage_type, scan_type, uid);
+       ret = __msc_read_dir(handle, start_path, storage_id, storage_type, scan_type, uid);
 
-       /*call for bundle commit*/
        ms_bacth_commit_disable(handle, TRUE, TRUE, uid);
-
        MS_DBG_INFO("ret : %d", ret);
 
        return ret;
 }
 
-
 static int __msc_stg_scan(void **handle, const char *storage_id, const char*start_path, ms_storage_type_t storage_type, int scan_type, uid_t uid)
 {
-       DIR *dp = NULL;
-       GArray *dir_array = NULL;
-       struct dirent entry;
-       struct dirent *result = NULL;
        int ret = MS_MEDIA_ERR_NONE;
+       GDir *dir = NULL;
+       GError *error = NULL;
+       const char *name;
+       GArray *dir_array = NULL;
        char *new_path = NULL;
        char *current_path = NULL;
        char path[MS_FILE_PATH_LEN_MAX] = { 0 };
@@ -309,7 +235,7 @@ static int __msc_stg_scan(void **handle, const char *storage_id, const char*star
                }
        }
 
-       if (ms_check_folder_path(new_start_path)) {
+       if (g_file_test(new_start_path, G_FILE_TEST_IS_DIR)) {
                ms_insert_folder(handle, storage_id, new_start_path, uid);
        }
 
@@ -333,36 +259,30 @@ static int __msc_stg_scan(void **handle, const char *storage_id, const char*star
 
                ms_insert_folder_start(handle);
 
-               dp = opendir(current_path);
-               if (dp != NULL) {
-                       while (!readdir_r(dp, &entry, &result)) {
+               dir = g_dir_open(current_path, 0, &error);
+               if (error == NULL && dir != NULL) {
+                       while ((name = g_dir_read_name(dir))) {
                                /*check poweroff status*/
                                ret = __msc_check_stop_status(storage_type);
                                if (ret != MS_MEDIA_ERR_NONE) {
                                        goto STOP_SCAN;
                                }
 
-                               if (result == NULL)
-                                       break;
-
-                               if (entry.d_name[0] == '.')
+                               if (name[0] == '.')
                                        continue;
 
-                                if (ms_strappend(path, sizeof(path), "%s/%s", current_path, entry.d_name) != MS_MEDIA_ERR_NONE) {
+                                if (ms_strappend(path, sizeof(path), "%s/%s", current_path, name) != MS_MEDIA_ERR_NONE) {
                                        MS_DBG_ERR("ms_strappend failed");
                                        continue;
                                }
 
-                               if (entry.d_type & DT_REG) {
-                                       /* insert into media DB */
+                               if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) {
                                        if (scan_function(handle, storage_id, path, uid) != MS_MEDIA_ERR_NONE) {
                                                MS_DBG_ERR("failed to update db : %d", scan_type);
                                                continue;
                                        }
-                               } else if (entry.d_type & DT_DIR) {
+                               } else if (g_file_test(path, G_FILE_TEST_IS_DIR)) {
                                        if (scan_type != MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) {
-                                               /* this request is recursive scanning */
-                                               /* add new directory to dir_array */
                                                new_path = strdup(path);
                                                if (new_path != NULL) {
                                                        g_array_append_val(dir_array, new_path);
@@ -375,8 +295,6 @@ static int __msc_stg_scan(void **handle, const char *storage_id, const char*star
                                                        continue;
                                                }
                                        } else {
-                                               /* this request is recursive scanning */
-                                               /* don't add new directory to dir_array */
                                                if (ms_insert_folder(handle, storage_id, path, uid) != MS_MEDIA_ERR_NONE) {
                                                        MS_DBG_ERR("insert folder failed");
                                                        continue;
@@ -384,22 +302,24 @@ static int __msc_stg_scan(void **handle, const char *storage_id, const char*star
                                        }
                                }
                        }
-                       /* update modified time of directory */
                        if (scan_type == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE && storage_type == MS_STORAGE_INTERNAL)
                                ms_update_folder_time(handle, INTERNAL_STORAGE_ID, current_path, uid);
                } else {
-                       MS_DBG_ERR("%s folder opendir fails", current_path);
+                       MS_DBG_ERR("g_dir_open fails [%s]", current_path);
+               }
+
+               if (dir) {
+                       g_dir_close(dir);
+                       dir = NULL;
                }
-               if (dp) closedir(dp);
-               dp = NULL;
 
                ms_insert_folder_end(handle, uid);
 
                MS_SAFE_FREE(current_path);
        }               /*db update while */
 
-               /*remove invalid folder in folder table.*/
-       if (__msc_check_mount_storage(start_path)) {
+       /*remove invalid folder in folder table.*/
+       if (g_file_test(start_path, G_FILE_TEST_IS_DIR)) {
                if (ms_delete_invalid_folder(handle, storage_id, storage_type, uid) != MS_MEDIA_ERR_NONE) {
                        MS_DBG_ERR("delete invalid folder failed");
                        ret = MS_MEDIA_ERR_DB_DELETE_FAIL;
@@ -409,8 +329,10 @@ static int __msc_stg_scan(void **handle, const char *storage_id, const char*star
        }
 
 STOP_SCAN:
-       if (dp) closedir(dp);
-       dp = NULL;
+       if (dir) {
+               g_dir_close(dir);
+               dir = NULL;
+       }
 
        __msc_clear_file_list(dir_array);
 
@@ -432,7 +354,6 @@ static int __msc_db_update(void **handle, const char *storage_id, const ms_comm_
        scan_type = scan_data->msg_type;
        start_path = strndup(scan_data->msg, scan_data->msg_size);
 
-       /*if scan type is not MS_SCAN_NONE, check data in db. */
        if (scan_type != MS_MSG_STORAGE_INVALID) {
                MS_DBG_INFO("INSERT");
 
@@ -440,10 +361,8 @@ static int __msc_db_update(void **handle, const char *storage_id, const ms_comm_
                if (err != MS_MEDIA_ERR_NONE) {
                        MS_DBG_ERR("error : %d", err);
                }
-       } else if (scan_type == MS_MSG_STORAGE_INVALID) {
+       } else {
                MS_DBG_INFO("INVALID");
-               /*In this case, update just validation record*/
-               /*update just valid type*/
                err = ms_validaty_change_all_items(handle, storage_id, storage_type, false, scan_data->uid);
                if (err != MS_MEDIA_ERR_NONE) {
                        MS_DBG_ERR("error : %d", err);
@@ -485,7 +404,6 @@ gboolean msc_directory_scan_thread(void *data)
 
                MS_DBG_WARN("DIRECTORY SCAN START [%s %d]", scan_data->msg, scan_data->msg_type);
 
-               /*connect to media db, if conneting is failed, db updating is stopped*/
                ret = ms_connect_db(&handle, scan_data->uid);
                if (ret != MS_MEDIA_ERR_NONE) {
                        MS_DBG_ERR("ms_connect_db failed");
@@ -495,28 +413,20 @@ gboolean msc_directory_scan_thread(void *data)
                scan_type = scan_data->msg_type;
 
                if (strlen(scan_data->storage_id) > 0) {
-                       /*MS_DBG("path : [%s], storage_id : [%s]", scan_data->msg, scan_data->storage_id);*/
-                       storage_id = strdup(scan_data->storage_id);
+                       storage_id = g_strdup(scan_data->storage_id);
+                       if (storage_id == NULL) {
+                               MS_DBG_ERR("storage_id NULL");
+                               ret = MS_MEDIA_ERR_INVALID_PARAMETER;
+                               goto NEXT;
+                       }
                } else {
                        MS_DBG_ERR("storage_id length is 0. There is no information of your request [%s]", scan_data->msg);
                        ret = MS_MEDIA_ERR_INVALID_PARAMETER;
                        goto NEXT;
                }
 
-               if (storage_id == NULL) {
-                       MS_DBG_ERR("storage_id NULL");
-                       ret = MS_MEDIA_ERR_INVALID_PARAMETER;
-                       goto NEXT;
-               }
-
                MS_DBG("path : [%s], storage_id : [%s]", scan_data->msg, storage_id);
 
-               if (strlen(storage_id) == 0) {
-                       MS_DBG_ERR("storage_id length is 0. There is no information of your request [%s]", scan_data->msg);
-                       ret = MS_MEDIA_ERR_INVALID_PARAMETER;
-                       goto NEXT;
-               }
-
                if (scan_type != MS_MSG_DIRECTORY_SCANNING
                        && scan_type != MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) {
                        MS_DBG_ERR("Invalid request");
@@ -526,7 +436,7 @@ gboolean msc_directory_scan_thread(void *data)
 
                ms_trim_dir_path(scan_data->msg);
 
-               if (ms_check_folder_path(scan_data->msg)) {
+               if (g_file_test(scan_data->msg, G_FILE_TEST_IS_DIR)) {
                        is_recursive = (scan_type == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) ? false : true;
 
                        if (ms_check_folder_exist(handle, storage_id, scan_data->msg) == MS_MEDIA_ERR_NONE) {
@@ -690,11 +600,11 @@ static int _check_folder_from_list(char *folder_path, int item_num, GArray *dir_
 
 static int __msc_compare_with_db(void **handle, const char *storage_id, const char*update_path, int scan_type, GArray **dir_array)
 {
-       DIR *dp = NULL;
-       GArray *read_dir_array = NULL;
-       struct dirent entry;
-       struct dirent *result = NULL;
        int ret = MS_MEDIA_ERR_NONE;
+       GDir *dir = NULL;
+       GError *error = NULL;
+       const char *name;
+       GArray *read_dir_array = NULL;
        char *new_path = NULL;
        char *current_path = NULL;
        char path[MS_FILE_PATH_LEN_MAX] = { 0 };
@@ -725,7 +635,6 @@ static int __msc_compare_with_db(void **handle, const char *storage_id, const ch
                /* get the current path from directory array */
                current_path = g_array_index(read_dir_array , char*, 0);
                g_array_remove_index(read_dir_array, 0);
-//             MS_DBG_ERR("%s", current_path);
 
                if (ms_check_scan_ignore(current_path) != MS_MEDIA_ERR_NONE) {
                        MS_DBG_ERR("%s is ignore", current_path);
@@ -733,25 +642,23 @@ static int __msc_compare_with_db(void **handle, const char *storage_id, const ch
                        continue;
                }
 
-               dp = opendir(current_path);
-               if (dp != NULL) {
-                       while (!readdir_r(dp, &entry, &result)) {
-                               if (result == NULL)
-                                       break;
+               dir = g_dir_open(current_path, 0, &error);
+               if (error == NULL && dir != NULL) {
+                       while ((name = g_dir_read_name(dir))) {
+                               if (name[0] == '.') {
+                                       continue;
+                               }
 
-                               if (entry.d_name[0] == '.') {
+                                if (ms_strappend(path, sizeof(path), "%s/%s", current_path, name) != MS_MEDIA_ERR_NONE) {
+                                       MS_DBG_ERR("ms_strappend failed");
                                        continue;
                                }
 
-                                if (entry.d_type & DT_DIR) {
-                                        if (ms_strappend(path, sizeof(path), "%s/%s", current_path, entry.d_name) != MS_MEDIA_ERR_NONE) {
-                                               MS_DBG_ERR("ms_strappend failed");
-                                               continue;
-                                       }
+                                if (g_file_test(path, G_FILE_TEST_IS_DIR)) {
                                        /* add new directory to dir_array */
                                        new_path = strdup(path);
                                        g_array_append_val(read_dir_array, new_path);
-                               } else if (entry.d_type & DT_REG) {
+                               } else if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) {
                                        item_num++;
                                }
                        }
@@ -760,10 +667,13 @@ static int __msc_compare_with_db(void **handle, const char *storage_id, const ch
                        _check_folder_from_list(current_path, item_num, *dir_array);
                        item_num = 0;
                } else {
-                       MS_DBG_ERR("%s folder opendir fails", current_path);
+                       MS_DBG_ERR("g_dir_open fails [%s]", current_path);
+               }
+               if (dir) {
+                       g_dir_close(dir);
+                       dir = NULL;
                }
-               if (dp) closedir(dp);
-               dp = NULL;
+
                MS_SAFE_FREE(current_path);
        }               /*db update while */
 
@@ -786,7 +696,6 @@ static int _msc_db_update_partial(void **handle, const char *storage_id, ms_stor
                dir_info = g_array_index(dir_array, ms_dir_info_s*, i);
                update_path = strdup(dir_info->dir_path);
 
-//             MS_DBG_SLOG("update_path : %s, %d", update_path, dir_info->modified_time);
                if (dir_info->modified_time != -1) {
                        err = ms_set_folder_item_validity(handle, storage_id, update_path, MS_INVALID, MS_NON_RECURSIVE, uid);
                        if (err != MS_MEDIA_ERR_NONE) {
@@ -797,9 +706,6 @@ static int _msc_db_update_partial(void **handle, const char *storage_id, ms_stor
 
                __msc_stg_scan(handle, storage_id, update_path, storage_type, MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE, uid);
 
-//             if (dir_info->modified_time != -1) {
-//                     ms_update_folder_time(handle, tmp_path);
-//             }
                MS_SAFE_FREE(update_path);
        }
 
@@ -1271,11 +1177,11 @@ int msc_set_cancel_path(const char *cancel_path)
 
 static int __msc_dir_scan_meta_update(void **handle, const char*start_path, const char *storage_id, ms_storage_type_t storage_type, uid_t uid)
 {
-       DIR *dp = NULL;
-       GArray *dir_array = NULL;
-       struct dirent entry;
-       struct dirent *result = NULL;
        int ret = MS_MEDIA_ERR_NONE;
+       GDir *dir = NULL;
+       GError *error = NULL;
+       const char *name;
+       GArray *dir_array = NULL;
        char *new_path = NULL;
        char *current_path = NULL;
        char *tmp_path = NULL;
@@ -1317,40 +1223,28 @@ static int __msc_dir_scan_meta_update(void **handle, const char*start_path, cons
                        continue;
                }
 
-               dp = opendir(current_path);
-               if (dp != NULL) {
-                       while (!readdir_r(dp, &entry, &result)) {
-                               /*check poweroff status*/
+               dir = g_dir_open(current_path, 0, &error);
+               if (error == NULL && dir != NULL) {
+                       while ((name = g_dir_read_name(dir))) {
                                ret = __msc_check_stop_status(storage_type);
                                if (ret != MS_MEDIA_ERR_NONE) {
                                        goto STOP_SCAN;
                                }
 
-                               if (result == NULL)
-                                       break;
-
-                               if (entry.d_name[0] == '.')
+                               if (name[0] == '.')
                                        continue;
 
-                               if (entry.d_type & DT_REG) {
-                                        if (ms_strappend(path, sizeof(path), "%s/%s", current_path, entry.d_name) != MS_MEDIA_ERR_NONE) {
-                                               MS_DBG_ERR("ms_strappend failed");
-                                               continue;
-                                       }
+                                if (ms_strappend(path, sizeof(path), "%s/%s", current_path, name) != MS_MEDIA_ERR_NONE) {
+                                       MS_DBG_ERR("ms_strappend failed");
+                                       continue;
+                               }
 
-                                       /* insert into media DB */
-                                       MS_DBG_WARN("%s", path);
+                               if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) {
                                        if (scan_function(handle, path, storage_id, uid) != MS_MEDIA_ERR_NONE) {
                                                MS_DBG_ERR("failed to update db");
                                                continue;
                                        }
-                               } else if (entry.d_type & DT_DIR) {
-                                       /* this request is recursive scanning */
-                                        if (ms_strappend(path, sizeof(path), "%s/%s", current_path, entry.d_name) != MS_MEDIA_ERR_NONE) {
-                                               MS_DBG_ERR("ms_strappend failed");
-                                               continue;
-                                       }
-                                       /* add new directory to dir_array */
+                               } else if (g_file_test(path, G_FILE_TEST_IS_DIR)) {
                                        new_path = strdup(path);
                                        g_array_append_val(dir_array, new_path);
                                }
@@ -1359,12 +1253,18 @@ static int __msc_dir_scan_meta_update(void **handle, const char*start_path, cons
                        MS_DBG_ERR("%s folder opendir fails", current_path);
                }
 
-               if (dp) closedir(dp);
-               dp = NULL;
+               if (dir) {
+                       g_dir_close(dir);
+                       dir = NULL;
+               }
+
                MS_SAFE_FREE(current_path);
        }               /*db update while */
 STOP_SCAN:
-       if (dp) closedir(dp);
+       if (dir) {
+               g_dir_close(dir);
+               dir = NULL;
+       }
 
        __msc_clear_file_list(dir_array);
 
index 1611a81..58542da 100755 (executable)
@@ -77,9 +77,11 @@ int main(int argc, char **argv)
        msc_init_scanner();
 
        /* Create pipe */
-       err = unlink(MS_SCANNER_FIFO_PATH_REQ);
-       if (err != 0) {
-               MS_DBG_STRERROR("unlink failed");
+       if (g_file_test(MS_SCANNER_FIFO_PATH_REQ, G_FILE_TEST_EXISTS)) {
+               err = unlink(MS_SCANNER_FIFO_PATH_REQ);
+               if (err != 0) {
+                       MS_DBG_STRERROR("unlink failed");
+               }
        }
 
        err = mkfifo(MS_SCANNER_FIFO_PATH_REQ, MS_SCANNER_FIFO_MODE);
index 17517c7..dfef975 100755 (executable)
@@ -434,17 +434,20 @@ int main(int argc, char **argv)
        GThread *dcm_thread = NULL;
        GIOChannel *channel = NULL;
        bool is_dcm_supported = __ms_is_dcm_supported();
+       power_off = FALSE;
+
+#ifdef _USE_TVPD_MODE
+       uid_t uid = MEDIA_DEFAULT_UID;
        double db_size = 0.0;
        double free_space = 0.0;
-       uid_t uid = MEDIA_DEFAULT_UID;
-
-       power_off = FALSE;
 
        __ms_deal_reset_status();
+#endif
 
        /*Init main loop*/
        mainloop = g_main_loop_new(NULL, FALSE);
 
+#ifdef _USE_TVPD_MODE
        ms_check_size_mediadb(uid, &db_size);
        ms_get_remain_space(&free_space);
        MS_DBG_WARN("==========================");
@@ -464,6 +467,7 @@ int main(int argc, char **argv)
                MS_DBG_ERR("MEDIA DB IS CORRUPTED. RESET MEDIA DB.");
                ms_reset_mediadb(uid);
        }
+#endif
 
        __ms_new_global_variable();
 
index 0c84256..09e3eed 100755 (executable)
@@ -234,10 +234,13 @@ int ms_scanner_start(void)
                ms_comm_msg_s recv_msg;
                int scanner_status = -1;
 
-               err = unlink(MS_SCANNER_FIFO_PATH_RES);
-               if (err != 0) {
-                       MS_DBG_STRERROR("[No-Error] unlink failed");
+               if (g_file_test(MS_SCANNER_FIFO_PATH_RES, G_FILE_TEST_EXISTS)) {
+                       err = unlink(MS_SCANNER_FIFO_PATH_RES);
+                       if (err != 0) {
+                               MS_DBG_STRERROR("unlink failed");
+                       }
                }
+
                err = mkfifo(MS_SCANNER_FIFO_PATH_RES, MS_SCANNER_FIFO_MODE);
                if (err != 0) {
                        MS_DBG_STRERROR("mkfifo failed");
index 6138e82..aaf8954 100755 (executable)
@@ -245,7 +245,7 @@ static int __ms_recovery_media_db(uid_t uid)
        ms_reset_mediadb(uid);
 
        /*write read schema*/
-       /*load functions from plusin(s)*/
+       /*load functions from plugin(s)*/
        err = ms_load_functions();
        if (err != MS_MEDIA_ERR_NONE) {
                MS_DBG_ERR("function load failed [%d]", err);