discomfitor pushed a commit to branch enlightenment-0.19.

http://git.enlightenment.org/core/enlightenment.git/commit/?id=e7f995294ac677e343a4f159fb4a5363ccf897fb

commit e7f995294ac677e343a4f159fb4a5363ccf897fb
Author: Mike Blumenkrantz <zm...@osg.samsung.com>
Date:   Thu Jan 29 16:01:25 2015 -0500

    ensure no duplicate XDG paths are prepended during startup
    
    the previous patch(es) had a number of issues which made them unsuitable 
for general use:
    
    * only checking "/usr" and "/usr/local" paths, despite this only being 
accurate if e was installed into /usr or /usr/local
    
    * only checking if the paths were at the beginning of the string, when it's 
possible that they could be anywhere
    
    * failure to also check XDG_CONFIG_DIRS
    
    * improper formatting: this is a bit of a nitpick, but there are no correct 
instances of 'strcmp(a, b) == 0' in the e codebase.
---
 src/bin/e_main.c | 33 ++++++++++++++++++++++++++++-----
 1 file changed, 28 insertions(+), 5 deletions(-)

diff --git a/src/bin/e_main.c b/src/bin/e_main.c
index 67570ec..a64a8e6 100644
--- a/src/bin/e_main.c
+++ b/src/bin/e_main.c
@@ -116,6 +116,20 @@ EAPI Eina_Bool e_nopause = EINA_FALSE;
 EINTERN const char *e_first_frame = NULL;
 EINTERN double e_first_frame_start_time = -1;
 
+static Eina_Bool
+_xdg_check_str(const char *env, const char *str)
+{
+   const char *p;
+   size_t len;
+
+   len = strlen(str);
+   for (p = strstr(env, str); p; p++, p = strstr(p, str))
+     {
+        if ((!p[len]) || (p[len] == ':')) return EINA_TRUE;
+     }
+   return EINA_FALSE;
+}
+
 static void
 _xdg_data_dirs_augment(void)
 {
@@ -126,18 +140,27 @@ _xdg_data_dirs_augment(void)
    if (!p) return;
 
    s = getenv("XDG_DATA_DIRS");
-   snprintf(newpath, sizeof(newpath), "%s:%s/share", e_prefix_data_get(), p);
    if (s)
      {
-        if (strncmp(s, newpath, strlen(newpath)))
+        Eina_Bool pfxdata, pfx;
+
+        pfxdata = !_xdg_check_str(s, e_prefix_data_get());
+        snprintf(newpath, sizeof(newpath), "%s/share", p);
+        pfx = !_xdg_check_str(s, newpath);
+        if (pfxdata || pfx)
           {
-             snprintf(buf, sizeof(buf), "%s:%s", newpath, s);
+             snprintf(buf, sizeof(buf), "%s%s%s%s%s",
+               pfxdata ? e_prefix_data_get() : "",
+               pfxdata ? ":" : "",
+               pfx ? newpath : "",
+               pfx ? ":" : "",
+               s);
              e_util_env_set("XDG_DATA_DIRS", buf);
           }
      }
    else
      {
-        snprintf(buf, sizeof(buf), "%s:/usr/local/share:/usr/share", newpath);
+        snprintf(buf, sizeof(buf), "%s:%s/share:/usr/local/share:/usr/share", 
e_prefix_data_get(), p);
         e_util_env_set("XDG_DATA_DIRS", buf);
      }
 
@@ -145,7 +168,7 @@ _xdg_data_dirs_augment(void)
    snprintf(newpath, sizeof(newpath), "%s/etc/xdg", p);
    if (s)
      {
-        if (strncmp(s, newpath, strlen(newpath)))
+        if (!_xdg_check_str(s, newpath))
           {
              snprintf(buf, sizeof(buf), "%s:%s", newpath, s);
              e_util_env_set("XDG_CONFIG_DIRS", buf);

-- 


Reply via email to