Report on what changed after a set/match/values.
This commit is contained in:
parent
22bcbb825a
commit
31e703920d
1 changed files with 20 additions and 3 deletions
23
src/uci.lua
23
src/uci.lua
|
@ -197,14 +197,31 @@ function set_value(module)
|
||||||
|
|
||||||
local res
|
local res
|
||||||
if nil ~= p["match"] then
|
if nil ~= p["match"] then
|
||||||
|
local preres = module:ubus_call(conn, "uci", "changes", {config=conf})
|
||||||
|
local prechanges = preres["changes"] or {}
|
||||||
|
|
||||||
local message = {
|
local message = {
|
||||||
config=conf,
|
config=conf,
|
||||||
values=p["values"],
|
values=p["values"],
|
||||||
match=p["match"]
|
match=p["match"]
|
||||||
}
|
}
|
||||||
-- TODO: how can we properly report whether a changed happend in this case?
|
res = module:ubus_call(conn, "uci", "set", message) or {}
|
||||||
-- Get the entire config before and after to compare?
|
|
||||||
res = module:ubus_call(conn, "uci", "set", message)
|
-- Since 'uci changes' returns changes in the order they were made,
|
||||||
|
-- determine what the 'set' command changed by stripping off the
|
||||||
|
-- first #prechanges entries from the postchanges.
|
||||||
|
local postres = module:ubus_call(conn, "uci", "changes", {config=conf})
|
||||||
|
local postchanges = postres["changes"] or {}
|
||||||
|
for i = #prechanges, 1, -1 do
|
||||||
|
table.remove(postchanges, i)
|
||||||
|
end
|
||||||
|
res["changes"] = postchanges
|
||||||
|
|
||||||
|
conn:close()
|
||||||
|
if #postchanges > 0 then
|
||||||
|
module:exit_json({msg="Changes made", changed=true, result=res})
|
||||||
|
end
|
||||||
|
module:exit_json({msg="No changes made", changed=false, result=res})
|
||||||
elseif not sec then
|
elseif not sec then
|
||||||
-- We have to create a section and use "uci add"
|
-- We have to create a section and use "uci add"
|
||||||
if not p["type"] then
|
if not p["type"] then
|
||||||
|
|
Loading…
Add table
Reference in a new issue