Optimized error handling
[project/luci.git] / libs / web / luasrc / dispatcher.lua
index 9603f5f..7692dd2 100644 (file)
@@ -263,6 +263,13 @@ function createindex_plain(path, suffix)
        if indexcache then
                local cachedate = fs.mtime(indexcache)
                if cachedate and cachedate > fs.mtime(path) then
+
+                       assert(
+                               sys.process.info("uid") == fs.stat(indexcache, "uid")
+                               and fs.stat(indexcache, "mode") == "rw-------",
+                               "Fatal: Indexcache is not sane!"
+                       )
+
                        index = loadfile(indexcache)()
                        return index
                end             
@@ -287,6 +294,7 @@ function createindex_plain(path, suffix)
        
        if indexcache then
                fs.writefile(indexcache, util.get_bytecode(index))
+               fs.chmod(indexcache, "a-rwx,u+rw")
        end
 end
 
@@ -307,7 +315,7 @@ function createtree()
        require "luci.i18n".loadc("default")
        
        local scope = setmetatable({}, {__index = _G})
-       for k,v in pairs(_M) do
+       for k,v in pairs(luci.dispatcher) do
                if type(v) == "function" then
                        scope[k] = v
                end
@@ -456,18 +464,10 @@ function cbi(model)
                require("luci.cbi")
                require("luci.template")
 
-               local stat, maps = luci.util.copcall(luci.cbi.load, model, ...)
-               if not stat then
-                       error500(maps)
-                       return true
-               end
+               maps = luci.cbi.load(model, ...)
 
                for i, res in ipairs(maps) do
-                       local stat, err = luci.util.copcall(res.parse, res)
-                       if not stat then
-                               error500(err)
-                               return true
-                       end
+                       res:parse()
                end
 
                luci.template.render("cbi/header")
@@ -485,18 +485,10 @@ function form(model)
                require("luci.cbi")
                require("luci.template")
 
-               local stat, maps = luci.util.copcall(luci.cbi.load, model, ...)
-               if not stat then
-                       error500(maps)
-                       return true
-               end
+               maps = luci.cbi.load(model, ...)
 
                for i, res in ipairs(maps) do
-                       local stat, err = luci.util.copcall(res.parse, res)
-                       if not stat then
-                               error500(err)
-                               return true
-                       end
+                       res:parse()
                end
 
                luci.template.render("header")