improve vconf callback for data disc 44/107144/2
authorYong Yeon Kim <yy9875.kim@samsung.com>
Tue, 27 Dec 2016 02:05:43 +0000 (11:05 +0900)
committerYong Yeon Kim <yy9875.kim@samsung.com>
Tue, 27 Dec 2016 02:14:31 +0000 (11:14 +0900)
Change-Id: I4d61b1d8a1e8ad723cd65b0c8c5be268d0f02b7b

packaging/media-server.spec
src/server/media-server-main.c

index d0cad14..839f11d 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       media-server
 Summary:    A server for media content management
-Version:    0.3.26
+Version:    0.3.27
 Release:    0
 Group:      Multimedia/Service
 License:    Apache-2.0
index 673fba3..dc20bc0 100755 (executable)
@@ -89,7 +89,7 @@ bool __ms_deal_reset_status()
        if(value == 1 || value == 2)
        {
                MS_DBG_WARN("POWER_OFF_REASON_FACTORY_RESET or SERVICE RESET");
-               
+
                ms_reset_mediadb(uid);
 
                if(!ms_config_set_int(MS_VCONF_KEY_RESET_STATUS, 0))
@@ -158,12 +158,14 @@ void _ms_datadisc_vconf_cb(void *data)
 {
        int ret = MS_MEDIA_ERR_NONE;
        int disc_state = 0;
+       int validity = 0;
        char *disc_type = NULL;
        char *disc_path = NULL;
        char *valid_type = "data";
        ms_dir_scan_type_t scan_type = MS_SCAN_PART;
        uid_t uid = MEDIA_DEFAULT_UID;
-       char storage_path[11] = {0,};
+       char mnt_path[11] = {0,};
+       char *storage_path = NULL;
        void **handle = NULL;
 
        /*check disc type */
@@ -195,24 +197,45 @@ void _ms_datadisc_vconf_cb(void *data)
                }
 
                MS_DBG("[disc path] %s", disc_path);
-               memset(storage_path, 0x0, sizeof(storage_path));
-               strncpy(storage_path, disc_path, sizeof(storage_path)-1);
+               memset(mnt_path, 0x0, sizeof(mnt_path));
+               strncpy(mnt_path, disc_path, sizeof(mnt_path)-1);
 
                if (disc_state == 1) {
                        MS_DBG_WARN("[DISC INSERTED][%s]",disc_type);
-               
-                       MS_DBG_WARN("MOUNT PATH [%s]", storage_path);
 
-                       ret = ms_insert_storage(handle, DATADISC_STORAGE_ID, NULL, storage_path, uid);
-                       if (ret != MS_MEDIA_ERR_NONE) {
-                               MS_DBG_ERR("ms_insert_storage failed");
+                       MS_DBG_WARN("MOUNT PATH [%s]", mnt_path);
+
+                       /* update storage information into media DB */
+                       ret = ms_check_storage(handle, DATADISC_STORAGE_ID, NULL, &storage_path, &validity);
+                       if (ret == 0) {
+                               ms_set_storage_validity(handle, DATADISC_STORAGE_ID, 1, uid);
+                               if (ms_set_storage_scan_status(handle, DATADISC_STORAGE_ID, MEDIA_SCAN_PREPARE, uid) != MS_MEDIA_ERR_NONE) {
+                                       MS_DBG_ERR("ms_set_storage_scan_status failed");
+                                       goto END;
+                               }
+
+                               MS_DBG_WARN("init storage data in DB");
+                               /* update storage_id table set validity=0 first */
+                               ms_validaty_change_all_items(handle, DATADISC_STORAGE_ID, MS_STORAGE_EXTERNAL, false, uid);
+                               /*update folder table set validity = 0*/
+                               ms_set_folder_validity(handle, DATADISC_STORAGE_ID, mnt_path, MS_INVALID, TRUE, uid);
+                               /* update folder table set scan_status=0 first */
+                               ms_set_folder_scan_status(handle, DATADISC_STORAGE_ID, NULL, MS_DIR_SCAN_NONE, uid);
+                               MS_DBG_WARN("init storage data in DB end");
+
                        } else {
-                               ms_send_storage_scan_request(storage_path, DATADISC_STORAGE_ID, scan_type, uid);
+                               ret = ms_insert_storage(handle, DATADISC_STORAGE_ID, NULL, mnt_path, uid);
+                               if (ret != MS_MEDIA_ERR_NONE) {
+                                       MS_DBG_ERR("ms_insert_storage failed");
+                                       goto END;
+                               }
                        }
+
+                       ms_send_storage_scan_request(mnt_path, DATADISC_STORAGE_ID, scan_type, uid);
                } else {
                        MS_DBG_WARN("[DISC REMOVED]");
                        ms_set_storage_validity(handle, DATADISC_STORAGE_ID, 0, uid);
-                       ms_set_folder_validity(handle, DATADISC_STORAGE_ID, storage_path, false, true, uid);
+                       ms_set_folder_validity(handle, DATADISC_STORAGE_ID, mnt_path, false, true, uid);
                        ms_validaty_change_all_items(handle, DATADISC_STORAGE_ID, MS_STORAGE_EXTERNAL_USB, false, uid);
                }
 
@@ -725,12 +748,13 @@ static int __ms_check_disc_status(void)
 
                        ms_connect_db(&handle, uid);
 
-                                       /* update storage information into media DB */
+                       /* update storage information into media DB */
                        ret = ms_check_storage(handle, DATADISC_STORAGE_ID, NULL, &storage_path, &validity);
                        if (ret == 0) {
                                ms_set_storage_validity(handle, DATADISC_STORAGE_ID, 1, uid);
                                if (ms_set_storage_scan_status(handle, DATADISC_STORAGE_ID, MEDIA_SCAN_PREPARE, uid) != MS_MEDIA_ERR_NONE) {
                                        MS_DBG_ERR("ms_set_storage_scan_status failed");
+                                       goto END;
                                }
 
                                MS_DBG_WARN("init storage data in DB");