]> git.alsa-project.org Git - alsa-lib.git/commitdiff
ucm: cfg-save - allow to save the sub-tree including root keys
authorJaroslav Kysela <perex@perex.cz>
Tue, 18 May 2021 10:22:46 +0000 (12:22 +0200)
committerJaroslav Kysela <perex@perex.cz>
Tue, 18 May 2021 10:33:43 +0000 (12:33 +0200)
The leading '+' in the keys specification add the key prefix
(sub-tree root identification) to the saved configuration.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
src/conf.c
src/ucm/main.c

index 1a526a2d62d6b7f967eaa934dca4c04c744c8fb5..5c977266d39a2b0b0fe4688b1b9717bfceadd7c3 100644 (file)
@@ -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) {
index b1536ac350bb837be28cb06ccd5f12acec3e234e..81bed83362e29e3d9c97e4798da902d4b90235b1 100644 (file)
@@ -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));