From: Jaroslav Kysela Date: Tue, 2 Dec 2025 09:08:58 +0000 (+0100) Subject: ucm: Include directive - add optional behaviour X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=ae921dc1c9430f57c1c4747914ef8fe2c5f87de4;p=alsa-lib.git ucm: Include directive - add optional behaviour It may be useful to skip the include when the file does not exist (make it optional). Signed-off-by: Jaroslav Kysela --- diff --git a/src/ucm/ucm_include.c b/src/ucm/ucm_include.c index e31f2ceb..b155a086 100644 --- a/src/ucm/ucm_include.c +++ b/src/ucm/ucm_include.c @@ -43,7 +43,9 @@ static int include_eval_one(snd_use_case_mgr_t *uc_mgr, snd_config_t **before, snd_config_t **after) { + snd_config_t *opt; const char *file; + bool opt_bool = false; char *s; int err; @@ -72,10 +74,28 @@ static int include_eval_one(snd_use_case_mgr_t *uc_mgr, return -EINVAL; } + err = snd_config_search(inc, "Optional", &opt); + if (err < 0 && err != -ENOENT) { + snd_error(UCM, "optional error"); + return -EINVAL; + } else if (err == 0) { + err = snd_config_get_bool(opt); + if (err < 0) { + snd_error(UCM, "optional format error"); + return -EINVAL; + } + opt_bool = err > 0; + } + err = uc_mgr_get_substituted_value(uc_mgr, &s, file); if (err < 0) return err; - err = uc_mgr_config_load_file(uc_mgr, s, result); + if (opt_bool && access(s, R_OK) != 0) { + snd_trace(UCM, "optional file '%s' not found", s); + err = 0; + } else { + err = uc_mgr_config_load_file(uc_mgr, s, result); + } free(s); return err; }