Improve __ms_check_storage_status 29/213729/4 accepted/tizen/unified/20190916.111552 submit/tizen/20190916.065445
authorMinje Ahn <minje.ahn@samsung.com>
Wed, 11 Sep 2019 00:20:30 +0000 (09:20 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Wed, 11 Sep 2019 02:46:50 +0000 (11:46 +0900)
Change-Id: Id16ddf944bf79ffc7dd71c6d23ced3c5597b3c6e

src/common/include/media-common-system.h
src/common/media-common-db-svc.c
src/common/media-common-system.c
src/scanner/media-scanner-scan.c
src/server/include/media-server-device-block.h
src/server/media-server-device-block.c
src/server/media-server-main.c
src/server/media-server-socket.c

index f99db06..2d56a2b 100755 (executable)
@@ -57,7 +57,6 @@ int ms_sys_set_device_block_event_cb(usb_connected_cb usr_callback, void *usr_da
 #endif
 int ms_sys_unset_device_block_event_cb(void);
 int ms_sys_get_device_list(ms_stg_type_e stg_type, GArray **dev_list);
-int ms_sys_release_device_list(GArray **dev_list);
 
 typedef struct ms_power_info_s {
        int option;
index 6c765dc..0215680 100755 (executable)
@@ -131,7 +131,7 @@ int ms_load_functions(void)
        dlerror();      /* Clear any existing error */
 
        MS_MALLOC(func_array, sizeof(void*) * eFUNC_MAX);
-       if (func_array == NULL) {
+       if (!func_array) {
                MS_DBG_ERR("malloc failed");
                dlclose(func_handle);
 
@@ -175,20 +175,19 @@ int ms_connect_db(sqlite3 **handle, uid_t uid)
 
 void ms_disconnect_db(sqlite3 *handle)
 {
-       if (handle)
-               media_db_disconnect(handle);
+       media_db_disconnect(handle);
 }
 
 int ms_cleanup_db(sqlite3 *handle, uid_t uid)
 {
-       int ret;
+       int ret = MS_MEDIA_ERR_NONE;
 
        ret = ((CLEANUP_DB)func_array[eCLEANUP_DB])(handle, uid); /*dlopen*/
        MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "CLEANUP_DB failed [%d]", ret);
 
        MS_DBG_INFO("Cleanup Media DB");
 
-       return MS_MEDIA_ERR_NONE;
+       return ret;
 }
 
 int __ms_check_item_exist(sqlite3 *handle, const char *storage_id, const char *path, bool *modified)
index 4470b1f..6625561 100755 (executable)
@@ -231,6 +231,15 @@ int ms_sys_unset_device_block_event_cb(void)
 }
 #endif
 
+static void __ms_dev_free(gpointer data)
+{
+       ms_block_info_s **_data = (ms_block_info_s **)data;
+
+       MS_SAFE_FREE((*_data)->mount_path);
+       MS_SAFE_FREE((*_data)->mount_uuid);
+       MS_SAFE_FREE(*_data);
+}
+
 #ifdef _USE_DEVICED_DBUS
 #define DBUS_REPLY_TIMEOUT (-1)
 static int __ms_gdbus_method_sync(const char *dest, const char *path, const char *interface, const char *method, const char *param, GArray **dev_list)
@@ -315,6 +324,7 @@ static int __ms_gdbus_method_sync(const char *dest, const char *path, const char
                                if (*dev_list == NULL) {
                                        MS_DBG_ERR("DEV LIST IS NULL");
                                        *dev_list = g_array_new(FALSE, FALSE, sizeof(ms_block_info_s*));
+                                       g_array_set_clear_func(*dev_list, __ms_dev_free);
                                }
                                g_array_append_val(*dev_list, data);
                        }
@@ -397,6 +407,7 @@ int ms_sys_get_device_list(ms_stg_type_e stg_type, GArray **dev_list)
                        if (*dev_list == NULL) {
                                MS_DBG_ERR("DEV LIST IS NULL");
                                *dev_list = g_array_new(FALSE, FALSE, sizeof(ms_block_info_s*));
+                               g_array_set_clear_func(*dev_list, __ms_dev_free);
                        }
 
                        for (i = 0; i < count; i++) {
@@ -443,28 +454,6 @@ int ms_sys_get_device_list(ms_stg_type_e stg_type, GArray **dev_list)
 }
 #endif
 
-int ms_sys_release_device_list(GArray **dev_list)
-{
-       if (*dev_list) {
-               while ((*dev_list)->len != 0) {
-                       ms_block_info_s *data = NULL;
-                       data = g_array_index(*dev_list , ms_block_info_s*, 0);
-                       g_array_remove_index(*dev_list, 0);
-
-                       if (data != NULL) {
-                               MS_DBG("MOUNT PATH [%s] RELEASED", data->mount_path);
-                               MS_SAFE_FREE(data->mount_path);
-                               MS_SAFE_FREE(data->mount_uuid);
-                               MS_SAFE_FREE(data);
-                       }
-               }
-               g_array_free(*dev_list, FALSE);
-               *dev_list = NULL;
-       }
-
-       return MS_MEDIA_ERR_NONE;
-}
-
 //////////////////////////////////////////////////////////////////////////////
 /// GET ACTIVATE USER ID
 //////////////////////////////////////////////////////////////////////////////
index 07305d2..3bf7200 100755 (executable)
@@ -454,7 +454,7 @@ static int __msc_make_file_list(char *file_path, GPtrArray **path_array, uid_t u
        /* This is an array for storing the path of insert datas*/
        _path_array = g_ptr_array_new_with_free_func(g_free);
        if (!_path_array) {
-               MS_DBG_ERR("g_array_new failed");
+               MS_DBG_ERR("g_ptr_array_new_with_free_func failed");
                fclose(fp);
                return MS_MEDIA_ERR_OUT_OF_MEMORY;
        }
index 316710b..ba4559f 100755 (executable)
@@ -29,7 +29,7 @@ int ms_storage_remove_handler(const char *mount_path, const char *mount_uuid);
 void ms_device_block_changed_cb(ms_block_info_s *block_info, void *user_data);
 #else
 void ms_device_block_changed_cb(usb_device_h usb_device, char *action, void *user_data);
-#endif
 int ms_check_mounted_storage(uid_t uid);
+#endif
 
 #endif
index 98ec975..54f8cf8 100755 (executable)
@@ -407,7 +407,6 @@ static int __ms_check_mounted_storage_list(GArray **added_list)
 
        return ret;
 }
-#endif
 
 int ms_check_mounted_storage(uid_t uid)
 {
@@ -430,11 +429,7 @@ int ms_check_mounted_storage(uid_t uid)
 
        ms_connect_db(&handle, uid);
 
-#ifdef _USE_DEVICED_DBUS
-       ret = ms_sys_get_device_list(MS_STG_TYPE_ALL, &added_list);
-#else
        ret = __ms_check_mounted_storage_list(&added_list);
-#endif
        if (ret != MS_MEDIA_ERR_NONE)
                MS_DBG_ERR("__ms_check_mounted_storage_list failed");
 
@@ -533,4 +528,5 @@ int ms_check_mounted_storage(uid_t uid)
 
        return ret;
 }
+#endif
 
index 0645990..077c0ed 100755 (executable)
@@ -53,7 +53,7 @@ bool smarthub_reset_start;
 bool smarthub_reset;
 
 static void __ms_check_mediadb(void);
-static int __ms_check_storage_status(void);
+static void __ms_update_storage_status(void);
 static void __ms_add_signal_handler(void);
 static void __ms_add_event_receiver(GIOChannel *channel);
 static void __ms_add_request_receiver(GMainLoop *mainloop, GIOChannel **channel);
@@ -601,35 +601,33 @@ static void __ms_add_signal_handler(void)
 }
 
 ////////////////////////////////////////////////////////////////////
-static int __ms_check_storage_status(void)
+static void __ms_update_storage_status(void)
 {
        int ret = MS_MEDIA_ERR_NONE;
-       ms_stg_type_e stg_type = MS_STG_TYPE_ALL;
        GArray *dev_list = NULL;
+       ms_block_info_s *block_info = NULL;
+       int i = 0;
 
-       ret = ms_sys_get_device_list(stg_type, &dev_list);
-       if (ret == MS_MEDIA_ERR_NONE) {
-               if (dev_list != NULL) {
-                       MS_DBG_WARN("External storage found[%d]", dev_list->len);
-                       int i = 0 ;
-                       int dev_num = dev_list->len;
-                       ms_block_info_s *block_info = NULL;
-
-                       for (i = 0; i < dev_num; i++) {
-                               block_info = (ms_block_info_s *)g_array_index(dev_list , ms_stg_type_e*, i);
-                               ms_storage_insert_handler(block_info->mount_path, block_info->mount_uuid);
-                       }
-
-                       ms_sys_release_device_list(&dev_list);
-               } else {
-                       MS_DBG_ERR("External storage not found");
-                       ms_storage_remove_handler(STORAGE_REMOVED, NULL);
-               }
-       } else {
+       ret = ms_sys_get_device_list(MS_STG_TYPE_ALL, &dev_list);
+       if (ret != MS_MEDIA_ERR_NONE) {
                MS_DBG_ERR("ms_sys_get_device_list failed");
+               return;
        }
 
-       return MS_MEDIA_ERR_NONE;
+       if (!dev_list) {
+               MS_DBG_ERR("External storage not found");
+               ms_storage_remove_handler(STORAGE_REMOVED, NULL);
+               return;
+       }
+
+       MS_DBG_WARN("External storage found[%d]", dev_list->len);
+
+       for (i = 0; i < dev_list->len; i++) {
+               block_info = g_array_index(dev_list , ms_block_info_s *, i);
+               ms_storage_insert_handler(block_info->mount_path, block_info->mount_uuid);
+       }
+
+       g_array_free(dev_list, TRUE);
 }
 
 #ifdef _USE_SENIOR_MODE
@@ -780,7 +778,7 @@ static void __ms_check_mediadb(void)
 #endif
 
        /* update external storage */
-       __ms_check_storage_status();
+       __ms_update_storage_status();
 
 #ifdef _USE_SENIOR_MODE
        __ms_check_disc_status();
index ce0789b..5dd918e 100755 (executable)
@@ -192,8 +192,8 @@ static int __ms_recovery_media_db(uid_t uid)
        /*unload functions*/
        ms_unload_functions();
 
-       ms_check_mounted_storage(uid);
 #ifdef _USE_TVPD_MODE
+       ms_check_mounted_storage(uid);
        ms_config_set_int(MS_DB_RESET, 0);
 #endif
        return MS_MEDIA_ERR_NONE;