[PATCH uci] uci: decrease the n_section when section is freed
Jan Venekamp
jan at venekamp.net
Thu Sep 7 09:12:56 PDT 2023
When working on 16e8a3b1 [1] I looked at anonymous sections and
uci_fixup_section too. It seemed rather hairy to me, but I decided then
to leave it as is.
> The package n_section counter increases when a section is allocated
> but does not decrease when a section is freed.
I suspect this is by design. Find attached a test case that your
patch does not pass.
> Since the anonymous section name is comprised of the section counter,
> if the package is not reloaded, an incorrect count will result in
> operating on the wrong section.
Could you provided a example / test case for this behaviour?
Kind regards,
Jan Venekamp
[1] https://git.openwrt.org/?p=project/uci.git;a=commitdiff;h=16e8a3b1
---
.../references/batch_anonymous_section.result | 7 +++++++
tests/shunit2/tests.d/060_batch | 17 +++++++++++++++++
2 files changed, 24 insertions(+)
create mode 100644 tests/shunit2/references/batch_anonymous_section.result
diff --git a/tests/shunit2/references/batch_anonymous_section.result b/tests/shunit2/references/batch_anonymous_section.result
new file mode 100644
index 0000000..fe000a1
--- /dev/null
+++ b/tests/shunit2/references/batch_anonymous_section.result
@@ -0,0 +1,7 @@
+
+config foo
+ option bar '1'
+
+config foo
+ option bar '2'
+
diff --git a/tests/shunit2/tests.d/060_batch b/tests/shunit2/tests.d/060_batch
index 40f473b..4aa3047 100644
--- a/tests/shunit2/tests.d/060_batch
+++ b/tests/shunit2/tests.d/060_batch
@@ -41,3 +41,20 @@ EOF
assertSameFile "${REF_DIR}/batch_comments.result" "${CONFIG_DIR}/batch_comments"
}
+
+test_batch_anonymous_section()
+{
+ touch ${CONFIG_DIR}/batch_anonymous_section
+
+ ${UCI} batch <<EOF
+add batch_anonymous_section foo
+set batch_anonymous_section. at foo[-1].bar='0'
+add batch_anonymous_section foo
+set batch_anonymous_section. at foo[-1].bar='1'
+del batch_anonymous_section. at foo[0]
+add batch_anonymous_section foo
+set batch_anonymous_section. at foo[-1].bar='2'
+EOF
+ ${UCI} commit
+ assertSameFile "${REF_DIR}/batch_anonymous_section.result" "${CONFIG_DIR}/batch_anonymous_section"
+}
--
2.32.0 (Apple Git-132)
More information about the openwrt-devel
mailing list