return MEDIA_CONTENT_ERROR_NONE;
}
+static bool __is_scan_ignore_exist(const char *path)
+{
+ const char *scan_ignore = ".scan_ignore";
+ char *ignore_path = NULL;
+ gboolean result = FALSE;
+
+ if (!STRING_VALID(path))
+ return false;
+
+ ignore_path = g_build_path(G_DIR_SEPARATOR_S, path, scan_ignore, NULL);
+ result = g_file_test(ignore_path, G_FILE_TEST_EXISTS);
+
+ if (result)
+ media_content_error("scan ignore file exist [%s]", ignore_path);
+
+ SAFE_FREE(ignore_path);
+
+ return (bool)result;
+}
+
int _media_util_check_ignore_dir(const char *dir_path, bool *ignore)
{
int ret = MEDIA_CONTENT_ERROR_NONE;
ms_user_storage_type_e storage_type = MS_USER_STORAGE_INTERNAL;
- const char *scan_ignore = ".scan_ignore";
- bool find = false;
- GDir *dir = NULL;
- GError *error = NULL;
- const char *name;
-
- media_content_sec_debug("dir_path : %s", dir_path);
media_content_retvm_if(!STRING_VALID(dir_path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid dir_path");
+ media_content_sec_debug("dir_path : %s", dir_path);
- *ignore = FALSE;
+ *ignore = false;
/*1. Check Hidden Directory*/
if (strstr(dir_path, "/.") != NULL) {
- *ignore = TRUE;
+ *ignore = true;
media_content_error("hidden path");
return MEDIA_CONTENT_ERROR_NONE;
}
}
while (STRING_VALID(search_path)) {
- dir = g_dir_open(search_path, 0, &error);
- if (dir != NULL && error == NULL) {
- while ((name = g_dir_read_name(dir))) {
- if (g_strcmp0(name, scan_ignore) == 0) {
- media_content_sec_debug("Ignore path[%s]", search_path);
- find = TRUE;
- break;
- }
- }
- } else {
- *ignore = TRUE;
- media_content_error("Open Directory fail");
- if (error->code == G_FILE_ERROR_ACCES) {
- g_error_free(error);
- return MEDIA_CONTENT_ERROR_PERMISSION_DENIED;
- } else {
- g_error_free(error);
- return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
- }
-
- if (dir)
- g_dir_close(dir);
+ if ((*ignore = __is_scan_ignore_exist(search_path)))
+ break;
- if (find) {
- *ignore = TRUE;
+ leaf_path = strrchr(search_path, '/');
+ if (!leaf_path)
break;
- } else {
- /*If root path, Stop Scanning*/
- if ((storage_type == MS_USER_STORAGE_INTERNAL) && (STRING_VALID(MEDIA_ROOT_PATH_INTERNAL) && g_strcmp0(search_path, MEDIA_ROOT_PATH_INTERNAL) == 0)) {
- break;
- } else if ((storage_type == MS_USER_STORAGE_EXTERNAL) && (STRING_VALID(MEDIA_ROOT_PATH_SDCARD)) && (g_strcmp0(search_path, MEDIA_ROOT_PATH_SDCARD) == 0)) {
- break;
- } else if ((storage_type == MS_USER_STORAGE_EXTERNAL_USB) && (STRING_VALID(MEDIA_ROOT_PATH_DISC)) && (g_strcmp0(search_path, MEDIA_ROOT_PATH_DISC) == 0)) {
- break;
- } else if (storage_type == MS_USER_STORAGE_EXTERNAL_USB) {
- char *parent_folder_path = NULL;
- bool is_root = FALSE;
-
- parent_folder_path = g_path_get_dirname(search_path);
- if (STRING_VALID(MEDIA_ROOT_PATH_USB) && STRING_VALID(parent_folder_path) && (g_strcmp0(parent_folder_path, MEDIA_ROOT_PATH_USB) == 0))
- is_root = TRUE;
-
- SAFE_FREE(parent_folder_path);
-
- if (is_root == TRUE)
- break;
- }
-#ifdef _USE_SENIOR_MODE
- if (_media_content_is_support_senior_mode()) {
- if ((storage_type == MEDIA_SVC_STORAGE_EXTERNAL) && (g_strcmp0(search_path, MEDIA_ROOT_PATH_SENIOR_MODE) == 0))
- break;
- }
-#endif
- leaf_path = strrchr(search_path, '/');
- if (leaf_path != NULL) {
- int seek_len = leaf_path -search_path;
- search_path[seek_len] = '\0';
- /*media_content_sec_debug("go to other dir [%s]", search_path);*/
- } else {
- media_content_debug("Fail to find leaf path");
- break;
- }
- }
+ search_path[leaf_path - search_path] = '\0';
}
return MEDIA_CONTENT_ERROR_NONE;