Change return type to bool 23/229123/3
authorhj kim <backto.kim@samsung.com>
Mon, 30 Mar 2020 02:31:44 +0000 (11:31 +0900)
committerhj kim <backto.kim@samsung.com>
Mon, 30 Mar 2020 06:57:06 +0000 (06:57 +0000)
Change-Id: If968f793b4235dfb0b9f537cf3e3c821daca2bd7

include/media_util_private.h
include_product/media_util_private.h
src/media_content.c
src/media_folder.c
src/media_info.c
src/media_util_private.c

index cf523ec..2b48fb6 100755 (executable)
@@ -33,8 +33,8 @@ bool _media_util_check_support_media_type(const char *path);
 int _media_util_check_file_exist(const char *path);
 void _media_util_trim_path(const char *input_path, char **output_path);
 int _media_util_get_file_time(const char *path);
-int _media_util_check_ignore_file(const char *path, bool *ignore);
-int _media_util_check_ignore_dir(const char *dir_path, bool *ignore);
+bool _media_util_is_ignorable_file(const char *path);
+bool _media_util_is_ignorable_dir(const char *dir_path);
 int _media_content_check_dir(const char *path);
 char * _media_content_replace_path_in_condition(const char *condition);
 int _media_content_replace_path(const char *path, char *replace_path);
index bafa61b..5aa639e 100755 (executable)
@@ -33,8 +33,8 @@ bool _media_util_check_support_media_type(const char *path);
 int _media_util_check_file_exist(const char *path);
 void _media_util_trim_path(const char *input_path, char **output_path);
 int _media_util_get_file_time(const char *path);
-int _media_util_check_ignore_file(const char *path, bool *ignore);
-int _media_util_check_ignore_dir(const char *dir_path, bool *ignore);
+bool _media_util_is_ignorable_file(const char *path);
+bool _media_util_is_ignorable_dir(const char *dir_path);
 int _media_content_check_dir(const char *path);
 char * _media_content_replace_path_in_condition(const char *condition);
 int _media_content_replace_path(const char *path, char *replace_path);
index a29a02a..1640353 100644 (file)
@@ -249,8 +249,6 @@ int media_content_disconnect(void)
 int media_content_scan_file(const char *path)
 {
        int ret = MEDIA_CONTENT_ERROR_NONE;
-       bool ignore_file = FALSE;
-       bool ignore_dir = FALSE;
        char *folder_path = NULL;
        int check_file = MEDIA_CONTENT_ERROR_NONE;
        char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0,};
