0
0
mirror of https://github.com/Doodle3D/doodle3d-firmware.git synced 2024-12-23 03:23:47 +01:00

Implemented noCommit optimization to reset and resetall

This commit is contained in:
peteruithoven 2013-12-23 20:27:32 +01:00
parent b56a0ed1a9
commit 7de2e2aed0

View File

@ -315,7 +315,7 @@ end
function M.resetAll() function M.resetAll()
log:info("settings:resetAll") log:info("settings:resetAll")
-- delete all uci sections but system -- find all sections
local allSections, msg = uci:get_all(UCI_CONFIG_NAME) local allSections, msg = uci:get_all(UCI_CONFIG_NAME)
if not allSections and msg ~= nil then if not allSections and msg ~= nil then
local errorMSG = "Issue reading all settings: "..utils.dump(msg); local errorMSG = "Issue reading all settings: "..utils.dump(msg);
@ -323,6 +323,7 @@ function M.resetAll()
return nil, errorMSG; return nil, errorMSG;
end end
-- delete all uci sections but system
for key,value in pairs(allSections) do for key,value in pairs(allSections) do
if key ~= "system" and not key:match('^[A-Z_]*$') then --TEMP: skip 'constants', which should be moved anyway if key ~= "system" and not key:match('^[A-Z_]*$') then --TEMP: skip 'constants', which should be moved anyway
local rv, msg = uci:delete(UCI_CONFIG_NAME,key) local rv, msg = uci:delete(UCI_CONFIG_NAME,key)
@ -337,19 +338,19 @@ function M.resetAll()
-- reset all to defaults -- reset all to defaults
for k,_ in pairs(baseconfig) do for k,_ in pairs(baseconfig) do
if not k:match('^[A-Z_]*$') then --TEMP: skip 'constants', which should be moved anyway if not k:match('^[A-Z_]*$') then --TEMP: skip 'constants', which should be moved anyway
M.reset(k) M.reset(k,true)
end end
end end
uci:commit(UCI_CONFIG_NAME) M.commit()
return true return true
end end
--- Reset setting to default value --- Reset setting to default value
-- @string key The key to reset. -- @string key The key to reset.
-- @p[opt=nil] noCommit If true, do not commit the uci configuration; this is more efficient when resetting multiple values
-- @treturn bool|nil True if everything went well, nil in case of error. -- @treturn bool|nil True if everything went well, nil in case of error.
function M.reset(key) function M.reset(key, noCommit)
log:info("settings:reset: "..utils.dump(key)) log:info("settings:reset: "..utils.dump(key))
-- delete -- delete
@ -361,7 +362,6 @@ function M.reset(key)
section = M.get(base.subSection) section = M.get(base.subSection)
end end
local rv, msg = uci:delete(UCI_CONFIG_NAME, section, key) local rv, msg = uci:delete(UCI_CONFIG_NAME, section, key)
log:info(errorMSG)
-- we can't respond to errors in general here because when a key isn't found -- we can't respond to errors in general here because when a key isn't found
-- (which always happens when reset is used in resetall) it will also generate a error -- (which always happens when reset is used in resetall) it will also generate a error
--if not rv and msg ~= nil then --if not rv and msg ~= nil then
@ -371,9 +371,9 @@ function M.reset(key)
--end --end
-- reuse get logic to retrieve default and set it. -- reuse get logic to retrieve default and set it.
M.set(key,M.get(key)) M.set(key,M.get(key),true)
uci:commit(UCI_CONFIG_NAME) if noCommit ~= true then uci:commit(UCI_CONFIG_NAME) end
return true return true
end end