summaryrefslogtreecommitdiffhomepage
path: root/libs
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2008-08-17 10:20:36 +0000
committerSteven Barth <steven@midlink.org>2008-08-17 10:20:36 +0000
commit75d4cca7ae10a39d9787afd5f1c2f14800491acd (patch)
treed78aa1fec1690510ed723f6c8433f71fda709e28 /libs
parent746fa9df8f3d3443d82cd26d6717e7b5cf3dc8c1 (diff)
Fixed a design flaw in luci.model.uci
Diffstat (limited to 'libs')
-rw-r--r--libs/cbi/luasrc/cbi.lua24
-rw-r--r--libs/uci/luasrc/model/uci.lua49
-rw-r--r--libs/uvl/luasrc/uvl.lua9
3 files changed, 56 insertions, 26 deletions
diff --git a/libs/cbi/luasrc/cbi.lua b/libs/cbi/luasrc/cbi.lua
index bf4bfb80c3..fed53f6ee8 100644
--- a/libs/cbi/luasrc/cbi.lua
+++ b/libs/cbi/luasrc/cbi.lua
@@ -157,7 +157,7 @@ function Map.__init__(self, config, ...)
self.config = config
self.parsechain = {self.config}
self.template = "cbi/map"
- if not uci.load(self.config) then
+ if not uci.load_config(self.config) then
error("Unable to read UCI data: " .. self.config)
end
end
@@ -170,9 +170,16 @@ end
-- Use optimized UCI writing
function Map.parse(self, ...)
+ if self.stateful then
+ uci.load_state(self.config)
+ else
+ uci.load_config(self.config)
+ end
+
Node.parse(self, ...)
+
for i, config in ipairs(self.parsechain) do
- uci.save(config)
+ uci.save_config(config)
end
if luci.http.formvalue("cbi.apply") then
for i, config in ipairs(self.parsechain) do
@@ -182,8 +189,7 @@ function Map.parse(self, ...)
end
-- Refresh data because commit changes section names
- uci.unload(config)
- uci.load(config)
+ uci.load_config(config)
end
-- Reparse sections
@@ -240,11 +246,6 @@ function Map.get(self, section, option)
end
end
--- UCI stateget
-function Map.stateget(self, section, option)
- return uci.get_statevalue(self.config, section, option)
-end
-
--[[
Page - A simple node
@@ -705,7 +706,6 @@ function AbstractValue.__init__(self, map, option, ...)
self.default = nil
self.size = nil
self.optional = false
- self.stateful = false
end
-- Add a dependencie to another section field
@@ -789,9 +789,7 @@ end
-- Return the UCI value of this object
function AbstractValue.cfgvalue(self, section)
- return self.stateful
- and self.map:stateget(section, self.option)
- or self.map:get(section, self.option)
+ return self.map:get(section, self.option)
end
-- Validate the form value
diff --git a/libs/uci/luasrc/model/uci.lua b/libs/uci/luasrc/model/uci.lua
index 665866e682..dd7a48ab6c 100644
--- a/libs/uci/luasrc/model/uci.lua
+++ b/libs/uci/luasrc/model/uci.lua
@@ -79,15 +79,46 @@ function section(config, type, name, values)
return stat and name
end
---- Get a certain state value.
--- @param ... Parameters passed to function get
--- @return UCI value
--- @see get
-function get_statevalue(...)
+--- Savely load the configuration.
+-- @param config Configuration to load
+-- @return Sucess status
+-- @see load_state
+-- @see load
+function load_config(...)
+ set_confdir(confdir_default)
+ set_savedir(savedir_default)
+ return load(...)
+end
+
+--- Savely load state values.
+-- @param config Configuration to load
+-- @return Sucess status
+-- @see load_config
+-- @see load
+function load_state(config)
+ set_confdir(confdir_default)
set_savedir(savedir_state)
- local result = get(...)
+ return load(config)
+end
+
+--- Save changes to config values.
+-- @param config Configuration to save
+-- @return Sucess status
+-- @see save_state
+-- @see save
+function save_config(config)
set_savedir(savedir_default)
- return result
+ return save(config)
+end
+
+--- Save changes to state values.
+-- @param config Configuration to save
+-- @return Sucess status
+-- @see save_config
+-- @see save
+function save_state(config)
+ set_savedir(savedir_state)
+ return save(config)
end
--- Updated the data of a section using data from a table.
@@ -157,10 +188,13 @@ end
-- @return Table of UCI sections or table of UCI values
--- Manually load a config.
+-- Warning: This function is unsave! You should use load_config or load_state if possible.
-- @class function
-- @name load
-- @param config UCI config
-- @return Boolean whether operation succeeded
+-- @see load_config
+-- @see load_state
-- @see save
-- @see unload
@@ -180,6 +214,7 @@ end
-- @see unload
--- Set a value or create a named section.
+-- Warning: This function is unsave! You should use save_config or save_state if possible.
-- @class function
-- @name set
-- @param config UCI config
diff --git a/libs/uvl/luasrc/uvl.lua b/libs/uvl/luasrc/uvl.lua
index 0e32dc1e23..33ee79b79b 100644
--- a/libs/uvl/luasrc/uvl.lua
+++ b/libs/uvl/luasrc/uvl.lua
@@ -69,8 +69,7 @@ end
-- @return String containing the reason for errors (if any)
function UVL.validate( self, config )
- self.uci.set_confdir( self.uci.confdir_default )
- self.uci.load( config )
+ self.uci.load_config( config )
self.beenthere = { }
local co = self.uci.get_all( config )
@@ -109,8 +108,7 @@ function UVL.validate( self, config )
end
function UVL.validate_section( self, config, section )
- self.uci.set_confdir( self.uci.confdir_default )
- self.uci.load( config )
+ self.uci.load_config( config )
self.beenthere = { }
local co = self.uci.get_all( config )
@@ -125,8 +123,7 @@ function UVL.validate_section( self, config, section )
end
function UVL.validate_option( self, config, section, option )
- self.uci.set_confdir( self.uci.confdir_default )
- self.uci.load( config )
+ self.uci.load_config( config )
self.beenthere = { }
local co = self.uci.get_all( config )