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.
This commit is contained in:
Colin Baumgarten 2024-03-18 13:41:47 +01:00 committed by Olof Hagsand
parent 34fff6c270
commit 60fdb65ee0
2 changed files with 23 additions and 6 deletions

View file

@ -119,6 +119,7 @@ cli_auto_edit(clixon_handle h,
{ {
int retval = -1; int retval = -1;
char *api_path_fmt; /* xml key format */ char *api_path_fmt; /* xml key format */
char *api_path_fmt01 = NULL;
char *api_path = NULL; char *api_path = NULL;
char *treename; char *treename;
pt_head *ph; pt_head *ph;
@ -177,9 +178,18 @@ cli_auto_edit(clixon_handle h,
clixon_err(OE_YANG, EINVAL, "No apipath found"); clixon_err(OE_YANG, EINVAL, "No apipath found");
goto done; goto done;
} }
/* get api-path and xpath */ if (mtpoint){
if (api_path_fmt2api_path(api_path_fmt, cvv2, yspec0, &api_path, NULL) < 0) /* Get and combine api-path01 */
goto done; 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 */ /* Store this as edit-mode */
if (clicon_data_set(h, "cli-edit-mode", api_path) < 0) if (clicon_data_set(h, "cli-edit-mode", api_path) < 0)
goto done; goto done;
@ -204,6 +214,8 @@ cli_auto_edit(clixon_handle h,
} }
retval = 0; retval = 0;
done: done:
if (api_path_fmt01)
free(api_path_fmt01);
if (mtpoint2) if (mtpoint2)
free(mtpoint2); free(mtpoint2);
if (api_path) if (api_path)

View file

@ -1236,8 +1236,7 @@ cli_show_auto_mode(clixon_handle h,
if (yang_mount_get(yu, mtpoint, &yspec) < 0) if (yang_mount_get(yu, mtpoint, &yspec) < 0)
goto done; goto done;
} }
else yspec = yspec0;
yspec = yspec0;
if (api_path2xpath(api_path, yspec, &xpath, &nsc, NULL) < 0) if (api_path2xpath(api_path, yspec, &xpath, &nsc, NULL) < 0)
goto done; goto done;
if (xpath == NULL){ if (xpath == NULL){
@ -1249,7 +1248,13 @@ cli_show_auto_mode(clixon_handle h,
goto done; goto done;
} }
if (mtpoint){ 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) if (xml_nsctx_yangspec(yspec0, &nsc0) < 0)
goto done; goto done;
cv = NULL; /* Append cvv1 to cvv2 */ cv = NULL; /* Append cvv1 to cvv2 */