Skip to content

Commit b13a224

Browse files
committed
session client UPDATE ignore modules without revision
... when searching for a module in a specific revision. Fixes #445
1 parent 6f86598 commit b13a224

File tree

1 file changed

+42
-32
lines changed

1 file changed

+42
-32
lines changed

src/session_client.c

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -354,51 +354,61 @@ static char *
354354
retrieve_module_data_localfile(const char *name, const char *rev, struct clb_data_s *clb_data,
355355
LYS_INFORMAT *format)
356356
{
357-
char *localfile = NULL;
357+
char *localfile = NULL, *model_data = NULL;
358+
const char *ptr;
358359
FILE *f;
359360
long length, l;
360-
char *model_data = NULL;
361361

362362
if (lys_search_localfile(ly_ctx_get_searchdirs(clb_data->session->ctx),
363363
!(ly_ctx_get_options(clb_data->session->ctx) & LY_CTX_DISABLE_SEARCHDIR_CWD),
364364
name, rev, &localfile, format)) {
365365
return NULL;
366366
}
367-
if (localfile) {
368-
VRB(clb_data->session, "Reading module \"%s@%s\" from local file \"%s\".", name, rev ? rev : "<latest>",
369-
localfile);
370-
f = fopen(localfile, "r");
371-
if (!f) {
372-
ERR(clb_data->session, "Unable to open file \"%s\" (%s).", localfile, strerror(errno));
373-
free(localfile);
374-
return NULL;
367+
if (localfile && rev) {
368+
ptr = strrchr(localfile, '/');
369+
if (!strchr(ptr, '@')) {
370+
/* we do not know the revision of the module and we require a specific one, so ignore this module */
371+
localfile = NULL;
375372
}
373+
}
376374

377-
fseek(f, 0, SEEK_END);
378-
length = ftell(f);
379-
if (length < 0) {
380-
ERR(clb_data->session, "Unable to get the size of module file \"%s\".", localfile);
381-
free(localfile);
382-
fclose(f);
383-
return NULL;
384-
}
385-
fseek(f, 0, SEEK_SET);
375+
if (!localfile) {
376+
return NULL;
377+
}
386378

387-
model_data = malloc(length + 1);
388-
if (!model_data) {
389-
ERRMEM;
390-
} else if ((l = fread(model_data, 1, length, f)) != length) {
391-
ERR(clb_data->session, "Reading module from \"%s\" failed (%d bytes read, but %d expected).", localfile, l,
392-
length);
393-
free(model_data);
394-
model_data = NULL;
395-
} else {
396-
/* terminating NULL byte */
397-
model_data[length] = '\0';
398-
}
399-
fclose(f);
379+
VRB(clb_data->session, "Reading module \"%s@%s\" from local file \"%s\".", name, rev ? rev : "<latest>",
380+
localfile);
381+
f = fopen(localfile, "r");
382+
if (!f) {
383+
ERR(clb_data->session, "Unable to open file \"%s\" (%s).", localfile, strerror(errno));
384+
free(localfile);
385+
return NULL;
386+
}
387+
388+
fseek(f, 0, SEEK_END);
389+
length = ftell(f);
390+
if (length < 0) {
391+
ERR(clb_data->session, "Unable to get the size of module file \"%s\".", localfile);
400392
free(localfile);
393+
fclose(f);
394+
return NULL;
395+
}
396+
fseek(f, 0, SEEK_SET);
397+
398+
model_data = malloc(length + 1);
399+
if (!model_data) {
400+
ERRMEM;
401+
} else if ((l = fread(model_data, 1, length, f)) != length) {
402+
ERR(clb_data->session, "Reading module from \"%s\" failed (%d bytes read, but %d expected).", localfile, l,
403+
length);
404+
free(model_data);
405+
model_data = NULL;
406+
} else {
407+
/* terminating NULL byte */
408+
model_data[length] = '\0';
401409
}
410+
fclose(f);
411+
free(localfile);
402412

403413
return model_data;
404414
}

0 commit comments

Comments
 (0)