From: Jaehwan Kim Date: Thu, 25 Jun 2015 05:04:23 +0000 (+0900) Subject: config: read flush.cfg when elm_config_all_flush is called. X-Git-Tag: submit/tizen/20150811.061834^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bd19cb03daa8340fef70d15c3eb0ad83c8cc3743;p=platform%2Fupstream%2Felementary.git config: read flush.cfg when elm_config_all_flush is called. When elm_config_all_flush is called, another processes should get the config of current process instead of saved base.cfg. so current process save the config to flush.cfg and another processes read it when it is changed. @fix Change-Id: I49c18257dc327662cfca44c9ea82077128e3f519 origin: upstream --- diff --git a/src/lib/elm_config.c b/src/lib/elm_config.c index ecead8fa4..bd674a2ea 100644 --- a/src/lib/elm_config.c +++ b/src/lib/elm_config.c @@ -115,7 +115,6 @@ static void _config_free(Elm_Config *cfg); static void _config_apply(void); static void _config_sub_apply(void); static void _config_update(void); -static void _config_get(void); static void _env_get(void); static void _color_overlays_cancel(void); @@ -1462,13 +1461,53 @@ _config_load(void) } static void -_config_get(void) +_config_flush_load(void) +{ + Elm_Config *cfg = NULL; + Eet_File *ef; + char buf[PATH_MAX]; + + _elm_config_user_dir_snprintf(buf, sizeof(buf), "config/flush.cfg"); + + ef = eet_open(buf, EET_FILE_MODE_READ); + if (ef) + { + cfg = eet_data_read(ef, _config_edd, "config"); + eet_close(ef); + } + + if (cfg) + { + size_t len; + + len = _elm_config_user_dir_snprintf(buf, sizeof(buf), "themes/"); + if (len + 1 < sizeof(buf)) + ecore_file_mkpath(buf); + + _elm_config = cfg; + + if ((_elm_config->config_version >> ELM_CONFIG_VERSION_EPOCH_OFFSET) < ELM_CONFIG_EPOCH) + { + WRN("User's elementary config seems outdated and unusable. Fallback to load system config."); + _config_free(_elm_config); + _elm_config = NULL; + } + else + { + if (_elm_config->config_version < ELM_CONFIG_VERSION) + _config_update(); + } + } +} + +static void +_config_flush_get(void) { _elm_config_font_overlays_cancel(); _color_overlays_cancel(); _config_free(_elm_config); _elm_config = NULL; - _config_load(); + _config_flush_load(); _env_get(); _config_apply(); _config_sub_apply(); @@ -3051,16 +3090,83 @@ elm_config_audio_mute_set(Edje_Channel channel, Eina_Bool mute) EAPI void elm_config_all_flush(void) { - FILE *f; - char buf[PATH_MAX]; + char buf[4096], buf2[4096]; + int ok = 0, ret; + const char *err; + Eet_File *ef; + size_t len; + + len = _elm_config_user_dir_snprintf(buf, sizeof(buf), "themes/"); + if (len + 1 >= sizeof(buf)) + return; + + ok = ecore_file_mkpath(buf); + if (!ok) + { + ERR("Problem accessing Elementary's user configuration directory: %s", + buf); + return; + } + + len = _elm_config_user_dir_snprintf(buf, sizeof(buf), "config"); + if (len + 1 >= sizeof(buf)) + return; + + ok = ecore_file_mkpath(buf); + if (!ok) + { + ERR("Problem accessing Elementary's user configuration directory: %s", + buf); + return; + } + + if (!_elm_config_profile_save()) + return; + + buf[len] = '/'; + len++; + + if (len + sizeof("flush.cfg") >= sizeof(buf) - len) + return; + + memcpy(buf + len, "flush.cfg", sizeof("flush.cfg")); + len += sizeof("flush.cfg") - 1; + + if (len + sizeof(".tmp") >= sizeof(buf)) + return; + + memcpy(buf2, buf, len); + memcpy(buf2 + len, ".tmp", sizeof(".tmp")); + + ef = eet_open(buf2, EET_FILE_MODE_WRITE); + if (!ef) + return; - _elm_config_user_dir_snprintf(buf, sizeof(buf), "config/flush"); - f = fopen(buf, "w+"); - if (f) + ok = eet_data_write(ef, _config_edd, "config", _elm_config, 1); + if (!ok) + goto err; + + err = _elm_config_eet_close_error_get(ef, buf2); + if (err) { - fprintf(f, "flush"); - fclose(f); + ERR("%s", err); + free((void *)err); + goto err; } + + ret = ecore_file_mv(buf2, buf); + if (!ret) + { + ERR("Error saving Elementary's configuration file"); + goto err; + } + + ecore_file_unlink(buf2); + return; + +err: + ecore_file_unlink(buf2); + return; } static void @@ -3122,7 +3228,10 @@ _elm_config_sub_shutdown(void) static Eina_Bool _config_change_delay_cb(void *data EINA_UNUSED) { - _config_get(); + char buf[PATH_MAX]; + + _elm_config_user_dir_snprintf(buf, sizeof(buf), "config/flush.cfg"); + if (ecore_file_exists(buf)) _config_flush_get(); _config_change_delay_timer = NULL; return ECORE_CALLBACK_CANCEL; @@ -3217,7 +3326,7 @@ _elm_config_sub_init(void) int ok = 0; len = _elm_config_user_dir_snprintf(buf, sizeof(buf), "config/"); - if (len + 6 >= sizeof(buf)) // the space to add "flush" + if (len + 10 >= sizeof(buf)) // the space to add "flush.cfg" goto end; ok = ecore_file_mkpath(buf); @@ -3228,18 +3337,9 @@ _elm_config_sub_init(void) goto end; } - strcat(buf, "flush"); - if (!ecore_file_exists(buf)) - { - FILE *f = fopen(buf, "w+"); + strcat(buf, "flush.cfg"); + if (!ecore_file_exists(buf)) elm_config_all_flush(); - if (f) - { - fprintf(f, "flush"); - fclose(f); - goto end; - } - } _eio_monitor = eio_monitor_add(buf); ecore_event_handler_add(EIO_MONITOR_FILE_MODIFIED, _elm_config_file_monitor_cb, NULL);