Hi,
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.

Am I wrong ?

(And readlink() is ssize_t)
--- ecore_file.c	2012-10-06 13:11:59.884889232 +0200
+++ ecore_file.c	2012-10-06 13:08:24.569905570 +0200
@@ -399,21 +399,16 @@
 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 @@
         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 @@
 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;
------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to