diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-11-23 12:48:07 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2022-11-23 13:19:11 +0100 |
commit | d2cc00310dba05de233ff18d3c830c8638f9bfdf (patch) | |
tree | 5fd5fc6734da0bacad08df7092dd6c6fa6701716 | |
parent | fdc9b6a3841d7346dab6f4aeea06322be0d3ee95 (diff) |
uci: auto-load package in `ctx.foreach()` and `ctx.get_first()`
Functions that use `uci_lookup_ptr()` internally, such as `ctx.get()`,
`ctx.set()` or `ctx.delete()`, implicitly load the given configuration
name while the higher level functions `ctx.foreach()` or `ctx.get_first()`
do not.
This behaviour violates the principle of least surprise and might lead to
non-deterministic program behavior as the outcome of these functions
depends on prior uci operations performed on the cursor.
Fix this issue by invoking `uci_load()` internally in case the given
uci package name cannot be found in the cursor's package cache.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r-- | lib/uci.c | 10 |
1 files changed, 4 insertions, 6 deletions
@@ -346,8 +346,8 @@ uc_uci_get_first(uc_vm_t *vm, size_t nargs) break; } - if (!p) - err_return(UCI_ERR_NOTFOUND); + if (!p && uci_load(*c, ucv_string_get(conf), &p)) + err_return((*c)->err); uci_foreach_element(&p->sections, e) { sc = uci_to_section(e); @@ -917,8 +917,8 @@ uc_uci_foreach(uc_vm_t *vm, size_t nargs) break; } - if (!p) - err_return(UCI_ERR_NOTFOUND); + if (!p && uci_load(*c, ucv_string_get(conf), &p)) + err_return((*c)->err); uci_foreach_element_safe(&p->sections, tmp, e) { sc = uci_to_section(e); @@ -946,8 +946,6 @@ uc_uci_foreach(uc_vm_t *vm, size_t nargs) break; } - /* XXX: rethrow */ - return ucv_boolean_new(ret); } |