* luci/libs/uvl: more sensitive checking of error reasons in evaluation of option dependencies
This commit is contained in:
parent
4219ec1754
commit
8d75d524f9
3 changed files with 26 additions and 8 deletions
|
@ -295,9 +295,8 @@ function UVL._validate_option( self, option, nodeps )
|
||||||
if not nodeps then
|
if not nodeps then
|
||||||
local ok, err = dependencies.check( self, option )
|
local ok, err = dependencies.check( self, option )
|
||||||
if not ok then
|
if not ok then
|
||||||
-- XXX: maybe this needs to be more specific
|
if not err:is_all(ERR.ERR_DEP_NOTEQUAL) and
|
||||||
if not err:is(ERR.ERR_DEP_NOTEQUAL) and
|
not err:is_all(ERR.ERR_DEP_NOVALUE)
|
||||||
not err:is(ERR.ERR_DEP_NOVALUE)
|
|
||||||
then
|
then
|
||||||
option:error(err)
|
option:error(err)
|
||||||
return false, option:errors()
|
return false, option:errors()
|
||||||
|
|
|
@ -37,7 +37,7 @@ function _parse_reference( r, c, s, o )
|
||||||
for v in r:gmatch("[^.]+") do
|
for v in r:gmatch("[^.]+") do
|
||||||
ref[#ref+1] = (v:gsub( "%$(.+)", vars ))
|
ref[#ref+1] = (v:gsub( "%$(.+)", vars ))
|
||||||
end
|
end
|
||||||
|
|
||||||
if #ref < 2 then
|
if #ref < 2 then
|
||||||
table.insert(ref, 1, s or '$section')
|
table.insert(ref, 1, s or '$section')
|
||||||
end
|
end
|
||||||
|
@ -81,7 +81,11 @@ function check( self, object, nodeps )
|
||||||
|
|
||||||
for _, dep in ipairs(object:scheme('depends')) do
|
for _, dep in ipairs(object:scheme('depends')) do
|
||||||
local subcondition = true
|
local subcondition = true
|
||||||
for k, v in pairs(dep) do
|
local score = 0
|
||||||
|
|
||||||
|
for k, v in util.spairs(
|
||||||
|
dep, function(a, b) return type(dep[a]) == "string" end
|
||||||
|
) do
|
||||||
-- XXX: better error
|
-- XXX: better error
|
||||||
local ref = _parse_reference( k, unpack(object.cref) )
|
local ref = _parse_reference( k, unpack(object.cref) )
|
||||||
|
|
||||||
|
@ -103,10 +107,13 @@ function check( self, object, nodeps )
|
||||||
derr:child(
|
derr:child(
|
||||||
type(v) == "boolean"
|
type(v) == "boolean"
|
||||||
and ERR.DEP_NOVALUE(option, depstr)
|
and ERR.DEP_NOVALUE(option, depstr)
|
||||||
or ERR.DEP_NOTEQUAL(option, {depstr, v})
|
or ERR.DEP_NOTEQUAL(option, {depstr, v}),
|
||||||
|
score
|
||||||
)
|
)
|
||||||
|
|
||||||
break
|
--break
|
||||||
|
else
|
||||||
|
score = score + ( type(v) == "boolean" and 1 or 10 )
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
subcondition = false
|
subcondition = false
|
||||||
|
|
|
@ -19,7 +19,7 @@ local uvl = require "luci.uvl"
|
||||||
local util = require "luci.util"
|
local util = require "luci.util"
|
||||||
local string = require "string"
|
local string = require "string"
|
||||||
|
|
||||||
local ipairs, error, type = ipairs, error, type
|
local ipairs, error, type = ipairs, error, type
|
||||||
local tonumber, unpack = tonumber, unpack
|
local tonumber, unpack = tonumber, unpack
|
||||||
|
|
||||||
|
|
||||||
|
@ -184,3 +184,15 @@ function error.is(self, code)
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function error.is_all(self, code)
|
||||||
|
if self.code == code then
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
local equal = false
|
||||||
|
for _, c in ipairs(self.childs) do
|
||||||
|
equal = ( c.code == code )
|
||||||
|
end
|
||||||
|
return equal
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in a new issue