elm/config: fix config usage with EFL_RUN_IN_TREE set
authorMike Blumenkrantz <zmike@samsung.com>
Mon, 29 Jul 2019 16:41:59 +0000 (12:41 -0400)
committerWooHyun Jung <wh0705.jung@samsung.com>
Mon, 5 Aug 2019 01:48:35 +0000 (10:48 +0900)
when running in tree, elm_config should not attempt to access files
outside the tree, nor should it attempt to overwrite any existing config
files

@fix

Reviewed-by: Cedric BAIL <cedric.bail@free.fr>
Differential Revision: https://phab.enlightenment.org/D9433

src/lib/elementary/elm_config.c

index a61db7c..e0b2e00 100644 (file)
@@ -5,6 +5,7 @@
 #include <Elementary.h>
 #include "elm_priv.h"
 
+#include "../../static_libs/buildsystem/buildsystem.h"
 #include "efl_config_global.eo.h"
 
 EAPI int ELM_EVENT_CONFIG_ALL_CHANGED = 0;
@@ -1062,7 +1063,8 @@ _elm_config_profile_dir_get(const char *prof,
    if (!is_user)
      goto not_user;
 
-   _elm_config_user_dir_snprintf(buf, sizeof(buf), "config/%s", prof);
+   if ((!_use_build_config) || (!bs_data_path_get(buf, sizeof(buf), "elementary/config", prof)))
+     _elm_config_user_dir_snprintf(buf, sizeof(buf), "config/%s", prof);
 
    // See elm_config_profile_dir_free: always use strdup+free
    if (ecore_file_is_dir(buf))
@@ -1071,7 +1073,8 @@ _elm_config_profile_dir_get(const char *prof,
    return NULL;
 
 not_user:
-   snprintf(buf, sizeof(buf), "%s/config/%s", _elm_data_dir, prof);
+   if ((!_use_build_config) || (!bs_data_path_get(buf, sizeof(buf), "elementary/config", prof)))
+     snprintf(buf, sizeof(buf), "%s/config/%s", _elm_data_dir, prof);
 
    // See elm_config_profile_dir_free: always use strdup+free
    if (ecore_file_is_dir(buf))
@@ -1457,9 +1460,15 @@ _elm_config_profiles_list(Eina_Bool hide_profiles)
    Eina_Iterator *file_it;
    char buf[PATH_MAX];
    const char *dir;
-   size_t len;
+   size_t len = 0;
 
-   len = _elm_config_user_dir_snprintf(buf, sizeof(buf), "config");
+   if (_use_build_config)
+     {
+        len = bs_data_path_get(buf, sizeof(buf), "elementary", "config");
+        if (len) len = strlen(buf);
+     }
+   if (!len)
+     len = _elm_config_user_dir_snprintf(buf, sizeof(buf), "config");
 
    file_it = eina_file_stat_ls(buf);
    if (!file_it) goto sys;
@@ -2332,7 +2341,7 @@ _elm_config_profile_save(const char *profile)
    Eet_File *ef;
    size_t len;
 
-   if ((s = getenv("ELM_PROFILE_NOSAVE")) && atoi(s))
+   if (_use_build_config || ((s = getenv("ELM_PROFILE_NOSAVE")) && atoi(s)))
      return EINA_TRUE;
 
    len = _elm_config_user_dir_snprintf(buf, sizeof(buf), "config/profile.cfg");
@@ -3311,6 +3320,11 @@ elm_config_profile_exists(const char *profile)
 
    if (!profile) return EINA_FALSE;
 
+   if (_use_build_config)
+     {
+        if (!bs_data_path_get(buf, sizeof(buf), "elementary/config", profile)) return EINA_FALSE;
+        return ecore_file_exists(buf);
+     }
    _elm_config_user_dir_snprintf(buf, sizeof(buf),
                                  "config/%s/base.cfg", profile);
    if (ecore_file_exists(buf)) return EINA_TRUE;
@@ -4443,6 +4457,7 @@ elm_config_all_flush(void)
    int ok = 0;
    size_t len;
 
+   if (_use_build_config) return;
    len = _elm_config_user_dir_snprintf(buf, sizeof(buf), "themes/");
    if (len + 1 >= sizeof(buf))
      return;
@@ -4555,6 +4570,7 @@ _elm_config_sub_shutdown(void)
    ELM_SAFE_FREE(_monitor_file_created_handler, ecore_event_handler_del);
    ELM_SAFE_FREE(_monitor_file_modified_handler, ecore_event_handler_del);
    ELM_SAFE_FREE(_monitor_directory_created_handler, ecore_event_handler_del);
+   _use_build_config = EINA_FALSE;
 }
 
 static Eina_Bool
@@ -4646,8 +4662,13 @@ _elm_config_sub_init(void)
    char buf[PATH_MAX];
    int ok = 0;
 
-   _elm_config_user_dir_snprintf(buf, sizeof(buf), "config");
-   ok = ecore_file_mkpath(buf);
+   if (_use_build_config)
+     ok = bs_data_path_get(buf, sizeof(buf), "elementary", "config");
+   else
+     {
+        _elm_config_user_dir_snprintf(buf, sizeof(buf), "config");
+        ok = ecore_file_mkpath(buf);
+     }
    if (!ok)
      {
         ERR("Problem accessing Elementary's user configuration directory: %s",