Skip to content

Commit dbd3a3b

Browse files
committed
tree schema UPDATE improve latest_revision of submodules
1 parent e86acad commit dbd3a3b

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

src/tree_schema.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,7 +1539,8 @@ lysp_load_module_data_check(const struct ly_ctx *ctx, struct lysp_module *mod, s
15391539

15401540
LY_ERR
15411541
lys_parse_submodule(struct ly_ctx *ctx, struct ly_in *in, LYS_INFORMAT format, struct lysp_ctx *main_ctx,
1542-
const struct lysp_load_module_data *mod_data, struct ly_set *new_mods, struct lysp_submodule **submodule)
1542+
const struct lysp_load_module_data *mod_data, ly_bool in_searchdirs, struct ly_set *new_mods,
1543+
struct lysp_submodule **submodule)
15431544
{
15441545
LY_ERR rc = LY_SUCCESS, r;
15451546
struct lysp_submodule *submod = NULL, *latest_sp;
@@ -1590,7 +1591,9 @@ lys_parse_submodule(struct ly_ctx *ctx, struct ly_in *in, LYS_INFORMAT format, s
15901591
latest_sp = NULL;
15911592
}
15921593
} else {
1593-
submod->latest_revision = 1;
1594+
/* if found in searchdirs and looking for the latest revision, it is the latest revision available,
1595+
* otherwise the only such submodule in the context */
1596+
submod->latest_revision = (in_searchdirs && !mod_data->revision) ? 2 : 1;
15941597
}
15951598

15961599
/* check the parsed submodule is as expected */

src/tree_schema_common.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ lys_parse_localfile(struct ly_ctx *ctx, const char *name, const char *revision,
732732
mod_data.path = filepath;
733733
mod_data.submoduleof = main_name;
734734
if (main_ctx) {
735-
ret = lys_parse_submodule(ctx, in, format, main_ctx, &mod_data, new_mods, (struct lysp_submodule **)&mod);
735+
ret = lys_parse_submodule(ctx, in, format, main_ctx, &mod_data, 1, new_mods, (struct lysp_submodule **)&mod);
736736
} else {
737737
ret = lys_parse_in(ctx, in, format, &mod_data, new_mods, (struct lys_module **)&mod);
738738

@@ -1166,7 +1166,7 @@ lysp_load_submod_from_clb_or_file(struct lysp_ctx *pctx, const char *name, const
11661166
mod_data.name = name;
11671167
mod_data.revision = revision;
11681168
mod_data.submoduleof = PARSER_CUR_PMOD(pctx)->mod->name;
1169-
r = lys_parse_submodule(ctx, in, format, pctx->main_ctx, &mod_data, new_mods, submod);
1169+
r = lys_parse_submodule(ctx, in, format, pctx->main_ctx, &mod_data, 0, new_mods, submod);
11701170
ly_in_free(in, 0);
11711171
if (submodule_data_free) {
11721172
submodule_data_free((void *)submodule_data, ctx->imp_clb_data);
@@ -1188,12 +1188,6 @@ lysp_load_submod_from_clb_or_file(struct lysp_ctx *pctx, const char *name, const
11881188
return LY_ENOTFOUND;
11891189
}
11901190

1191-
if (!revision && ((*submod)->latest_revision == 1)) {
1192-
/* update the latest_revision flag - here we have selected the latest available schema,
1193-
* consider that even the callback provides correct latest revision */
1194-
(*submod)->latest_revision = 2;
1195-
}
1196-
11971191
return LY_SUCCESS;
11981192
}
11991193

@@ -1220,12 +1214,21 @@ lysp_load_submodules(struct lysp_ctx *pctx, struct lysp_module *pmod, struct ly_
12201214
submod_included = 0;
12211215
} else if (r) {
12221216
return r;
1217+
} else if (inc->submodule->latest_revision == 2) {
1218+
/* submodule found and is the latest existing revision */
1219+
continue;
12231220
}
12241221
}
12251222

12261223
/* try to use currently parsed submodule */
12271224
r = lysp_parsed_mods_get_submodule(pctx, inc);
1228-
LY_CHECK_RET(r != LY_ENOT, r);
1225+
if (r && (r != LY_ENOT)) {
1226+
return r;
1227+
} else if (!r && ((inc->submodule->latest_revision == 2) || inc->submodule->parsing)) {
1228+
/* use the module if we already have its latest revision or if it is being parsed, we have to stop looking
1229+
* recursively for latest revisions at some point to prevent infinite recursion */
1230+
continue;
1231+
}
12291232

12301233
/* try to load the submodule */
12311234
LY_CHECK_RET(lysp_load_submod_from_clb_or_file(pctx, inc->name, inc->rev[0] ? inc->rev : NULL, new_mods, &submod));

src/tree_schema_internal.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,12 +561,14 @@ LY_ERR lys_parse_in(struct ly_ctx *ctx, struct ly_in *in, LYS_INFORMAT format,
561561
* @param[in] format Format of the input data (YANG or YIN).
562562
* @param[in] main_ctx Parser context of the main module.
563563
* @param[in] mod_data Optional expected module data to check.
564+
* @param[in] in_searchdirs Whether the submodule was found in the searchdirs.
564565
* @param[in] new_mods Set of all the new mods added to the context. Includes this module and all of its imports.
565-
* @param[out] submodule Parsed submodule.
566+
* @param[out] submodule Parsed submodule, may be NULL even on success if an adequate submodule has already been parsed.
566567
* @return LY_ERR value.
567568
*/
568569
LY_ERR lys_parse_submodule(struct ly_ctx *ctx, struct ly_in *in, LYS_INFORMAT format, struct lysp_ctx *main_ctx,
569-
const struct lysp_load_module_data *mod_data, struct ly_set *new_mods, struct lysp_submodule **submodule);
570+
const struct lysp_load_module_data *mod_data, ly_bool in_searchdirs, struct ly_set *new_mods,
571+
struct lysp_submodule **submodule);
570572

571573
/**
572574
* @brief Fill filepath value if available in input handler @p in

0 commit comments

Comments
 (0)