Recover media table 03/321503/4 accepted/tizen_9.0_unified tizen_9.0 accepted/tizen/9.0/unified/20250327.154353 accepted/tizen/9.0/unified/20250327.160032
authorMinje Ahn <minje.ahn@samsung.com>
Mon, 24 Mar 2025 08:02:35 +0000 (17:02 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Tue, 25 Mar 2025 02:22:55 +0000 (11:22 +0900)
This is a code to recover the media table when the db is corrupted due to frequent insertion/deletion of external storage.

Change-Id: Ie700fc700da8299df756626ed5c2133dd39442b5
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
packaging/media-server.spec
src/common/media-common-db-svc.c
src/server/media-server-device-block.c

index dc5a7d9d34d71311978433f1c1bfa26740da5f34..daf099fb932a406c8e8b1732d8abdf9af74bc41d 100644 (file)
@@ -1,7 +1,7 @@
 Name:       media-server
 Summary:    A server for media content management
 Version:    0.6.12
-Release:    0
+Release:    1
 Group:      Multimedia/Service
 License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
index dae18b1aa403acc3906e0f6879f73da3645ec565..8f7165a2e7dd5dc55d9b8113e24e9d311ae0a5c6 100644 (file)
@@ -198,10 +198,18 @@ static int __ms_check_item_exist(sqlite3 *handle, const char *path, bool *modifi
        struct stat st = { 0, };
        sqlite3_stmt *sql_stmt = NULL;
        char *sql = NULL;
+#ifdef _USE_TVPD_MODE
+       g_autofree gchar *folder_path = NULL;
+#endif
 
        *modified = true;
        MS_DBG_RETVM_IF(!MS_STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
-       sql = sqlite3_mprintf("SELECT media_modified_time, media_size FROM media WHERE media_path='%q'", path);
+#ifdef _USE_TVPD_MODE
+       folder_path = g_path_get_dirname(path);
+       sql = sqlite3_mprintf("SELECT media_modified_time, media_size FROM media WHERE media_path=%Q AND folder_id=(SELECT folder_id FROM folder WHERE folder_path=%Q)", path, folder_path);
+#else
+       sql = sqlite3_mprintf("SELECT media_modified_time, media_size FROM media WHERE media_path=%Q", path);
+#endif
 
        ret = media_db_get_result(handle, sql, &sql_stmt);
        sqlite3_free(sql);
index 4ba187978f9a5aa98c61435903db363e32fe7807..586beb90221357f1dce06c219ab212c4f36cbf82 100644 (file)
@@ -174,6 +174,9 @@ void ms_device_handle_usb_added(const char *mount_path)
                                if (ms_set_storage_scan_status(storage_id, MEDIA_SCAN_PREPARE, uid) != MS_MEDIA_ERR_NONE)
                                        MS_DBG_ERR("ms_set_storage_scan_status failed");
 
+                               ms_validity_change_all_items(handle, storage_id, false, uid);
+                               ms_set_folder_validity(handle, mount_path, MS_INVALID, true, uid);
+
                                media_db_update_send(getpid(), MS_MEDIA_ITEM_STORAGE, MS_MEDIA_ITEM_UPDATE, mount_path, storage_id, 0, PROD_CUSTOM_MIME_ADDED);
                        } else {
                                /* there is no information of this storage in Media DB */