Modify function for remove thumbnail 73/148873/1
authorMinje Ahn <minje.ahn@samsung.com>
Mon, 11 Sep 2017 05:30:53 +0000 (14:30 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Mon, 11 Sep 2017 05:30:53 +0000 (14:30 +0900)
Use g_dir_open instead of readdir_r

Change-Id: I79a68a14314415b15edb66b339a7747667ccdb5f
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
packaging/libmedia-service.spec
src/common/media-svc-util.c

index 1f7de80..3039c0a 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmedia-service
 Summary:    Media information service library for multimedia applications
-Version: 0.3.17
+Version: 0.3.18
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0 and PD
index 13d249f..8c37e8f 100755 (executable)
@@ -851,41 +851,30 @@ int _media_svc_remove_file(const char *path)
 
 int _media_svc_remove_all_files_in_dir(const char *dir_path)
 {
-       struct dirent entry;
-       struct dirent *result;
-       struct stat st;
        char filename[MEDIA_SVC_PATHNAME_SIZE] = {0, };
-       DIR *dir = NULL;
-
-       dir = opendir(dir_path);
-       if (dir == NULL) {
+       GDir *dir = NULL;
+       GError *error = NULL;
+       const char *name;
+
+       dir = g_dir_open(dir_path, 0, &error);
+       if (dir != NULL && error == NULL) {
+               while ((name = g_dir_read_name(dir))) {
+                       memset(filename, 0, sizeof(filename));
+                       snprintf(filename, sizeof(filename), "%s/%s", dir_path, name);
+
+                       if (g_file_test(filename, G_FILE_TEST_IS_REGULAR)) {
+                               if (unlink(filename) != 0) {
+                                       media_svc_stderror("failed to remove");
+                               }
+                       }
+               }
+       } else {
                media_svc_error("%s is not exist", dir_path);
                return MS_MEDIA_ERR_INVALID_PARAMETER;
        }
 
-       while (!readdir_r(dir, &entry, &result)) {
-               if (result == NULL)
-                       break;
-
-               if (strcmp(entry.d_name, ".") == 0 || strcmp(entry.d_name, "..") == 0)
-                       continue;
-
-               snprintf(filename, sizeof(filename), "%s/%s", dir_path, entry.d_name);
-
-               if (stat(filename, &st) != 0)
-                       continue;
-
-               if (S_ISDIR(st.st_mode))
-                       continue;
-
-               if (unlink(filename) != 0) {
-                       media_svc_stderror("failed to remove");
-                       closedir(dir);
-                       return MS_MEDIA_ERR_INTERNAL;
-               }
-       }
+       g_dir_close(dir);
 
-       closedir(dir);
        return MS_MEDIA_ERR_NONE;
 }