From: rustyBSD <rustyBSD@gmx.fr>

Subject: [E-devel] [ecore] Recursive rm

I looked at the ecore_file_recursive_rm() function
(in ecore/src/lib/ecore_file/), and I wonder why this
is so ugly/complicated.

We are doing a readlink() and two stat(). Why not simply
do a lstat() ?

It takes less memory and it's simplier. Here is a patch.

(And readlink() is ssize_t)



SVN revision: 77979
This commit is contained in:
rustyBSD 2012-10-15 06:51:39 +00:00 committed by Carsten Haitzler
parent 2499d34087
commit 5c81b6e412
2 changed files with 9 additions and 16 deletions

View File

@ -56,3 +56,4 @@ Seong-ho Cho (DarkCircle) <darkcircle.0426@gmail.com>
Patryk Kaczmarek <patryk.k@samsung.com>
Daniel Willmann <d.willmann@samsung.com>
Michal Pakula vel Rutka <m.pakula@samsung.com>
Maxime Villard <rustyBSD@gmx.fr>

View File

@ -399,21 +399,16 @@ ecore_file_remove(const char *file)
EAPI Eina_Bool
ecore_file_recursive_rm(const char *dir)
{
Eina_Iterator *it;
char buf[PATH_MAX];
struct stat st;
int ret;
if (readlink(dir, buf, sizeof(buf) - 1) > 0)
return ecore_file_unlink(dir);
if (lstat(dir, &st) == -1)
return EINA_FALSE;
ret = stat(dir, &st);
if ((ret == 0) && (S_ISDIR(st.st_mode)))
if (S_ISDIR(st.st_mode))
{
Eina_File_Direct_Info *info;
ret = 1;
if (stat(dir, &st) == -1) return EINA_FALSE; /* WOOT: WHY ARE WE CALLING STAT TWO TIMES ??? */
Eina_Iterator *it;
int ret = 1;
it = eina_file_direct_ls(dir);
EINA_ITERATOR_FOREACH(it, info)
@ -429,11 +424,8 @@ ecore_file_recursive_rm(const char *dir)
else
return EINA_FALSE;
}
else
{
if (ret == -1) return EINA_FALSE;
return ecore_file_unlink(dir);
}
return ecore_file_unlink(dir);
}
static inline Eina_Bool
@ -790,7 +782,7 @@ EAPI char *
ecore_file_readlink(const char *lnk)
{
char buf[PATH_MAX];
int count;
ssize_t count;
if ((count = readlink(lnk, buf, sizeof(buf) - 1)) < 0) return NULL;
buf[count] = 0;