Revert external tree usage
This commit is contained in:
parent
6d8143f573
commit
2655871d39
1 changed files with 30 additions and 37 deletions
|
@ -108,7 +108,7 @@ end
|
||||||
|
|
||||||
--- Dispatch an HTTP request.
|
--- Dispatch an HTTP request.
|
||||||
-- @param request LuCI HTTP Request object
|
-- @param request LuCI HTTP Request object
|
||||||
function httpdispatch(request, prefix, ext_tree)
|
function httpdispatch(request)
|
||||||
luci.http.context.request = request
|
luci.http.context.request = request
|
||||||
context.request = {}
|
context.request = {}
|
||||||
local pathinfo = http.urldecode(request:getenv("PATH_INFO") or "", true)
|
local pathinfo = http.urldecode(request:getenv("PATH_INFO") or "", true)
|
||||||
|
@ -118,7 +118,7 @@ function httpdispatch(request, prefix, ext_tree)
|
||||||
end
|
end
|
||||||
|
|
||||||
local stat, err = util.coxpcall(function()
|
local stat, err = util.coxpcall(function()
|
||||||
dispatch(context.request, ext_tree)
|
dispatch(context.request)
|
||||||
end, error500)
|
end, error500)
|
||||||
|
|
||||||
luci.http.close()
|
luci.http.close()
|
||||||
|
@ -128,7 +128,7 @@ end
|
||||||
|
|
||||||
--- Dispatches a LuCI virtual path.
|
--- Dispatches a LuCI virtual path.
|
||||||
-- @param request Virtual path
|
-- @param request Virtual path
|
||||||
function dispatch(request, ext_tree)
|
function dispatch(request)
|
||||||
--context._disable_memtrace = require "luci.debug".trap_memtrace("l")
|
--context._disable_memtrace = require "luci.debug".trap_memtrace("l")
|
||||||
local ctx = context
|
local ctx = context
|
||||||
ctx.path = request
|
ctx.path = request
|
||||||
|
@ -151,14 +151,12 @@ function dispatch(request, ext_tree)
|
||||||
end
|
end
|
||||||
require "luci.i18n".setlanguage(lang)
|
require "luci.i18n".setlanguage(lang)
|
||||||
|
|
||||||
if ext_tree then
|
|
||||||
ctx.index, ctx.tree, ctx.treecache, ctx.modifiers = unpack(ext_tree)
|
|
||||||
elseif not ctx.tree then
|
|
||||||
createtree()
|
|
||||||
end
|
|
||||||
|
|
||||||
local c = ctx.tree
|
local c = ctx.tree
|
||||||
local stat
|
local stat
|
||||||
|
if not c then
|
||||||
|
c = createtree()
|
||||||
|
end
|
||||||
|
|
||||||
local track = {}
|
local track = {}
|
||||||
local args = {}
|
local args = {}
|
||||||
ctx.args = args
|
ctx.args = args
|
||||||
|
@ -364,9 +362,9 @@ function createindex()
|
||||||
local suff = { ".lua", ".lua.gz" }
|
local suff = { ".lua", ".lua.gz" }
|
||||||
|
|
||||||
if luci.util.copcall(require, "luci.fastindex") then
|
if luci.util.copcall(require, "luci.fastindex") then
|
||||||
return createindex_fastindex(path, suff)
|
createindex_fastindex(path, suff)
|
||||||
else
|
else
|
||||||
return createindex_plain(path, suff)
|
createindex_plain(path, suff)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -374,7 +372,7 @@ end
|
||||||
-- @param path Controller base directory
|
-- @param path Controller base directory
|
||||||
-- @param suffixes Controller file suffixes
|
-- @param suffixes Controller file suffixes
|
||||||
function createindex_fastindex(path, suffixes)
|
function createindex_fastindex(path, suffixes)
|
||||||
local index = {}
|
index = {}
|
||||||
|
|
||||||
if not fi then
|
if not fi then
|
||||||
fi = luci.fastindex.new("index")
|
fi = luci.fastindex.new("index")
|
||||||
|
@ -388,8 +386,6 @@ function createindex_fastindex(path, suffixes)
|
||||||
for k, v in pairs(fi.indexes) do
|
for k, v in pairs(fi.indexes) do
|
||||||
index[v[2]] = v[1]
|
index[v[2]] = v[1]
|
||||||
end
|
end
|
||||||
|
|
||||||
return index
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Generate the dispatching index using the native file-cache based strategy.
|
--- Generate the dispatching index using the native file-cache based strategy.
|
||||||
|
@ -424,7 +420,7 @@ function createindex_plain(path, suffixes)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local index = {}
|
index = {}
|
||||||
|
|
||||||
for i,c in ipairs(controllers) do
|
for i,c in ipairs(controllers) do
|
||||||
local module = "luci.controller." .. c:sub(#path+1, #c):gsub("/", ".")
|
local module = "luci.controller." .. c:sub(#path+1, #c):gsub("/", ".")
|
||||||
|
@ -445,24 +441,21 @@ function createindex_plain(path, suffixes)
|
||||||
f:writeall(util.get_bytecode(index))
|
f:writeall(util.get_bytecode(index))
|
||||||
f:close()
|
f:close()
|
||||||
end
|
end
|
||||||
|
|
||||||
return index
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Create the dispatching tree from the index.
|
--- Create the dispatching tree from the index.
|
||||||
-- Build the index before if it does not exist yet.
|
-- Build the index before if it does not exist yet.
|
||||||
function createtree()
|
function createtree()
|
||||||
local ctx = context
|
if not index then
|
||||||
local tree = {nodes={}}
|
createindex()
|
||||||
local cache = setmetatable({}, {__mode="v"})
|
|
||||||
local modi = {}
|
|
||||||
|
|
||||||
if not ctx.index then
|
|
||||||
ctx.index = createindex()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local ctx = context
|
||||||
|
local tree = {nodes={}}
|
||||||
|
local modi = {}
|
||||||
|
|
||||||
|
ctx.treecache = setmetatable({}, {__mode="v"})
|
||||||
ctx.tree = tree
|
ctx.tree = tree
|
||||||
ctx.treecache = cache
|
|
||||||
ctx.modifiers = modi
|
ctx.modifiers = modi
|
||||||
|
|
||||||
-- Load default translation
|
-- Load default translation
|
||||||
|
@ -470,10 +463,10 @@ function createtree()
|
||||||
|
|
||||||
local scope = setmetatable({}, {__index = luci.dispatcher})
|
local scope = setmetatable({}, {__index = luci.dispatcher})
|
||||||
|
|
||||||
for k, v in pairs(ctx.index) do
|
for k, v in pairs(index) do
|
||||||
scope._NAME = k
|
scope._NAME = k
|
||||||
setfenv(v, scope)
|
setfenv(v, scope)
|
||||||
pcall(v)
|
v()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function modisort(a,b)
|
local function modisort(a,b)
|
||||||
|
@ -483,10 +476,10 @@ function createtree()
|
||||||
for _, v in util.spairs(modi, modisort) do
|
for _, v in util.spairs(modi, modisort) do
|
||||||
scope._NAME = v.module
|
scope._NAME = v.module
|
||||||
setfenv(v.func, scope)
|
setfenv(v.func, scope)
|
||||||
pcall(v.func)
|
v.func()
|
||||||
end
|
end
|
||||||
|
|
||||||
return { index, tree, cache, modi }
|
return tree
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Register a tree modifier.
|
--- Register a tree modifier.
|
||||||
|
|
Loading…
Reference in a new issue