Modify checker for scan ignore 44/148944/1 accepted/tizen/unified/20170913.071139 submit/tizen/20170912.034220
authorMinje Ahn <minje.ahn@samsung.com>
Mon, 11 Sep 2017 07:28:13 +0000 (16:28 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Mon, 11 Sep 2017 07:28:13 +0000 (16:28 +0900)
Use g_dir_open instead of readdir_r

Change-Id: Idc9f0ddd3c16809443435a28268c44c0370b4160
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
packaging/capi-content-media-content.spec
src/media_util_private.c

index b28f1f4..70494c3 100755 (executable)
@@ -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
index cf7586d..b41e3e8 100755 (executable)
@@ -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;