mirror of
https://github.com/Doodle3D/doodle3d-firmware.git
synced 2024-12-22 11:03:48 +01:00
Implemented noCommit optimization to reset and resetall
This commit is contained in:
parent
b56a0ed1a9
commit
7de2e2aed0
@ -315,7 +315,7 @@ end
|
||||
function M.resetAll()
|
||||
log:info("settings:resetAll")
|
||||
|
||||
-- delete all uci sections but system
|
||||
-- find all sections
|
||||
local allSections, msg = uci:get_all(UCI_CONFIG_NAME)
|
||||
if not allSections and msg ~= nil then
|
||||
local errorMSG = "Issue reading all settings: "..utils.dump(msg);
|
||||
@ -323,6 +323,7 @@ function M.resetAll()
|
||||
return nil, errorMSG;
|
||||
end
|
||||
|
||||
-- delete all uci sections but system
|
||||
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
|
||||
local rv, msg = uci:delete(UCI_CONFIG_NAME,key)
|
||||
@ -337,19 +338,19 @@ function M.resetAll()
|
||||
-- reset all to defaults
|
||||
for k,_ in pairs(baseconfig) do
|
||||
if not k:match('^[A-Z_]*$') then --TEMP: skip 'constants', which should be moved anyway
|
||||
M.reset(k)
|
||||
M.reset(k,true)
|
||||
end
|
||||
end
|
||||
|
||||
uci:commit(UCI_CONFIG_NAME)
|
||||
|
||||
M.commit()
|
||||
return true
|
||||
end
|
||||
|
||||
--- Reset setting to default value
|
||||
-- @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.
|
||||
function M.reset(key)
|
||||
function M.reset(key, noCommit)
|
||||
log:info("settings:reset: "..utils.dump(key))
|
||||
|
||||
-- delete
|
||||
@ -361,7 +362,6 @@ function M.reset(key)
|
||||
section = M.get(base.subSection)
|
||||
end
|
||||
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
|
||||
-- (which always happens when reset is used in resetall) it will also generate a error
|
||||
--if not rv and msg ~= nil then
|
||||
@ -371,9 +371,9 @@ function M.reset(key)
|
||||
--end
|
||||
|
||||
-- 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
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user