elm/config: fix config usage with EFL_RUN_IN_TREE set

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
This commit is contained in:
Mike Blumenkrantz 2019-07-29 12:41:59 -04:00 committed by Cedric BAIL
parent b561e9632e
commit 36ff0a012c
1 changed files with 28 additions and 7 deletions

View 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;
@ -964,7 +965,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))
@ -973,7 +975,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))
@ -1355,9 +1358,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;
@ -2082,7 +2091,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");
@ -3001,6 +3010,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;
@ -4093,6 +4107,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;
@ -4199,6 +4214,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
@ -4290,8 +4306,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",