davemds pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=762d4fb551529421df2c2b37efdc7d462f3359b6

commit 762d4fb551529421df2c2b37efdc7d462f3359b6
Author: Dave Andreoli <d...@gurumeditation.it>
Date:   Sun Jan 25 12:44:09 2015 +0100

    Efreet: do not get confused by path ending with / in XDG_* vars
    
    This @fix the parsing of dirs from the xdg env vars. Now always remove
    the leading / char from the paths.
    
    This was causing lots of trouble on my system, where XDG_DATA_DIRS is:
    
/usr/local/share/enlightenment:/usr/local/share:/usr/local/share/:/usr/share/
    
    At first /usr/local/share was added 2 times in the list, one with the / and 
one
    witout, causing a double lookup for each file.
    
    Secondly the icon cache was totally unusable as the cached paths ended up
    as: /usr/share//icons/Mint-X/places/32/folder.svg. The double / in there
    was making the cache lookup to fail and anways return the biggest icon
    available. Causing a big system slowdown whe searching for icons.
    
    As a bonus the function now use eina_str_split instead of the custom 
splitting
    code that require a bad special handling for the last item.
---
 src/lib/efreet/efreet_base.c | 35 +++++++++++++++--------------------
 1 file changed, 15 insertions(+), 20 deletions(-)

diff --git a/src/lib/efreet/efreet_base.c b/src/lib/efreet/efreet_base.c
index 3e68187..ba7a7e8 100644
--- a/src/lib/efreet/efreet_base.c
+++ b/src/lib/efreet/efreet_base.c
@@ -379,8 +379,9 @@ efreet_dirs_get(const char *key, const char *fallback)
 {
     Eina_List *dirs = NULL;
     const char *path = NULL;
-    char *s, *p;
-    size_t len;
+    char *s, **split;
+    char sep[2] = {EFREET_PATH_SEP, '\0'};
+    size_t len, i;
 
 #if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
     if (getuid() == geteuid())
@@ -390,13 +391,17 @@ efreet_dirs_get(const char *key, const char *fallback)
 
     if (!path) return dirs;
 
-    len = strlen(path) + 1;
-    s = alloca(len);
-    memcpy(s, path, len);
-    p = strchr(s, EFREET_PATH_SEP);
-    while (p)
+    split = eina_str_split(path, sep, 0);
+    for (i = 0; split[i]; i++)
     {
-        *p = '\0';
+        s = split[i];
+
+        // ensure the dir not end with '/'
+        len = strlen(s);
+        if ((len > 2) && (s[len-1] == '/'))
+            s[len-1] = '\0';
+
+        // add the dir to the list, if not yet there
         if (!eina_list_search_unsorted(dirs, EINA_COMPARE_CB(strcmp), s))
         {
             char *tmp = eina_file_path_sanitize(s);
@@ -406,20 +411,10 @@ efreet_dirs_get(const char *key, const char *fallback)
                 free(tmp);
             }
         }
-
-        s = ++p;
-        p = strchr(s, EFREET_PATH_SEP);
-    }
-    if (!eina_list_search_unsorted(dirs, EINA_COMPARE_CB(strcmp), s))
-    {
-        char *tmp = eina_file_path_sanitize(s);
-        if (tmp)
-        {
-            dirs = eina_list_append(dirs, eina_stringshare_add(tmp));
-            free(tmp);
-        }
     }
 
+    free(split[0]);
+    free(split);
     return dirs;
 }
 

-- 


Reply via email to