context CHANGE avoid error messages when searching for latest revision import
When searching for the latest revision import (import without explicit
revision) and the context already contains some revision of the required
module, libyang searches for the latest revision in the searchpatchs and
via callback. In the case no revision of the module found in the
searchpaths, an error message was printed despite libyang actually has a
revision of the module in the context and it is going to use it (and
actually mark it as the latest available revision).
So this patch avoids such an error message in this particular case.
diff --git a/src/tree_schema_helpers.c b/src/tree_schema_helpers.c
index dfe563a..ddc2d3a 100644
--- a/src/tree_schema_helpers.c
+++ b/src/tree_schema_helpers.c
@@ -749,7 +749,7 @@
LY_ERR
lys_module_localfile(struct ly_ctx *ctx, const char *name, const char *revision, int implement,
- struct lys_parser_ctx *main_ctx, const char *main_name, void **result)
+ struct lys_parser_ctx *main_ctx, const char *main_name, int required, void **result)
{
int fd;
char *filepath = NULL;
@@ -762,9 +762,8 @@
LY_CHECK_RET(lys_search_localfile(ly_ctx_get_searchdirs(ctx), !(ctx->flags & LY_CTX_DISABLE_SEARCHDIR_CWD), name, revision,
&filepath, &format));
- LY_CHECK_ERR_RET(!filepath, LOGERR(ctx, LY_ENOTFOUND, "Data model \"%s%s%s\" not found in local searchdirs.",
- name, revision ? "@" : "", revision ? revision : ""), LY_ENOTFOUND);
-
+ LY_CHECK_ERR_RET(!filepath, if (required) {LOGERR(ctx, LY_ENOTFOUND, "Data model \"%s%s%s\" not found in local searchdirs.",
+ name, revision ? "@" : "", revision ? revision : "");}, LY_ENOTFOUND);
LOGVRB("Loading schema from \"%s\" file.", filepath);
@@ -875,7 +874,7 @@
search_file:
if (!(ctx->flags & LY_CTX_DISABLE_SEARCHDIRS)) {
/* module was not received from the callback or there is no callback set */
- lys_module_localfile(ctx, name, revision, implement, NULL, NULL, (void **)mod);
+ lys_module_localfile(ctx, name, revision, implement, NULL, NULL, m ? 0 : 1, (void **)mod);
}
if (!(*mod) && (ctx->flags & LY_CTX_PREFER_SEARCHDIRS)) {
goto search_clb;
@@ -885,6 +884,7 @@
/* update the latest_revision flag - here we have selected the latest available schema,
* consider that even the callback provides correct latest revision */
if (!(*mod) && m) {
+ LOGVRB("Newer revision than %s-%s not found, using this as the latest revision.", m->name, m->revision);
m->latest_revision = 2;
*mod = m;
} else if ((*mod) && !revision && ((*mod)->latest_revision == 1)) {
@@ -990,7 +990,7 @@
search_file:
if (!(ctx->ctx->flags & LY_CTX_DISABLE_SEARCHDIRS)) {
/* submodule was not received from the callback or there is no callback set */
- lys_module_localfile(ctx->ctx, inc->name, inc->rev[0] ? inc->rev : NULL, 0, ctx, mod->mod->name, (void**)&submod);
+ lys_module_localfile(ctx->ctx, inc->name, inc->rev[0] ? inc->rev : NULL, 0, ctx, mod->mod->name, 1, (void**)&submod);
}
if (!submod && (ctx->ctx->flags & LY_CTX_PREFER_SEARCHDIRS)) {
goto search_clb;