From cb284b5fd4011a70e1bdc16f249fbf8efcb04a0c Mon Sep 17 00:00:00 2001 From: Minje Ahn Date: Mon, 11 Sep 2017 16:28:13 +0900 Subject: [PATCH] Modify checker for scan ignore Use g_dir_open instead of readdir_r Change-Id: Idc9f0ddd3c16809443435a28268c44c0370b4160 Signed-off-by: Minje Ahn --- packaging/capi-content-media-content.spec | 2 +- src/media_util_private.c | 43 ++++++++++++------------------- 2 files changed, 17 insertions(+), 28 deletions(-) diff --git a/packaging/capi-content-media-content.spec b/packaging/capi-content-media-content.spec index b28f1f4..70494c3 100755 --- a/packaging/capi-content-media-content.spec +++ b/packaging/capi-content-media-content.spec @@ -1,6 +1,6 @@ Name: capi-content-media-content Summary: A Media content library in Tizen Native API -Version: 0.3.26 +Version: 0.3.27 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/media_util_private.c b/src/media_util_private.c index cf7586d..b41e3e8 100755 --- a/src/media_util_private.c +++ b/src/media_util_private.c @@ -65,6 +65,9 @@ int _media_util_check_ignore_dir(const char *dir_path, bool *ignore) media_svc_storage_type_e storage_type = 0; 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); @@ -85,10 +88,6 @@ int _media_util_check_ignore_dir(const char *dir_path, bool *ignore) return _content_error_capi(MEDIA_CONTENT_TYPE, ret); } - DIR *dp = NULL; - struct dirent entry; - struct dirent *result = NULL; - char *leaf_path = NULL; char search_path[MAX_PATH_LEN] = {0, }; @@ -99,36 +98,26 @@ int _media_util_check_ignore_dir(const char *dir_path, bool *ignore) } while (STRING_VALID(search_path)) { - dp = opendir(search_path); - if (dp == NULL) { + dir = g_dir_open(search_path, 0, &error); + if (dir != NULL && error == NULL) { + while ((name = g_dir_read_name(dir))) { + if (strcmp(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"); - media_content_sec_debug("Open fail path[%s]", search_path); - if (errno == EACCES || errno == EPERM) + if (error->code == G_FILE_ERROR_ACCES) return MEDIA_CONTENT_ERROR_PERMISSION_DENIED; else return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; } - media_content_retvm_if(dp == NULL, MEDIA_CONTENT_ERROR_INVALID_OPERATION, "Open Directory fail"); - - while (!readdir_r(dp, &entry, &result)) { - if (result == NULL) - break; - - if (STRING_VALID(entry.d_name) && (strcmp(entry.d_name, scan_ignore) == 0)) { - media_content_error("Find Ignore path"); - media_content_sec_debug("Ignore path[%s]", search_path); - find = TRUE; - break; - } else { - /*media_content_sec_debug("entry.d_name[%s]", entry.d_name);*/ - continue; - } - } - - if (dp) closedir(dp); - dp = NULL; + if (dir) + g_dir_close(dir); if (find) { *ignore = TRUE; -- 2.7.4