summaryrefslogtreecommitdiffhomepage
path: root/libs/uci/luasrc/model
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2008-09-06 13:51:51 +0000
committerSteven Barth <steven@midlink.org>2008-09-06 13:51:51 +0000
commitdbde0216c29148520226a96a57be20ceb2406f45 (patch)
treeb2db4607952c7361f3f4e093e93b126210da0a76 /libs/uci/luasrc/model
parent8e00d27ae72245aa26feebfcf5cc0338ba1167d0 (diff)
Rewrote UCI apply logic
Diffstat (limited to 'libs/uci/luasrc/model')
-rw-r--r--libs/uci/luasrc/model/uci.lua60
1 files changed, 54 insertions, 6 deletions
diff --git a/libs/uci/luasrc/model/uci.lua b/libs/uci/luasrc/model/uci.lua
index 659cd6254..8852d1e5f 100644
--- a/libs/uci/luasrc/model/uci.lua
+++ b/libs/uci/luasrc/model/uci.lua
@@ -54,14 +54,17 @@ end
local Cursor = getmetatable(cursor())
---- Applies the new config
--- @param config UCI config
-function Cursor.apply(self, config)
- local conf = require "luci.config"
- return conf.uci_oncommit[config] and
- os.execute(conf.uci_oncommit[config] .. " >/dev/null 2>&1")
+--- Applies UCI configuration changes
+-- @param configlist List of UCI configurations
+-- @param command Don't apply only return the command
+function Cursor.apply(self, configlist, command)
+ configlist = self:_affected(configlist)
+ local reloadcmd = "/sbin/luci-reload " .. table.concat(configlist, " ")
+
+ return command and reloadcmd or os.execute(reloadcmd .. " >/dev/null 2>&1")
end
+
--- Delete all sections of a given type that match certain criteria.
-- @param config UCI config
-- @param type UCI section type
@@ -180,6 +183,51 @@ function Cursor.changes(self, config)
end
+-- Return a list of initscripts affected by configuration changes.
+function Cursor._affected(self, configlist)
+ configlist = type(configlist) == "table" and configlist or {configlist}
+
+ local c = cursor()
+ c:load("ucitrack")
+
+ -- Resolve dependencies
+ local reloadlist = {}
+
+ local function _resolve_deps(name)
+ local reload = {name}
+ local deps = {}
+
+ c:foreach("ucitrack", name,
+ function(section)
+ if section.affects then
+ for i, aff in ipairs(section.affects) do
+ table.insert(deps, aff)
+ end
+ end
+ end)
+
+ for i, dep in ipairs(deps) do
+ for j, add in ipairs(_resolve_deps(dep)) do
+ table.insert(reload, add)
+ end
+ end
+
+ return reload
+ end
+
+ -- Collect initscripts
+ for j, config in ipairs(configlist) do
+ for i, e in ipairs(_resolve_deps(config)) do
+ if not util.contains(reloadlist, e) then
+ table.insert(reloadlist, e)
+ end
+ end
+ end
+
+ return reloadlist
+end
+
+
--- Add an anonymous section.
-- @class function
-- @name Cursor.add