yanglint BUGFIX handling context search paths
yanglint adds the location of the file to parse as a temporary
searchpath and it is necessary also to check that it is not a
duplication of the already set searchpaths.
In non-interactive mode, there was also a bug when removing this
temporary path since there was used a wrong path index to remove.
diff --git a/tools/lint/commands.c b/tools/lint/commands.c
index d654579..67d6422 100644
--- a/tools/lint/commands.c
+++ b/tools/lint/commands.c
@@ -223,16 +223,23 @@
}
while (path) {
+ int unset_path = 1;
format = get_schema_format(path);
if (format == LYS_IN_UNKNOWN) {
free(path);
goto cleanup;
}
+ /* add temporarily also the path of the module itself */
dir = strdup(path);
- ly_ctx_set_searchdir(ctx, dirname(dir));
+ if (ly_ctx_set_searchdir(ctx, dirname(dir)) == LY_EEXIST) {
+ unset_path = 0;
+ }
+ /* parse the file */
lys_parse_path(ctx, path, format, &model);
- ly_ctx_unset_searchdir(ctx, index);
+ if (unset_path) {
+ ly_ctx_unset_searchdir(ctx, index);
+ }
free(path);
free(dir);
diff --git a/tools/lint/main_ni.c b/tools/lint/main_ni.c
index d7e0626..cf05963 100644
--- a/tools/lint/main_ni.c
+++ b/tools/lint/main_ni.c
@@ -677,7 +677,9 @@
for (u = 0; u < searchpaths->count; u++) {
ly_ctx_set_searchdir(ctx, (const char*)searchpaths->objs[u]);
}
- index = u + 1;
+ /* remember the number of set paths, respectively the first index after the set serchpaths
+ * to know what index is supposed to be removed in case of adding some implicit paths later */
+ index = u;
}
/* derefered setting of verbosity in libyang after context initiation */
@@ -695,13 +697,21 @@
if (informat_s) {
/* load/validate schema */
+ int unset_path = 1;
+
if (verbose >= 2) {
fprintf(stdout, "Validating %s schema file.\n", argv[optind + i]);
}
+
+ /* add temporarily also the path of the module itself */
dir = strdup(argv[optind + i]);
- ly_ctx_set_searchdir(ctx, ptr = dirname(dir));
+ if (ly_ctx_set_searchdir(ctx, ptr = dirname(dir)) == LY_EEXIST) {
+ unset_path = 0;
+ }
lys_parse_path(ctx, argv[optind + i], informat_s, &mod);
- ly_ctx_unset_searchdir(ctx, index);
+ if (unset_path) {
+ ly_ctx_unset_searchdir(ctx, index);
+ }
free(dir);
if (!mod) {
goto cleanup;