DIR *dir = NULL;
struct dirent *dent;
struct stat fstat;
- char sub_path[PATH_MAX] = {0,};
+ static char sub_path[PATH_MAX] = {0,};
+ static int depth = 0;
int ret;
+ char *ptr;
if (except && g_list_find_custom(except, path, (GCompareFunc)find_except_item))
return 0;
return -EINVAL;
}
- while((dent = readdir(dir))) {
+ if (!depth)
+ strncpy(sub_path, path, sizeof(sub_path) - 1);
+
+ while ((dent = readdir(dir))) {
if(strcmp(dent->d_name, ".") == 0 ||
strcmp(dent->d_name, "..") == 0)
continue;
continue;
}
- snprintf(sub_path, PATH_MAX, "%s/%s", path, dent->d_name);
+ /* attach sub path */
+ snprintf(sub_path + strlen(sub_path), PATH_MAX - strlen(sub_path), "/%s", dent->d_name);
+
+ ++depth;
ret = cleanup_recursive(sub_path, except, (target == CLEANUP_TARGET_OLDFILE)? target: CLEANUP_TARGET_ALL);
+ --depth;
+
+ /* detach sub path */
+ ptr = strrchr(sub_path, '/');
+ if (ptr)
+ *ptr = 0;
+
if (ret != 0)
break;
}