X-Git-Url: https://git.archive.openwrt.org/?a=blobdiff_plain;ds=sidebyside;f=modules%2Fluci-base%2Fluasrc%2Fcbi.lua;h=f3d4618b654879c12d7962fa13b7cb5ccb8cbec9;hb=237740b38655cc1c56e13574f07e5c56e9910ef1;hp=34de44a5f01cace744ddb2f2066c82344cf6808e;hpb=7a3493b1f7d75a3945279115324cf2ff4da26b7b;p=project%2Fluci.git diff --git a/modules/luci-base/luasrc/cbi.lua b/modules/luci-base/luasrc/cbi.lua index 34de44a5f..f3d4618b6 100644 --- a/modules/luci-base/luasrc/cbi.lua +++ b/modules/luci-base/luasrc/cbi.lua @@ -12,6 +12,7 @@ require("luci.http") local fs = require("nixio.fs") local uci = require("luci.model.uci") local datatypes = require("luci.cbi.datatypes") +local dispatcher = require("luci.dispatcher") local class = util.class local instanceof = util.instanceof @@ -307,8 +308,30 @@ function Map.__init__(self, config, ...) self.changed = false - if not self.uci:load(self.config) then - error("Unable to read UCI data: " .. self.config) + local path = "%s/%s" %{ self.uci:get_confdir(), self.config } + if fs.stat(path, "type") ~= "reg" then + fs.writefile(path, "") + end + + local ok, err = self.uci:load(self.config) + if not ok then + local url = dispatcher.build_url(unpack(dispatcher.context.request)) + local source = self:formvalue("cbi.source") + if type(source) == "string" then + fs.writefile(path, source:gsub("\r\n", "\n")) + ok, err = self.uci:load(self.config) + if ok then + luci.http.redirect(url) + end + end + self.save = false + end + + if not ok then + self.template = "cbi/error" + self.error = err + self.source = fs.readfile(path) or "" + self.pageaction = false end end @@ -1510,13 +1533,16 @@ function Flag.parse(self, section) if fexists then local fvalue = self:formvalue(section) and self.enabled or self.disabled + local cvalue = self:cfgvalue(section) if fvalue ~= self.default or (not self.optional and not self.rmempty) then self:write(section, fvalue) else self:remove(section) end + if (fvalue ~= cvalue) then self.section.changed = true end else self:remove(section) + self.section.changed = true end end