session client UPDATE do not store duplicates of modules
@@ -477,11 +477,16 @@ retrieve_module_data_getschema(const char *name, const char *rev, struct clb_dat
free(model_data);
model_data = NULL;
}
+ if (!model_data) {
+ goto cleanup;
+ }
- /* try to store the model_data into local module repository */
- if (model_data) {
+ /* set format */
*format = LYS_IN_YANG;
- if (client_opts.schema_searchpath) {
+
+ /* try to store the model_data into local module repository */
+ lys_search_localfile(ly_ctx_get_searchdirs(clb_data->session->ctx), 0, name, rev, &localfile, NULL);
+ if (client_opts.schema_searchpath && !localfile) {
if (asprintf(&localfile, "%s/%s%s%s.yang", client_opts.schema_searchpath, name, rev ? "@" : "",
rev ? rev : "") == -1) {
ERRMEM;
@@ -494,10 +499,9 @@ retrieve_module_data_getschema(const char *name, const char *rev, struct clb_dat
fputs(model_data, f);
fclose(f);
}
- free(localfile);
- }
}
}
+ free(localfile);
cleanup:
lyd_free_tree(envp);
