Use maapi_copy_tree function failed


I want to use maapi_copy_tree(int sock, int thandle, const char *from, const char *tofmt, …) to copy a list to another list under the same subtree.

I want copy /path/to/a/list{1}/ to /path/to/a/list{2}/

so, from is “/path/to/a/list{1}/”, tofmt is “/path/to/a/list{2}/”
maapi_copy_tree(sock, handle, “/path/to/a/list{1}/”, “/path/to/a/list{2}/”);

list{1} already exists, but list{2} is not.

when I use maapi_copy_tree, there have been the error " badly formatted or nonexistent path"

Am I giving a wrong path? could you please help me with this issue?

…well, according to error message, most probably :slight_smile:

double check that you have your paths correct, that your source tree really exists, etc.

Without specific small example with concrete YANG model and keypaths/cdb state, it’s hard to guess… (maybe some small extension to existing confd.example to preproduce problem?)

One thing you can try it to pre-create list entry {2} with maapi_create() and see if copy works after… (should not be necessary according to API info, but worth testing)

Also, verify that you don’t have some must/when statements in model that prevent you from creating such copy, and could lead to this note from maapi_copy_tree()'s manual pages:

If a data model mismatch is detected, e.g. an existing data node in the
source tree does not exist in the destination data model, or an existing leaf in the source tree
has a value that is incompatible with the type of the leaf in the destination data model,
maapi_copy_tree() will return CONFD_ERR with confd_errno set to CONFD_ERR_BADPATH.

I’m not sure if applicable for your use-case, but error code is (maybe just coincidence) the one that you encountered…