diff --git a/legacy/ecore/src/lib/ecore_file/Ecore_File.h b/legacy/ecore/src/lib/ecore_file/Ecore_File.h index 04e395849e..34fc8e7151 100644 --- a/legacy/ecore/src/lib/ecore_file/Ecore_File.h +++ b/legacy/ecore/src/lib/ecore_file/Ecore_File.h @@ -48,26 +48,27 @@ extern "C" { } Ecore_File_Event; - EAPI int ecore_file_init (void); - EAPI int ecore_file_shutdown (void); - EAPI time_t ecore_file_mod_time (const char *file); - EAPI int ecore_file_exists (const char *file); - EAPI int ecore_file_is_dir (const char *file); - EAPI int ecore_file_mkdir (const char *dir); - EAPI int ecore_file_rmdir (const char *dir); - EAPI int ecore_file_mkpath (const char *path); - EAPI int ecore_file_cp (const char *src, const char *dst); - EAPI int ecore_file_mv (const char *src, const char *dst); - EAPI char *ecore_file_realpath (const char *file); - EAPI int ecore_file_unlink (const char *file); - EAPI char *ecore_file_get_file (char *path); - EAPI char *ecore_file_get_dir (char *path); + EAPI int ecore_file_init (void); + EAPI int ecore_file_shutdown (void); + EAPI time_t ecore_file_mod_time (const char *file); + EAPI int ecore_file_exists (const char *file); + EAPI int ecore_file_is_dir (const char *file); + EAPI int ecore_file_mkdir (const char *dir); + EAPI int ecore_file_rmdir (const char *dir); + EAPI int ecore_file_recursive_rm (const char *dir); + EAPI int ecore_file_mkpath (const char *path); + EAPI int ecore_file_cp (const char *src, const char *dst); + EAPI int ecore_file_mv (const char *src, const char *dst); + EAPI char *ecore_file_realpath (const char *file); + EAPI int ecore_file_unlink (const char *file); + EAPI char *ecore_file_get_file (char *path); + EAPI char *ecore_file_get_dir (char *path); - EAPI int ecore_file_can_exec (const char *file); - EAPI char *ecore_file_readlink (const char *link); - EAPI Ecore_List *ecore_file_ls (const char *dir); - EAPI char *ecore_file_app_exe_get (const char *app); - EAPI char *ecore_file_strip_ext (const char *file); + EAPI int ecore_file_can_exec (const char *file); + EAPI char *ecore_file_readlink (const char *link); + EAPI Ecore_List *ecore_file_ls (const char *dir); + EAPI char *ecore_file_app_exe_get (const char *app); + EAPI char *ecore_file_strip_ext (const char *file); EAPI Ecore_File_Monitor *ecore_file_monitor_add(const char *path, void (*func) (void *data, diff --git a/legacy/ecore/src/lib/ecore_file/ecore_file.c b/legacy/ecore/src/lib/ecore_file/ecore_file.c index 846e867d56..a992ba0c54 100644 --- a/legacy/ecore/src/lib/ecore_file/ecore_file.c +++ b/legacy/ecore/src/lib/ecore_file/ecore_file.c @@ -4,6 +4,7 @@ #include "ecore_file_private.h" #include + static int init = 0; /* externally accessible functions */ @@ -93,6 +94,47 @@ ecore_file_unlink(const char *file) return 1; } +int +ecore_file_recursive_rm(const char *dir) +{ + DIR *dirp; + struct dirent *dp; + Ecore_List *list; + int ret; + + ret = 0; + dirp = opendir(dir); + if (!dirp) return ret; + + while ((dp = readdir(dirp))) + { + if ((strcmp(dp->d_name, ".")) && (strcmp(dp->d_name, ".."))) + { + char path[PATH_MAX]; + struct stat st; + + snprintf(path, PATH_MAX, "%s/%s", dir, dp->d_name); + if (stat(path, &st) == -1) { ret = 0; continue; } + + if(S_ISDIR(st.st_mode)) + { + ecore_file_recursive_rm(path); + ecore_file_rmdir(path); + } + else if(S_ISREG(st.st_mode)||S_ISLNK(st.st_mode)) + { + ecore_file_unlink(path); + } + } + } + closedir(dirp); + + if(ecore_file_rmdir(dir)) + ret = 1; + + return ret; +} + int ecore_file_mkpath(const char *path) {