pthread_mutex_unlock(&mutex_cancel);
}
-static int find_sub_except_item(const char *item, const char *path)
+static int find_except_item(const char *item, const char *path)
{
- if (strstr(item, path)) {
- _D("Find except item: %s, path: %s", item, path);
- return 0;
- }
+ char *sep;
+ int ret;
+
+ if (!item || !path)
+ return -1;
- return -1;
+ _D("item: %s, path:%s", item, path);
+
+ sep = strchr(item, '/');
+ if (sep)
+ ret = strcmp(item, path);
+ else {
+ if (strstr(path, item))
+ ret = 0;
+ else
+ ret = -1;
+ }
+ _D("result: %d", ret);
+ return ret;
}
-static int remove_dir(const char *path, GList *except)
+static int remove_dir(const char *path)
{
+ DIR *dir;
+ struct dirent *dent;
+ bool bEmpty = true;
+
if (!path)
return -EINVAL;
- if (!except)
- REMOVE(path)
- else if (except && !g_list_find_custom(except, path, (GCompareFunc)find_sub_except_item))
+ dir = opendir(path);
+ if (!dir) {
+ _E("Failed to open dir(%s).", path);
+ return -EINVAL;
+ }
+
+ while((dent = readdir(dir))) {
+ if(strcmp(dent->d_name, ".") == 0 ||
+ strcmp(dent->d_name, "..") == 0)
+ continue;
+
+ bEmpty = false;
+ _D("path (%s) is not empty.", path);
+ }
+
+ if (bEmpty)
REMOVE(path);
return 0;
char sub_path[PATH_MAX] = {0,};
int ret;
- if (except && g_list_find_custom(except, path, (GCompareFunc)strcmp))
+ if (except && g_list_find_custom(except, path, (GCompareFunc)find_except_item))
return 0;
if (is_cleanup_canceled())
}
closedir(dir);
if (!ret && (target == CLEANUP_TARGET_ALL))
- ret = remove_dir(path, except);
+ ret = remove_dir(path);
} else if (target == CLEANUP_TARGET_OLDFILE)
remove_oldfile(path);
else