From 54a6223d7277d899a4ed0feb620a0f49ad21e8b6 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Fri, 22 Sep 2023 08:23:38 +0000 Subject: [PATCH] config: apply overrides even if there's no file Previously, foot -a test wouldn't actually set the app ID if there was no config file and the defaults were used, which was very counterintuitive. Now, load_config() will carry on until the end, even if there's no config file, so overrides still work. --- CHANGELOG.md | 4 ++++ config.c | 39 +++++++++++++++++---------------------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e894eed..a44ba251 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -76,10 +76,14 @@ `BTN_LEFT+3` by default) ([#1364][1364]). * `file://` prefix from URI's are no longer stripped when opened/activated ([#1474][1474]). +- Command line configuration overrides are now applied even if the + configuration file does not exist or can't be + parsed. ([#1495][1495]). [1391]: https://codeberg.org/dnkl/foot/issues/1391 [1448]: https://codeberg.org/dnkl/foot/pulls/1448 [1474]: https://codeberg.org/dnkl/foot/pulls/1474 +[1495]: https://codeberg.org/dnkl/foot/pulls/1495 ### Deprecated diff --git a/config.c b/config.c index 68dbc679..6ba371e8 100644 --- a/config.c +++ b/config.c @@ -2912,7 +2912,7 @@ config_load(struct config *conf, const char *conf_path, config_override_t *overrides, bool errors_are_fatal, bool as_server) { - bool ret = false; + bool ret = true; enum fcft_capabilities fcft_caps = fcft_capabilities(); *conf = (struct config) { @@ -3106,45 +3106,40 @@ config_load(struct config *conf, const char *conf_path, if (fd < 0) { LOG_AND_NOTIFY_ERRNO("%s: failed to open", conf_path); ret = !errors_are_fatal; - goto out; + } else { + conf_file.path = xstrdup(conf_path); + conf_file.fd = fd; } - - conf_file.path = xstrdup(conf_path); - conf_file.fd = fd; } else { conf_file = open_config(); if (conf_file.fd < 0) { LOG_WARN("no configuration found, using defaults"); ret = !errors_are_fatal; - goto out; } } - xassert(conf_file.path != NULL); - xassert(conf_file.fd >= 0); - LOG_INFO("loading configuration from %s", conf_file.path); + if (conf_file.path && conf_file.fd >= 0) { + LOG_INFO("loading configuration from %s", conf_file.path); - FILE *f = fdopen(conf_file.fd, "r"); - if (f == NULL) { - LOG_AND_NOTIFY_ERRNO("%s: failed to open", conf_file.path); - ret = !errors_are_fatal; - goto out; + FILE *f = fdopen(conf_file.fd, "r"); + if (f == NULL) { + LOG_AND_NOTIFY_ERRNO("%s: failed to open", conf_file.path); + ret = !errors_are_fatal; + } else { + if (!parse_config_file(f, conf, conf_file.path, errors_are_fatal)) + ret = !errors_are_fatal; + + fclose(f); + } } - if (!parse_config_file(f, conf, conf_file.path, errors_are_fatal) || - !config_override_apply(conf, overrides, errors_are_fatal)) - { + if (!config_override_apply(conf, overrides, errors_are_fatal)) ret = !errors_are_fatal; - } else - ret = true; - - fclose(f); conf->colors.use_custom.selection = conf->colors.selection_fg >> 24 == 0 && conf->colors.selection_bg >> 24 == 0; -out: if (ret && conf->fonts[0].count == 0) { struct config_font font; if (!config_font_parse("monospace", &font)) {