Skip to content
Snippets Groups Projects
Verified Commit 9b4739f5 authored by Karel Koci's avatar Karel Koci :metal:
Browse files

Commit all changes when leaving context

parent adbff4eb
No related branches found
Tags v0.8
No related merge requests found
Pipeline #
......@@ -64,8 +64,20 @@ static PyObject *pyuci_enter(uci_object *self, PyObject *args) {
}
static PyObject *pyuci_exit(uci_object *self, PyObject *args) {
if (self->ctx)
if (self->ctx) {
// Commit all changes
struct uci_ptr ptr;
memset(&ptr, 0, sizeof ptr);
struct uci_element *e, *tmp;
uci_foreach_element_safe(&self->ctx->root, tmp, e) {
struct uci_package *p = uci_to_package(e);
if (ptr.p && (ptr.p != p))
continue;
ptr.p = p;
uci_commit(self->ctx, &p, false);
}
uci_free_context(self->ctx);
}
self->ctx = NULL;
Py_RETURN_NONE;
}
......
......@@ -177,3 +177,17 @@ config testing 'testing'
with uci.Uci(confdir=tmpdir.strpath) as u:
assert u.get('test', 'testing', 'one') == '0'
assert u.get('test', 'testing', 'two') == '1'
def test_context_commit(tmpdir):
"""Test that when we leave context that we commit. This depends on working
test_set.
"""
tmpdir.join('test').write("")
with uci.Uci(confdir=tmpdir.strpath) as u:
u.set('test', 'testing', 'testing')
u.set('test', 'testing', 'one', '0')
u.set('test', 'testing', 'two', '1')
with uci.Uci(confdir=tmpdir.strpath) as u:
assert u.get('test', 'testing', 'one') == '0'
assert u.get('test', 'testing', 'two') == '1'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment