Reinforce line coverage 47/309447/3 accepted/tizen/unified/20240412.141450 accepted/tizen/unified/x/20240415.014030
authorMinje Ahn <minje.ahn@samsung.com>
Thu, 11 Apr 2024 01:39:55 +0000 (10:39 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Fri, 12 Apr 2024 00:05:29 +0000 (09:05 +0900)
line coverage: 82.3%

Change-Id: I4c019a6da3162c30ec25edb72ec047fc448b1093
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
CMakeLists.txt
packaging/capi-content-media-content.spec
src/media_content.c
src/media_db.c
src/media_filter.c
src/media_info.c
src/media_util_private.c

index de0f984..e1b172e 100644 (file)
@@ -1,4 +1,4 @@
-CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6...2.8.12)
 SET(fw_name "capi-content-media-content")
 
 PROJECT(${fw_name})
index efbe6a2..0fac5ef 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-content-media-content
 Summary:    A Media content library in Tizen Native API
-Version:    0.4.31
+Version:    0.5.0
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 360a59f..77030a4 100644 (file)
@@ -68,7 +68,7 @@ int _content_get_result(char *query, sqlite3_stmt **stmt)
        content_retip_if_fail(_content_get_db_handle());
        content_retip_if_fail(query);
 
-       content_sec_debug("Query[%s]", query);
+       content_debug("Query[%s]", query);
 
        err = sqlite3_prepare_v2(_content_get_db_handle(), query, strlen(query), stmt, NULL);
        if (err != SQLITE_OK) {
@@ -237,10 +237,10 @@ int media_content_scan_file(const char *path)
                        ret = media_svc_insert_item_immediately(_content_get_db_handle(), storage_id, path, _content_get_uid());
                        if (ret != MS_MEDIA_ERR_NONE) {
                                if (ret == MS_MEDIA_ERR_DB_CONSTRAINT_FAIL) {
-                                       content_sec_error("This item is already inserted. This may be normal operation because other process already did this (%s)", path);
+                                       content_error("This item is already inserted. This may be normal operation because other process already did this");
                                        ret = MEDIA_CONTENT_ERROR_NONE;
                                } else {
-                                       content_sec_error("media_svc_insert_item_immediately failed : %d (%s)", ret, path);
+                                       content_error("media_svc_insert_item_immediately failed : %d", ret);
                                }
 
                                return _content_error_capi(ret);
@@ -345,6 +345,8 @@ int media_content_scan_folder(const char *path, bool is_recursive, media_scan_co
        ret = _media_content_check_dir(path);
        content_retvm_if(ret == MEDIA_CONTENT_ERROR_PERMISSION_DENIED, ret, "Permission Denied");
 
+       content_sec_debug("Path : %s", path);
+
        if (ret == MEDIA_CONTENT_ERROR_NONE) {
                /* If directory exist check that's ignore directory or not*/
                content_retvm_if(_media_util_is_ignorable_dir(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
@@ -352,7 +354,7 @@ int media_content_scan_folder(const char *path, bool is_recursive, media_scan_co
                /* This means this folder has to be deleted */
                /* Or, it is real invalid path.. check storage type */
                if (!ms_user_is_valid_path(_content_get_uid(), path)) {
-                       content_sec_error("ms_user_is_valid_path failed : %d (%s)", ret, path);
+                       content_error("ms_user_is_valid_path failed : %d", ret);
                        return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
                }
 
@@ -425,6 +427,8 @@ int media_content_scan_folder_v2(const char *path, bool is_recursive, media_scan
        content_retip_if_fail(STRING_VALID(path));
        content_retip_if_fail(callback);
 
+       content_sec_debug("Path : %s", path);
+
        content_retvm_if(!_is_mounted(path), MEDIA_CONTENT_ERROR_PERMISSION_DENIED, "path is not mounted");
        content_retvm_if(_media_util_is_ignorable_dir(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
 
index d4c0792..112d846 100755 (executable)
@@ -437,7 +437,7 @@ int _media_db_get_group_count(filter_h filter, group_list_e group_type, int *gro
        case MEDIA_GROUP_FOLDER:
                select_query = g_strdup(SELECT_FOLDER_COUNT);
                break;
-
+// LCOV_EXCL_START
        case MEDIA_GROUP_PLAYLIST:
                select_query = g_strdup(SELECT_PLAYLIST_COUNT);
                break;
@@ -453,7 +453,7 @@ int _media_db_get_group_count(filter_h filter, group_list_e group_type, int *gro
        case MEDIA_GROUP_FACE:
                select_query = g_strdup(SELECT_FACE_COUNT);
                break;
-
+// LCOV_EXCL_STOP
        default:
                content_error("Invalid group type [%d]", group_type);
                return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
@@ -645,7 +645,7 @@ int _media_db_get_folder(filter_h filter, media_folder_cb callback, void *user_d
 
        return ret;
 }
-
+// LCOV_EXCL_START
 int _media_db_get_playlist(filter_h filter, media_playlist_cb callback, void *user_data)
 {
        int ret = MEDIA_CONTENT_ERROR_NONE;
@@ -891,7 +891,7 @@ int _media_db_get_face(const char *media_id, filter_h filter, media_face_cb call
        return ret;
 
 }
-
+// LCOV_EXCL_STOP
 int _media_db_get_group_item_count_by_id(int group_id, filter_h filter, group_list_e group_type, int *item_count)
 {
        int ret = MEDIA_CONTENT_ERROR_NONE;
@@ -913,7 +913,7 @@ int _media_db_get_group_item_count_by_id(int group_id, filter_h filter, group_li
                select_query = g_strdup_printf(SELECT_MEDIA_COUNT_FROM_ALBUM, group_id);
 #endif
                break;
-
+// LCOV_EXCL_START
        case MEDIA_GROUP_PLAYLIST:
                select_query = g_strdup_printf(SELECT_MEDIA_COUNT_FROM_PLAYLIST, group_id);
                break;
@@ -921,7 +921,7 @@ int _media_db_get_group_item_count_by_id(int group_id, filter_h filter, group_li
        case MEDIA_GROUP_TAG:
                select_query = g_strdup_printf(SELECT_MEDIA_COUNT_FROM_TAG, group_id);
                break;
-
+// LCOV_EXCL_STOP
        default:
                content_error("INVALID_PARAMETER");
                return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
@@ -1081,7 +1081,7 @@ int _media_db_get_group_item_by_id(int group_id, filter_h filter, media_info_cb
                select_query = g_strdup_printf(SELECT_MEDIA_FROM_ALBUM, group_id);
 #endif
                break;
-
+// LCOV_EXCL_START
        case MEDIA_GROUP_PLAYLIST:
 #ifdef _USE_TVPD_MODE
                if (_filter && STRING_VALID(_filter->storage_id))
@@ -1103,7 +1103,7 @@ int _media_db_get_group_item_by_id(int group_id, filter_h filter, media_info_cb
                select_query = g_strdup_printf(SELECT_MEDIA_FROM_TAG, group_id);
 #endif
                break;
-
+// LCOV_EXCL_STOP
        default:
                content_error("INVALID_PARAMETER");
                return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
index afb90d9..fe6fee5 100755 (executable)
@@ -80,7 +80,7 @@ int _media_filter_build_condition(bool is_full, const char *condition, media_con
        else
                *result = g_strdup_printf("(%s%s)", condition, __get_collate_str(collate_type));
 
-       content_sec_debug("Condition : %s", *result);
+       content_debug("Condition : %s", *result);
 
        return MEDIA_CONTENT_ERROR_NONE;
 }
@@ -184,7 +184,7 @@ int media_filter_set_condition(filter_h filter, const char *condition, media_con
 
        _filter->condition = g_strdup(condition);
 
-       content_sec_debug("Condition string : %s", _filter->condition);
+       content_debug("Condition string : %s", _filter->condition);
 
        _filter->condition_collate_type = collate_type;
 
@@ -221,7 +221,7 @@ int media_filter_set_storage(filter_h filter, const char *storage_id)
        g_free(_filter->storage_id);
        _filter->storage_id = g_strdup(storage_id);
 
-       content_sec_debug("storage_id : %s", _filter->storage_id);
+       content_debug("storage_id : %s", _filter->storage_id);
 
        return MEDIA_CONTENT_ERROR_NONE;
 }
@@ -273,7 +273,7 @@ int media_filter_get_order(filter_h filter, media_content_order_e *order_type, c
 
        return MEDIA_CONTENT_ERROR_NONE;
 }
-
+// LCOV_EXCL_START
 int media_filter_set_condition_v2(filter_h filter, const char *condition)
 {
        filter_s *_filter = (filter_s *)filter;
@@ -287,7 +287,7 @@ int media_filter_set_condition_v2(filter_h filter, const char *condition)
 
        _filter->condition = g_strdup(condition);
 
-       content_sec_debug("Condition string : %s", _filter->condition);
+       content_debug("Condition string : %s", _filter->condition);
 
        return MEDIA_CONTENT_ERROR_NONE;
 }
@@ -332,3 +332,4 @@ int media_filter_get_order_v2(filter_h filter, char **order)
 
        return MEDIA_CONTENT_ERROR_NONE;
 }
+// LCOV_EXCL_STOP
\ No newline at end of file
index fe87c52..15b625a 100644 (file)
@@ -94,7 +94,6 @@ static int __media_info_insert_batch(const char **path_array,
 
        fp = fopen(list_path, "w");
        if (fp == NULL) {
-               content_sec_error("failed to open file : [%s]", list_path);
                content_stderror("failed to open file");
                return MEDIA_CONTENT_ERROR_INVALID_OPERATION;
        }
@@ -340,6 +339,8 @@ int media_info_insert_to_db(const char *path, media_info_h *info)
        content_retip_if_fail(STRING_VALID(path));
        content_retip_if_fail(info);
 
+       content_sec_debug("path [%s]", path);
+
        ret = __media_info_check_file_validity(path);
        content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
 
@@ -361,22 +362,21 @@ int media_info_insert_to_db(const char *path, media_info_h *info)
                        }
                }
        } else if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
-               content_sec_debug("media_svc_check_item_exist_by_path : no record : %s", path);
                content_retvm_if(!_media_util_check_support_media_type(path), MEDIA_CONTENT_ERROR_NOT_SUPPORTED, "Unsupported media type");
 
                ret = media_svc_insert_item_immediately(_content_get_db_handle(), storage_id, path, _content_get_uid());
                if (ret != MS_MEDIA_ERR_NONE) {
                        if (ret == MS_MEDIA_ERR_DB_CONSTRAINT_FAIL) {
-                               content_sec_error("This item is already inserted. This may be normal operation because other process already did this (%s)", path);
+                               content_info("This item is already inserted. This may be normal operation because other process already did this");
                                ret = MEDIA_CONTENT_ERROR_NONE;
                        } else {
-                               content_sec_error("media_svc_insert_item_immediately failed : %d (%s)", ret, path);
+                               content_error("media_svc_insert_item_immediately failed : %d", ret);
                        }
 
                        return _content_error_capi(ret);
                }
        } else {
-               content_sec_error("media_svc_get_modified_time failed : %d (%s)", ret, path);
+               content_error("media_svc_get_modified_time failed : %d", ret);
                return _content_error_capi(ret);
        }
 
@@ -753,7 +753,7 @@ int media_info_get_image(media_info_h media, image_meta_h *image)
 
        return ret;
 }
-
+// LCOV_EXCL_START
 int media_info_get_video(media_info_h media, video_meta_h *video)
 {
        content_warn("DEPRECATION WARNING: media_info_get_video() is deprecated and will be removed from next release.");
@@ -789,7 +789,7 @@ int media_info_get_video(media_info_h media, video_meta_h *video)
 
        return ret;
 }
-
+// LCOV_EXCL_STOP
 int media_info_get_audio(media_info_h media, audio_meta_h *audio)
 {
        int ret = MEDIA_CONTENT_ERROR_NONE;
index 52c65de..3ccf413 100755 (executable)
@@ -33,10 +33,7 @@ bool _media_util_check_support_media_type(const char *path)
 
        if (MEDIA_CONTENT_OTHER_SUPPORT == -1) {
                ret = system_info_get_platform_bool("http://tizen.org/feature/content.scanning.others", &is_supported);
-               if (ret != SYSTEM_INFO_ERROR_NONE) {
-                       content_debug("SYSTEM_INFO_ERROR: content.scanning.others [%d]", ret);
-                       return false;
-               }
+               content_retvm_if(ret != SYSTEM_INFO_ERROR_NONE, false, "SYSTEM_INFO_ERROR: content.scanning.others [%d]", ret);
 
                MEDIA_CONTENT_OTHER_SUPPORT = is_supported;
        }
@@ -45,9 +42,7 @@ bool _media_util_check_support_media_type(const char *path)
        if (!MEDIA_CONTENT_OTHER_SUPPORT) {
                ret = media_svc_get_media_type(path, &media_type);
                content_retvm_if(ret != MS_MEDIA_ERR_NONE, false, "Failed to get media type");
-
-               if (media_type == MEDIA_CONTENT_TYPE_OTHERS)
-                       return false;
+               content_retv_if(media_type == MEDIA_CONTENT_TYPE_OTHERS, false);
        }
 
        return true;
@@ -62,11 +57,9 @@ int _media_util_check_file_exist(const char *path)
        if (exist < 0) {
                if (errno == EACCES || errno == EPERM) {
                        content_stderror("open file fail");
-                       content_sec_debug("path [%s]", path);
                        return MEDIA_CONTENT_ERROR_PERMISSION_DENIED;
                } else {
                        content_stderror("open file fail");
-                       content_sec_debug("path [%s]", path);
                        return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
                }
        }
@@ -78,15 +71,9 @@ int _media_util_check_file_exist(const char *path)
 
 int _media_util_get_file_time(const char *path)
 {
-       struct stat statbuf;
-       int ret = 0;
-
-       memset(&statbuf, 0, sizeof(struct stat));
-       ret = stat(path, &statbuf);
-       if (ret == -1) {
-               content_stderror("stat failed");
-               return ret;
-       }
+       struct stat statbuf = { 0, };
+
+       content_retvm_if(stat(path, &statbuf) == -1, 0, "stat failed");
 
        return statbuf.st_mtime;
 }
@@ -94,7 +81,7 @@ int _media_util_get_file_time(const char *path)
 bool _media_util_is_ignorable_file(const char *path)
 {
        char *tmp_path = NULL;
-       char *org_path = NULL;
+       g_autofree gchar *org_path = NULL;
 
 #ifndef _USE_TVPD_MODE
        char replace[MAX_PATH_LEN] = {0, };
@@ -103,24 +90,13 @@ bool _media_util_is_ignorable_file(const char *path)
        content_retip_if_fail(STRING_VALID(path));
 
        /* Check is exist (It may be the path to the deleted file) */
-       if (!g_file_test(path, G_FILE_TEST_EXISTS)) {
-               content_sec_debug("removed path[%s]", path);
-               return false;
-       }
+       content_retvm_if(!g_file_test(path, G_FILE_TEST_EXISTS), false, "removed path");
 
        /* Check symbolic link file */
-       if (g_file_test(path, G_FILE_TEST_IS_SYMLINK)) {
-               content_error("symbolic link(file)");
-               content_sec_debug("path : %s", path);
-               return true;
-       }
+       content_retvm_if(g_file_test(path, G_FILE_TEST_IS_SYMLINK), true, "symbolic link(file)");
 
        /* Check hidden path */
-       if (strstr(path, "/.") != NULL) {
-               content_error("hidden path");
-               content_sec_debug("path : %s", path);
-               return true;
-       }
+       content_retvm_if(strstr(path, "/."), true, "hidden path");
 
        /* Check symbolic directory */
        tmp_path = realpath(path, NULL);
@@ -130,9 +106,7 @@ bool _media_util_is_ignorable_file(const char *path)
 #ifdef _USE_TVPD_MODE
        if (g_strcmp0(tmp_path, org_path) != 0) {
                content_error("symbolic link(directory)");
-               content_sec_debug("path[%s] real[%s]", org_path, tmp_path);
                SAFE_FREE(tmp_path);
-               g_free(org_path);
                return true;
        }
 #else
@@ -141,23 +115,18 @@ bool _media_util_is_ignorable_file(const char *path)
                snprintf(replace, MAX_PATH_LEN, "%s%s", tzplatform_getenv(TZ_USER_MEDIASHARED), tmp_path + strlen(tzplatform_getenv(TZ_SYS_MEDIASHARED)));
                if (g_strcmp0(replace, org_path) != 0) {
                        content_error("symbolic link(directory)");
-                       content_sec_debug("path[%s] real[%s]", org_path, tmp_path);
                        SAFE_FREE(tmp_path);
-                       g_free(org_path);
                        return true;
                }
        } else {
                if (g_strcmp0(tmp_path, org_path) != 0) {
                        content_error("symbolic link(directory)");
-                       content_sec_debug("path[%s] real[%s]", org_path, tmp_path);
                        SAFE_FREE(tmp_path);
-                       g_free(org_path);
                        return true;
                }
        }
 #endif
        SAFE_FREE(tmp_path);
-       g_free(org_path);
 
        return false;
 }
@@ -184,24 +153,14 @@ static bool __is_scan_ignore_exist(const char *path)
 
 bool _media_util_is_ignorable_dir(const char *dir_path)
 {
-       int ret = MEDIA_CONTENT_ERROR_NONE;
-
        if (!STRING_VALID(dir_path))
                return true;
 
-       content_sec_debug("dir_path : %s", dir_path);
-
        /*1. Check Hidden Directory*/
-       if (strstr(dir_path, "/.") != NULL) {
-               content_error("hidden path");
-               return true;
-       }
+       content_retvm_if(strstr(dir_path, "/."), true, "hidden path");
 
        /*2. Check Scan Ignore Directory*/
-       if (!ms_user_is_valid_path(_content_get_uid(), dir_path)) {
-               content_error("ms_user_is_valid_path failed : %d", ret);
-               return true;
-       }
+       content_retvm_if(!ms_user_is_valid_path(_content_get_uid(), dir_path), true, "ms_user_is_valid_path failed");
 
        char *leaf_path = NULL;
        char search_path[MAX_PATH_LEN] = {0, };
@@ -226,7 +185,7 @@ int _media_content_check_dir(const char *path)
 {
        DIR *dp = NULL;
        char *real = NULL;
-       char *origin = NULL;
+       g_autofree gchar *origin = NULL;
 #ifndef _USE_TVPD_MODE
        char result_path[MAX_PATH_LEN] = {0, };
 #endif
@@ -234,11 +193,9 @@ int _media_content_check_dir(const char *path)
        if (dp == NULL) {
                if (errno == EACCES || errno == EPERM) {
                        content_stderror("open dir fail");
-                       content_sec_error("path [%s]", path);
                        return MEDIA_CONTENT_ERROR_PERMISSION_DENIED;
                } else {
                        content_stderror("open dir fail");
-                       content_sec_error("path [%s]", path);
                        return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
                }
        }
@@ -253,9 +210,7 @@ int _media_content_check_dir(const char *path)
 #ifdef _USE_TVPD_MODE
        if (g_strcmp0(real, origin) != 0) {
                content_error("symbolic link(directory)");
-               content_sec_debug("path[%s] real[%s]", origin, real);
                SAFE_FREE(real);
-               g_free(origin);
                return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
        }
 #else
@@ -264,24 +219,19 @@ int _media_content_check_dir(const char *path)
                snprintf(result_path, MAX_PATH_LEN, "%s%s", tzplatform_getenv(TZ_USER_MEDIASHARED), real + strlen(tzplatform_getenv(TZ_SYS_MEDIASHARED)));
                if (g_strcmp0(result_path, origin) != 0) {
                        content_error("symbolic link(directory)");
-                       content_sec_debug("path[%s] real[%s]", origin, real);
                        SAFE_FREE(real);
-                       g_free(origin);
                        return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
                }
        } else {
                if (g_strcmp0(real, origin) != 0) {
                        content_error("symbolic link(directory)");
-                       content_sec_debug("path[%s] real[%s]", origin, real);
                        SAFE_FREE(real);
-                       g_free(origin);
                        return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
                }
        }
 #endif
 
        SAFE_FREE(real);
-       g_free(origin);
 
        return MEDIA_CONTENT_ERROR_NONE;
 }