Reinforce line coverage
[platform/core/api/media-content.git] / src / media_util_private.c
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;
 }