Skip to content

Commit

Permalink
Automatically add missing fields in config/lime
Browse files Browse the repository at this point in the history
  • Loading branch information
G10h4ck committed May 26, 2017
1 parent 2766bfd commit 86141ad
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions packages/lime-system/files/usr/lib/lua/lime/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ config = {}
config.uci = libuci:cursor()

function config.get(sectionname, option, default)
return config.uci:get("lime", sectionname, option) or config.uci:get("lime-defaults", sectionname, option, default)
local limeconf = config.uci:get("lime", sectionname, option)
if limeconf then return limeconf end

local defcnf = config.uci:get("lime-defaults", sectionname, option, default)
config.set(sectionname, option, defcnf)
return defcnf
end

function config.foreach(configtype, callback)
Expand All @@ -23,15 +28,15 @@ end

function config.get_all(sectionname)
local lime_section = config.uci:get_all("lime", sectionname)
local lime_default_section = config.uci:get_all("lime-defaults", sectionname)
local section_exists = (lime_section ~= nil) or (lime_default_section ~= nil)
local lime_def_section = config.uci:get_all("lime-defaults", sectionname)

if section_exists then
if lime_section or lime_def_section then
local ret = lime_section or {}

if lime_default_section then
for key,value in pairs(lime_default_section) do
if lime_def_section then
for key,value in pairs(lime_def_section) do
if (ret[key] == nil) then
config.set(sectionname, key, value)
ret[key] = value
end
end
Expand Down

0 comments on commit 86141ad

Please sign in to comment.