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);