cli_auto_up: Partly fix handling of mountpoints

The cli_auto_up command right now does not properly handle
mountpoints.

Fix the case when going up one level inside of a mounted
module.

Note that this does not yet fix the case where the current level
is the top-level of the mounted module. In that case the up command
should switch to the presence container that holds the mounted
module. Instead it switches all the way up to the topmost level, so
it has the same effect as the top command.
This commit is contained in:
Colin Baumgarten 2024-03-18 13:44:03 +01:00 committed by Olof Hagsand
parent c353c6dcab
commit 4b33841858

View file

@ -248,12 +248,14 @@ cli_auto_up(clixon_handle h,
cvec *cvv1 = NULL; /* copy */ cvec *cvv1 = NULL; /* copy */
char *api_path_fmt0; /* from */ char *api_path_fmt0; /* from */
char *api_path_fmt1; /* to */ char *api_path_fmt1; /* to */
char *api_path_fmt2 = NULL; /* 'to' with mountpoint prepended */
char *api_path = NULL; char *api_path = NULL;
int i; int i;
int j; int j;
size_t len; size_t len;
cvec *cvv_filter = NULL; cvec *cvv_filter = NULL;
yang_stmt *yspec0; yang_stmt *yspec0;
char *mtpoint = "";
if (cvec_len(argv) != 1){ if (cvec_len(argv) != 1){
clixon_err(OE_PLUGIN, EINVAL, "Usage: %s(<treename>)", __FUNCTION__); clixon_err(OE_PLUGIN, EINVAL, "Usage: %s(<treename>)", __FUNCTION__);
@ -313,15 +315,26 @@ cli_auto_up(clixon_handle h,
cv = cvec_i(cvv0, i); cv = cvec_i(cvv0, i);
cvec_append_var(cvv1, cv); cvec_append_var(cvv1, cv);
} }
/* get api-path and xpath */ clicon_data_get(h, "cli-edit-mtpoint", &mtpoint);
if (api_path_fmt2api_path(api_path_fmt1, cvv1, yspec0, &api_path, NULL) < 0) if (strlen(mtpoint)) {
goto done; if (mtpoint_paths(yspec0, mtpoint, api_path_fmt1, &api_path_fmt2) < 0)
goto done;
if (api_path_fmt2api_path(api_path_fmt2, cvv1, yspec0, &api_path, NULL) < 0)
goto done;
}
else{
/* get api-path and xpath */
if (api_path_fmt2api_path(api_path_fmt1, cvv1, yspec0, &api_path, NULL) < 0)
goto done;
}
/* Store this as edit-mode */ /* Store this as edit-mode */
clicon_data_set(h, "cli-edit-mode", api_path); clicon_data_set(h, "cli-edit-mode", api_path);
clicon_data_cvec_set(h, "cli-edit-cvv", cvv1); clicon_data_cvec_set(h, "cli-edit-cvv", cvv1);
ok: ok:
retval = 0; retval = 0;
done: done:
if (api_path_fmt2)
free(api_path_fmt2);
if (api_path) if (api_path)
free(api_path); free(api_path);
return retval; return retval;