From: Jaroslav Kysela Date: Tue, 18 May 2021 10:22:46 +0000 (+0200) Subject: ucm: cfg-save - allow to save the sub-tree including root keys X-Git-Tag: v1.2.5~14 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=0ee4642a693fd2211e05a1e009398c8ebc5dde85;p=alsa-lib.git ucm: cfg-save - allow to save the sub-tree including root keys The leading '+' in the keys specification add the key prefix (sub-tree root identification) to the saved configuration. Signed-off-by: Jaroslav Kysela --- diff --git a/src/conf.c b/src/conf.c index 1a526a2d..5c977266 100644 --- a/src/conf.c +++ b/src/conf.c @@ -1607,8 +1607,8 @@ static int _snd_config_save_children(snd_config_t *config, snd_output_t *out, unsigned int level, unsigned int joins, int array); -static int _snd_config_save_node_value(snd_config_t *n, snd_output_t *out, - unsigned int level) +int _snd_config_save_node_value(snd_config_t *n, snd_output_t *out, + unsigned int level) { int err, array; switch (n->type) { diff --git a/src/ucm/main.c b/src/ucm/main.c index b1536ac3..81bed833 100644 --- a/src/ucm/main.c +++ b/src/ucm/main.c @@ -573,20 +573,27 @@ static int execute_sysw(const char *sysw) return 0; } +int _snd_config_save_node_value(snd_config_t *n, snd_output_t *out, unsigned int level); + static int execute_cfgsave(snd_use_case_mgr_t *uc_mgr, const char *filename) { snd_config_t *config = uc_mgr->local_config; char *file, *root; snd_output_t *out; + bool with_root = false; int err = 0; file = strdup(filename); if (!file) return -ENOMEM; root = strchr(file, ':'); - if (root) { - *root = '\0'; - err = snd_config_search(config, root + 1, &config); + if (config && root) { + *root++ = '\0'; + if (*root == '+') { + with_root = true; + root++; + } + err = snd_config_search(config, root, &config); if (err < 0) { uc_error("Unable to find subtree '%s'", root); goto _err; @@ -598,7 +605,14 @@ static int execute_cfgsave(snd_use_case_mgr_t *uc_mgr, const char *filename) uc_error("unable to open file '%s': %s", file, snd_strerror(err)); goto _err; } - err = snd_config_save(config, out); + if (!config || snd_config_is_empty(config)) + goto _err; + if (with_root) { + snd_output_printf(out, "%s ", root); + err = _snd_config_save_node_value(config, out, 0); + } else { + err = snd_config_save(config, out); + } snd_output_close(out); if (err < 0) { uc_error("unable to save configuration: %s", snd_strerror(err));