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.
This commit is contained in:
Davide Andreoli 2015-01-25 12:44:09 +01:00
parent 546d87c8b5
commit 762d4fb551
1 changed files with 15 additions and 20 deletions

View File

@ -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;
}