From 762d4fb551529421df2c2b37efdc7d462f3359b6 Mon Sep 17 00:00:00 2001 From: Dave Andreoli Date: Sun, 25 Jan 2015 12:44:09 +0100 Subject: [PATCH] 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 3e681874c7..ba7a7e8225 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; }