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;
}