@@ -264,8 +262,7 @@ int media_content_scan_file(const char *path)
        ret = _media_content_replace_path(path, repl_path);
        content_retvm_if(!STRING_VALID(repl_path), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed");
 
-       ret = _media_util_check_ignore_file(repl_path, &ignore_file);
-       content_retvm_if(ignore_file == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
+       content_retvm_if(_media_util_is_ignorable_file(repl_path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
 
        memset(storage_id, 0x00, sizeof(storage_id));
        ret = media_svc_get_storage_id(_content_get_db_handle(), repl_path, storage_id, _content_get_uid());
@@ -278,10 +275,12 @@ int media_content_scan_file(const char *path)
        if (check_file == MEDIA_CONTENT_ERROR_NONE) {
                /* This means this path has to be inserted or refreshed */
                folder_path = g_path_get_dirname(repl_path);
-               ret = _media_util_check_ignore_dir(folder_path, &ignore_dir);
-               g_free(folder_path);
 
-               content_retvm_if(ignore_dir == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
+               if (_media_util_is_ignorable_dir(folder_path)) {
+                       g_free(folder_path);
+                       return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
+               }
+
                /* check feature */
                content_retvm_if(!_media_util_check_support_media_type(repl_path), MEDIA_CONTENT_ERROR_NOT_SUPPORTED, "Unsupported media type");
 
@@ -406,7 +405,6 @@ void _media_content_scan_cb_v2(media_request_result_s* result, void *user_data)
 int media_content_scan_folder(const char *path, bool is_recursive, media_scan_completed_cb callback, void *user_data)
 {
        int ret = MEDIA_CONTENT_ERROR_NONE;
-       bool ignore_dir = FALSE;
        char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
        char repl_path[MAX_PATH_LEN] = {0, };
        ms_user_storage_type_e storage_type = MS_USER_STORAGE_INTERNAL;
@@ -423,8 +421,7 @@ int media_content_scan_folder(const char *path, bool is_recursive, media_scan_co
 
        if (ret == MEDIA_CONTENT_ERROR_NONE) {
                /* If directory exist check that's ignore directory or not*/
-               ret = _media_util_check_ignore_dir(repl_path, &ignore_dir);
-               content_retvm_if((ignore_dir == TRUE || ret != MEDIA_CONTENT_ERROR_NONE), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
+               content_retvm_if(_media_util_is_ignorable_dir(repl_path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
        } else {
                /* This means this folder has to be deleted */
                /* Or, it is real invalid path.. check storage type */
@@ -463,14 +460,12 @@ int media_content_scan_folder(const char *path, bool is_recursive, media_scan_co
 int media_content_scan_folder_v2(const char *path, bool is_recursive, media_scan_completed_cb_v2 callback, void *user_data)
 {
        int ret = MEDIA_CONTENT_ERROR_NONE;
-       bool ignore_dir = FALSE;
        char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
 
        content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
        memset(storage_id, 0x00, sizeof(storage_id));
 
-       ret = _media_util_check_ignore_dir(path, &ignore_dir);
-       content_retvm_if(ignore_dir, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
+       content_retvm_if(_media_util_is_ignorable_dir(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
 
        ret = _media_content_check_dir(path);
        content_retvm_if(ret == MEDIA_CONTENT_ERROR_PERMISSION_DENIED, ret, "Permission Denied");
index 673f556..ac44f49 100755 (executable)
@@ -429,15 +429,13 @@ int media_folder_insert_to_db(const char *path)
        char repl_path[MAX_PATH_LEN] = {0, };
        int ret = MEDIA_CONTENT_ERROR_NONE;
        char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
-       bool ignore_dir = FALSE;
 
        content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid path");
        memset(repl_path, 0, sizeof(repl_path));
        ret = _media_content_replace_path(path, repl_path);
        content_retvm_if(!STRING_VALID(repl_path), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed");
 
-       ret = _media_util_check_ignore_dir(repl_path, &ignore_dir);
-       content_retvm_if(ignore_dir, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
+       content_retvm_if(_media_util_is_ignorable_dir(repl_path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
 
        ret = _media_content_check_dir(repl_path);
        content_retvm_if(ret == MEDIA_CONTENT_ERROR_PERMISSION_DENIED, ret, "Permission Denied");
index 75d45a0..791b1fb 100644 (file)
@@ -251,24 +251,23 @@ static int __media_info_insert_batch(const char **path_array,
 
 static int __media_info_check_file_validity(const char *path)
 {
-       bool ignore = FALSE;
        char *folder_path = NULL;
        int ret = MEDIA_CONTENT_ERROR_NONE;
 
        content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid path");
 
-       ret = _media_util_check_ignore_file(path, &ignore);
-       content_retvm_if(ignore == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid ignore path");
+       content_retvm_if(_media_util_is_ignorable_file(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid ignore path");
 
        ret = _media_util_check_file_exist(path);
        content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "invalid path");
 
        folder_path = g_path_get_dirname(path);
-       ret = _media_util_check_ignore_dir(folder_path, &ignore);
+       if (_media_util_is_ignorable_dir(folder_path))
+               ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
+
        g_free(folder_path);
-       content_retvm_if(ignore == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
 
-       return MEDIA_CONTENT_ERROR_NONE;
+       return ret;
 }
 
 void _media_info_item_get_detail(sqlite3_stmt* stmt, media_info_h media)
index 9df5125..c8ca777 100755 (executable)
@@ -125,11 +125,10 @@ int _media_util_get_file_time(const char *path)
        return statbuf.st_mtime;
 }
 
-int _media_util_check_ignore_file(const char *path, bool *ignore)
+bool _media_util_is_ignorable_file(const char *path)
 {
        content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid path");
 
-       *ignore = FALSE;
        char *tmp_path = NULL;
        char *org_path = NULL;
 
@@ -140,23 +139,21 @@ int _media_util_check_ignore_file(const char *path, bool *ignore)
        /* 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 MEDIA_CONTENT_ERROR_NONE;
+               return false;
        }
 
        /* Check symbolic link file */
        if (g_file_test(path, G_FILE_TEST_IS_SYMLINK)) {
-               *ignore = TRUE;
                content_error("symbolic link(file)");
                content_sec_debug("path : %s", path);
-               return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
+               return true;
        }
 
        /* Check hidden path */
        if (strstr(path, "/.") != NULL) {
-               *ignore = TRUE;
                content_error("hidden path");
                content_sec_debug("path : %s", path);
-               return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
+               return true;
        }
 
        /* Check symbolic directory */
@@ -166,40 +163,37 @@ int _media_util_check_ignore_file(const char *path, bool *ignore)
 
 #ifdef _USE_TVPD_MODE
        if (g_strcmp0(tmp_path, org_path) != 0) {
-               *ignore = TRUE;
                content_error("symbolic link(directory)");
                content_sec_debug("path[%s] real[%s]", org_path, tmp_path);
                SAFE_FREE(tmp_path);
                SAFE_FREE(org_path);
-               return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
+               return true;
        }
 #else
        if (g_str_has_prefix(tmp_path, MEDIA_SHARE_PATH)) {
                /* If shared dirctory, it should be change path to TZ_USER_SHARE from realpath */
                snprintf(replace, MAX_PATH_LEN, "%s%s", tzplatform_getenv(TZ_USER_MEDIASHARED), tmp_path + strlen(MEDIA_SHARE_PATH));
                if (g_strcmp0(replace, org_path) != 0) {
-                       *ignore = TRUE;
                        content_error("symbolic link(directory)");
                        content_sec_debug("path[%s] real[%s]", org_path, tmp_path);
                        SAFE_FREE(tmp_path);
                        SAFE_FREE(org_path);
-                       return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
+                       return true;
                }
        } else {
                if (g_strcmp0(tmp_path, org_path) != 0) {
-                       *ignore = TRUE;
                        content_error("symbolic link(directory)");
                        content_sec_debug("path[%s] real[%s]", org_path, tmp_path);
                        SAFE_FREE(tmp_path);
                        SAFE_FREE(org_path);
-                       return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
+                       return true;
                }
        }
 #endif
        SAFE_FREE(tmp_path);
        SAFE_FREE(org_path);
 
-       return MEDIA_CONTENT_ERROR_NONE;
+       return false;
 }
 
 static bool __is_scan_ignore_exist(const char *path)
@@ -222,7 +216,7 @@ static bool __is_scan_ignore_exist(const char *path)
        return (bool)result;
 }
 
-int _media_util_check_ignore_dir(const char *dir_path, bool *ignore)
+bool _media_util_is_ignorable_dir(const char *dir_path)
 {
        int ret = MEDIA_CONTENT_ERROR_NONE;
        ms_user_storage_type_e storage_type = MS_USER_STORAGE_INTERNAL;
@@ -230,19 +224,17 @@ int _media_util_check_ignore_dir(const char *dir_path, bool *ignore)
        content_retvm_if(!STRING_VALID(dir_path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid dir_path");
        content_sec_debug("dir_path : %s", dir_path);
 
-       *ignore = false;
        /*1. Check Hidden Directory*/
        if (strstr(dir_path, "/.") != NULL) {
-               *ignore = true;
                content_error("hidden path");
-               return MEDIA_CONTENT_ERROR_NONE;
+               return true;
        }
 
        /*2. Check Scan Ignore Directory*/
        ret = ms_user_get_storage_type(_content_get_uid(), dir_path, &storage_type);
        if (ret != MS_MEDIA_ERR_NONE) {
                content_error("ms_user_get_storage_type failed : %d", ret);
-               return _content_error_capi(ret);
+               return false;
        }
 
        char *leaf_path = NULL;
@@ -252,8 +244,8 @@ int _media_util_check_ignore_dir(const char *dir_path, bool *ignore)
        SAFE_STRLCPY(search_path, dir_path, sizeof(search_path));
 
        while (STRING_VALID(search_path)) {
-               if ((*ignore = __is_scan_ignore_exist(search_path)))
-                       break;
+               if (__is_scan_ignore_exist(search_path))
+                       return true;
 
                leaf_path = strrchr(search_path, '/');
                if (!leaf_path)
@@ -262,7 +254,7 @@ int _media_util_check_ignore_dir(const char *dir_path, bool *ignore)
                search_path[leaf_path - search_path] = '\0';
        }
 
-       return MEDIA_CONTENT_ERROR_NONE;
+       return false;
 }
 
 int _media_content_check_dir(const char *path)