modinfo CHANGE allow different modinfos for diff
But the set of REQ modules must be the same.
@@ -68,19 +68,29 @@ sr_modinfo_diff(struct sr_mod_info_s *src_mod_info, struct sr_mod_info_s *mod_in
{
sr_error_info_t *err_info = NULL;
struct lyd_difflist *ly_diff;
- struct sr_mod_info_mod_s *mod;
+ struct sr_mod_info_mod_s *src_mod, *mod;
struct lyd_node *mod_diff;
- uint16_t i;
+ uint16_t i, j;
assert(!mod_info->diff);
- assert(mod_info->mod_count == src_mod_info->mod_count);
for (i = 0; i < mod_info->mod_count; ++i) {
mod = &mod_info->mods[i];
- assert(mod->ly_mod == src_mod_info->mods[i].ly_mod);
+
+ /* only these modules can be changed */
+ if (mod->state & MOD_INFO_REQ) {
+ /* find the module in the other mod_info */
+ for (j = 0; j < src_mod_info->mod_count; ++j) {
+ src_mod = &src_mod_info->mods[j];
+ if (mod->ly_mod == src_mod->ly_mod) {
+ assert(src_mod->state & MOD_INFO_REQ);
+ break;
+ }
+ }
+ assert(j < src_mod_info->mod_count);
/* get libyang diff */
- ly_diff = lyd_diff(mod->mod_data, src_mod_info->mods[i].mod_data, LYD_DIFFOPT_WITHDEFAULTS);
+ ly_diff = lyd_diff(mod->mod_data, src_mod->mod_data, LYD_DIFFOPT_WITHDEFAULTS);
if (!ly_diff) {
sr_errinfo_new_ly(&err_info, mod_info->conn->ly_ctx);
return err_info;
@@ -95,7 +105,7 @@ sr_modinfo_diff(struct sr_mod_info_s *src_mod_info, struct sr_mod_info_s *mod_in
/* make the source data the new data */
lyd_free_withsiblings(mod->mod_data);
- mod->mod_data = src_mod_info->mods[i].mod_data;
+ mod->mod_data = src_mod->mod_data;
src_mod_info->mods[i].mod_data = NULL;
if (mod_diff) {
@@ -110,6 +120,7 @@ sr_modinfo_diff(struct sr_mod_info_s *src_mod_info, struct sr_mod_info_s *mod_in
}
}
}
+ }
return NULL;
}
