From 60fdb65ee0f5fc30747daa0ee16d2402e02b5be8 Mon Sep 17 00:00:00 2001 From: Colin Baumgarten Date: Mon, 18 Mar 2024 13:41:47 +0100 Subject: [PATCH] cli_auto_edit: Fix data below mountpoint cannot be edited Without this fix, every edit affects the mountpoint destination module directly instead of the same module inside of its mountpoint container. --- apps/cli/cli_auto.c | 18 +++++++++++++++--- apps/cli/cli_show.c | 11 ++++++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/apps/cli/cli_auto.c b/apps/cli/cli_auto.c index 20437052..6b9d9351 100644 --- a/apps/cli/cli_auto.c +++ b/apps/cli/cli_auto.c @@ -119,6 +119,7 @@ cli_auto_edit(clixon_handle h, { int retval = -1; char *api_path_fmt; /* xml key format */ + char *api_path_fmt01 = NULL; char *api_path = NULL; char *treename; pt_head *ph; @@ -177,9 +178,18 @@ cli_auto_edit(clixon_handle h, clixon_err(OE_YANG, EINVAL, "No apipath found"); goto done; } - /* get api-path and xpath */ - if (api_path_fmt2api_path(api_path_fmt, cvv2, yspec0, &api_path, NULL) < 0) - goto done; + if (mtpoint){ + /* Get and combine api-path01 */ + if (mtpoint_paths(yspec0, mtpoint, api_path_fmt, &api_path_fmt01) < 0) + goto done; + if (api_path_fmt2api_path(api_path_fmt01, cvv2, yspec0, &api_path, NULL) < 0) + goto done; + } + else{ + /* get api-path and xpath */ + if (api_path_fmt2api_path(api_path_fmt, cvv2, yspec0, &api_path, NULL) < 0) + goto done; + } /* Store this as edit-mode */ if (clicon_data_set(h, "cli-edit-mode", api_path) < 0) goto done; @@ -204,6 +214,8 @@ cli_auto_edit(clixon_handle h, } retval = 0; done: + if (api_path_fmt01) + free(api_path_fmt01); if (mtpoint2) free(mtpoint2); if (api_path) diff --git a/apps/cli/cli_show.c b/apps/cli/cli_show.c index e10e2063..e22bb939 100644 --- a/apps/cli/cli_show.c +++ b/apps/cli/cli_show.c @@ -1236,8 +1236,7 @@ cli_show_auto_mode(clixon_handle h, if (yang_mount_get(yu, mtpoint, &yspec) < 0) goto done; } - else - yspec = yspec0; + yspec = yspec0; if (api_path2xpath(api_path, yspec, &xpath, &nsc, NULL) < 0) goto done; if (xpath == NULL){ @@ -1249,7 +1248,13 @@ cli_show_auto_mode(clixon_handle h, goto done; } if (mtpoint){ - cprintf(cbxpath, "%s", mtpoint); + /* + * XXX disabled the line below, because otherwise the path up to the + * mount point would be added twice to cbxpath. This is because the + * api_path and thus also the xpath already include the path up to the + * mount point. (at least since cli_auto_edit() was changed) + */ + //cprintf(cbxpath, "%s", mtpoint); if (xml_nsctx_yangspec(yspec0, &nsc0) < 0) goto done; cv = NULL; /* Append cvv1 to cvv2 */