Skip to content

Commit a172117

Browse files
committed
session client UPDATE do not store duplicates of modules
1 parent 8022722 commit a172117

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

src/session_client.c

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -477,27 +477,31 @@ retrieve_module_data_getschema(const char *name, const char *rev, struct clb_dat
477477
free(model_data);
478478
model_data = NULL;
479479
}
480+
if (!model_data) {
481+
goto cleanup;
482+
}
483+
484+
/* set format */
485+
*format = LYS_IN_YANG;
480486

481487
/* try to store the model_data into local module repository */
482-
if (model_data) {
483-
*format = LYS_IN_YANG;
484-
if (client_opts.schema_searchpath) {
485-
if (asprintf(&localfile, "%s/%s%s%s.yang", client_opts.schema_searchpath, name, rev ? "@" : "",
486-
rev ? rev : "") == -1) {
487-
ERRMEM;
488+
lys_search_localfile(ly_ctx_get_searchdirs(clb_data->session->ctx), 0, name, rev, &localfile, NULL);
489+
if (client_opts.schema_searchpath && !localfile) {
490+
if (asprintf(&localfile, "%s/%s%s%s.yang", client_opts.schema_searchpath, name, rev ? "@" : "",
491+
rev ? rev : "") == -1) {
492+
ERRMEM;
493+
} else {
494+
f = fopen(localfile, "w");
495+
if (!f) {
496+
WRN(clb_data->session, "Unable to store \"%s\" as a local copy of module retrieved via <get-schema> (%s).",
497+
localfile, strerror(errno));
488498
} else {
489-
f = fopen(localfile, "w");
490-
if (!f) {
491-
WRN(clb_data->session, "Unable to store \"%s\" as a local copy of module retrieved via <get-schema> (%s).",
492-
localfile, strerror(errno));
493-
} else {
494-
fputs(model_data, f);
495-
fclose(f);
496-
}
497-
free(localfile);
499+
fputs(model_data, f);
500+
fclose(f);
498501
}
499502
}
500503
}
504+
free(localfile);
501505

502506
cleanup:
503507
lyd_free_tree(envp);

0 commit comments

Comments
 (0)