diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2009-07-19 00:24:58 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2009-07-19 00:24:58 +0000 |
commit | 8fcd841aa9af96c8a4a4d3c1a555d2d1ed42332c (patch) | |
tree | cf6466b373236442e63742cb4f73b22579940784 /libs | |
parent | 6abba6163290b58cd9ebae98d8459ac38ef52a4b (diff) |
convert luci.fs users to nixio.fs api
Diffstat (limited to 'libs')
-rw-r--r-- | libs/cbi/luasrc/cbi.lua | 17 | ||||
-rw-r--r-- | libs/cbi/luasrc/view/cbi/filebrowser.htm | 13 | ||||
-rw-r--r-- | libs/cbi/luasrc/view/cbi/upload.htm | 3 | ||||
-rw-r--r-- | libs/core/luasrc/util.lua | 2 | ||||
-rw-r--r-- | libs/lucid/luasrc/lucid.lua | 2 | ||||
-rw-r--r-- | libs/sys/luasrc/sys.lua | 40 | ||||
-rw-r--r-- | libs/uvl/luasrc/uvl.lua | 10 | ||||
-rw-r--r-- | libs/uvl/luasrc/uvl/datatypes.lua | 2 | ||||
-rw-r--r-- | libs/uvl/luasrc/uvl/validation.lua | 2 | ||||
-rw-r--r-- | libs/uvldoc/luasrc/uvldoc/renderer.lua | 4 | ||||
-rw-r--r-- | libs/web/luasrc/dispatcher.lua | 13 | ||||
-rw-r--r-- | libs/web/luasrc/sauth.lua | 21 | ||||
-rw-r--r-- | libs/web/luasrc/template.lua | 10 |
13 files changed, 69 insertions, 70 deletions
diff --git a/libs/cbi/luasrc/cbi.lua b/libs/cbi/luasrc/cbi.lua index e513053ba..f3c481cf8 100644 --- a/libs/cbi/luasrc/cbi.lua +++ b/libs/cbi/luasrc/cbi.lua @@ -30,9 +30,10 @@ require("luci.template") local util = require("luci.util") require("luci.http") require("luci.uvl") -require("luci.fs") + --local event = require "luci.sys.event" +local fs = require("nixio.fs") local uci = require("luci.model.uci") local class = util.class local instanceof = util.instanceof @@ -52,7 +53,7 @@ REMOVE_PREFIX = "cbi.rts." -- Loads a CBI map from given file, creating an environment and returns it function load(cbimap, ...) - require("luci.fs") + local fs = require "nixio.fs" local i18n = require "luci.i18n" require("luci.config") require("luci.util") @@ -60,9 +61,9 @@ function load(cbimap, ...) local upldir = "/lib/uci/upload/" local cbidir = luci.util.libpath() .. "/model/cbi/" - assert(luci.fs.stat(cbimap) or - luci.fs.stat(cbidir..cbimap..".lua") or - luci.fs.stat(cbidir..cbimap..".lua.gz"), + assert(fs.stat(cbimap) or + fs.stat(cbidir..cbimap..".lua") or + fs.stat(cbidir..cbimap..".lua.gz"), "Model not found!") local func, err = loadfile(cbimap) @@ -1703,7 +1704,7 @@ end function FileUpload.cfgvalue(self, section) local val = AbstractValue.cfgvalue(self, section) - if val and luci.fs.access(val) then + if val and fs.access(val) then return val end return nil @@ -1717,7 +1718,7 @@ function FileUpload.formvalue(self, section) then return val end - luci.fs.unlink(val) + fs.unlink(val) self.value = nil end return nil @@ -1725,7 +1726,7 @@ end function FileUpload.remove(self, section) local val = AbstractValue.formvalue(self, section) - if val and luci.fs.access(val) then luci.fs.unlink(val) end + if val and fs.access(val) then fs.unlink(val) end return AbstractValue.remove(self, section) end diff --git a/libs/cbi/luasrc/view/cbi/filebrowser.htm b/libs/cbi/luasrc/view/cbi/filebrowser.htm index 5eda993b6..f82957221 100644 --- a/libs/cbi/luasrc/view/cbi/filebrowser.htm +++ b/libs/cbi/luasrc/view/cbi/filebrowser.htm @@ -48,7 +48,8 @@ $Id$ </head> <body> <% - require("luci.fs") + require("nixio.fs") + require("nixio.util") require("luci.http") require("luci.dispatcher") @@ -63,7 +64,7 @@ $Id$ end local filepath = table.concat( path, '/' ) - local filestat = luci.fs.stat( filepath ) + local filestat = nixio.fs.stat( filepath ) local baseurl = luci.dispatcher.build_url('admin', 'filebrowser') if filestat and filestat.type == "reg" then @@ -76,7 +77,7 @@ $Id$ filepath = filepath .. '/' end - local entries = luci.fs.dir(filepath) + local entries = nixio.util.consume((nixio.fs.dir(filepath))) -%> <div id="path"> Location: @@ -98,8 +99,8 @@ $Id$ <div id="listing"> <ul> <% for _, e in luci.util.vspairs(entries) do - local stat = luci.fs.stat(filepath..e) - if e ~= '.' and e ~= '..' and stat and stat.type == 'dir' then + local stat = nixio.fs.stat(filepath..e) + if stat and stat.type == 'dir' then -%> <li class="dir"> <img src="/luci-static/resources/cbi/folder.png" alt="Directory" /> @@ -108,7 +109,7 @@ $Id$ <% end end -%> <% for _, e in luci.util.vspairs(entries) do - local stat = luci.fs.stat(filepath..e) + local stat = nixio.fs.stat(filepath..e) if stat and stat.type ~= 'dir' then -%> <li class="file"> diff --git a/libs/cbi/luasrc/view/cbi/upload.htm b/libs/cbi/luasrc/view/cbi/upload.htm index a4ab0c958..7bde74b48 100644 --- a/libs/cbi/luasrc/view/cbi/upload.htm +++ b/libs/cbi/luasrc/view/cbi/upload.htm @@ -16,10 +16,11 @@ $Id$ <% local t = require("luci.tools.webadmin") local v = self:cfgvalue(section) + v = v and nixio.fs.stat(v) -%> <%+cbi/valueheader%> <% if v then %> - <%:cbi_upload Uploaded File%> (<%=t.byte_format(luci.fs.stat(v, "size") or 0)%>) + <%:cbi_upload Uploaded File%> (<%=t.byte_format(v.size)%>) <input type="hidden"<%= attr("value", v) .. attr("name", cbid) .. attr("id", cbid) %> /> <input class="cbi-input-image" type="image" value="<%:cbi_replace%>" name="cbi.rlf.<%=section .. "." .. self.option%>" alt="<%:cbi_replace%>" title="<%:cbi_replace%>" src="<%=resource%>/cbi/reload.gif" /> <% else %> diff --git a/libs/core/luasrc/util.lua b/libs/core/luasrc/util.lua index e86d5ec23..f83cac576 100644 --- a/libs/core/luasrc/util.lua +++ b/libs/core/luasrc/util.lua @@ -705,7 +705,7 @@ end --- Returns the absolute path to LuCI base directory. -- @return String containing the directory path function libpath() - return require "luci.fs".dirname(ldebug.__file__) + return require "nixio.fs".dirname(ldebug.__file__) end diff --git a/libs/lucid/luasrc/lucid.lua b/libs/lucid/luasrc/lucid.lua index 96611d244..d743269fe 100644 --- a/libs/lucid/luasrc/lucid.lua +++ b/libs/lucid/luasrc/lucid.lua @@ -331,4 +331,4 @@ function daemonize() nixio.dup(devnull, nixio.stderr) return true -end
\ No newline at end of file +end diff --git a/libs/sys/luasrc/sys.lua b/libs/sys/luasrc/sys.lua index 9d03445bb..d57077026 100644 --- a/libs/sys/luasrc/sys.lua +++ b/libs/sys/luasrc/sys.lua @@ -27,12 +27,12 @@ limitations under the License. local io = require "io" local os = require "os" -local nixio = require "nixio" local table = require "table" +local nixio = require "nixio" +local fs = require "nixio.fs" local luci = {} luci.util = require "luci.util" -luci.fs = require "luci.fs" luci.ip = require "luci.ip" local tonumber, ipairs, pairs, pcall, type, next = @@ -135,7 +135,7 @@ getenv = nixio.getenv -- @return String containing the system hostname function hostname(newname) if type(newname) == "string" and #newname > 0 then - luci.fs.writefile( "/proc/sys/kernel/hostname", newname .. "\n" ) + fs.writefile( "/proc/sys/kernel/hostname", newname ) return newname else return nixio.uname().nodename @@ -180,8 +180,8 @@ end -- @return String containing the memory used for buffering in kB -- @return String containing the free memory amount in kB function sysinfo() - local cpuinfo = luci.fs.readfile("/proc/cpuinfo") - local meminfo = luci.fs.readfile("/proc/meminfo") + local cpuinfo = fs.readfile("/proc/cpuinfo") + local meminfo = fs.readfile("/proc/meminfo") local system = cpuinfo:match("system typ.-:%s*([^\n]+)") local model = "" @@ -219,7 +219,7 @@ end -- @param bytes Number of bytes for the unique id -- @return String containing hex encoded id function uniqueid(bytes) - local rand = luci.fs.readfile("/dev/urandom", bytes) + local rand = fs.readfile("/dev/urandom", bytes) return rand and nixio.bin.hexlify(rand) end @@ -247,7 +247,7 @@ end -- @return Table with the currently tracked IP connections function net.conntrack(callback) local connt = {} - if luci.fs.access("/proc/net/nf_conntrack", "r") then + if fs.access("/proc/net/nf_conntrack", "r") then for line in io.lines("/proc/net/nf_conntrack") do line = line:match "^(.-( [^ =]+=).-)%2" local entry, flags = _parse_mixed_record(line, " +") @@ -263,7 +263,7 @@ function net.conntrack(callback) connt[#connt+1] = entry end end - elseif luci.fs.access("/proc/net/ip_conntrack", "r") then + elseif fs.access("/proc/net/ip_conntrack", "r") then for line in io.lines("/proc/net/ip_conntrack") do line = line:match "^(.-( [^ =]+=).-)%2" local entry, flags = _parse_mixed_record(line, " +") @@ -369,13 +369,11 @@ end -- @return String containing the MAC address or nil if it cannot be found function net.ip4mac(ip) local mac = nil - - for i, l in ipairs(net.arptable()) do - if l["IP address"] == ip then - mac = l["HW address"] + net.arptable(function(e) + if e["IP address"] == ip then + mac = e["HW address"] end - end - + end) return mac end @@ -432,7 +430,7 @@ end -- { "source", "dest", "nexthop", "metric", "refcount", "usecount", -- "flags", "device" } function net.routes6(callback) - if luci.fs.access("/proc/net/ipv6_route", "r") then + if fs.access("/proc/net/ipv6_route", "r") then local routes = { } for line in io.lines("/proc/net/ipv6_route") do @@ -711,8 +709,8 @@ init.dir = "/etc/init.d/" -- @return Table containing the names of all inistalled init scripts function init.names() local names = { } - for _, name in ipairs(luci.fs.glob(init.dir.."*")) do - names[#names+1] = luci.fs.basename(name) + for name in fs.glob(init.dir.."*") do + names[#names+1] = fs.basename(name) end return names end @@ -721,7 +719,7 @@ end -- @param name Name of the init script -- @return Boolean indicating whether init is enabled function init.enabled(name) - if luci.fs.access(init.dir..name) then + if fs.access(init.dir..name) then return ( call(init.dir..name.." enabled") == 0 ) end return false @@ -731,7 +729,7 @@ end -- @param name Name of the init script -- @return Numeric index value function init.index(name) - if luci.fs.access(init.dir..name) then + if fs.access(init.dir..name) then return call("source "..init.dir..name.."; exit $START") end end @@ -740,7 +738,7 @@ end -- @param name Name of the init script -- @return Boolean indicating success function init.enable(name) - if luci.fs.access(init.dir..name) then + if fs.access(init.dir..name) then return ( call(init.dir..name.." enable") == 1 ) end end @@ -749,7 +747,7 @@ end -- @param name Name of the init script -- @return Boolean indicating success function init.disable(name) - if luci.fs.access(init.dir..name) then + if fs.access(init.dir..name) then return ( call(init.dir..name.." disable") == 0 ) end end diff --git a/libs/uvl/luasrc/uvl.lua b/libs/uvl/luasrc/uvl.lua index dd8058f03..33f45bf89 100644 --- a/libs/uvl/luasrc/uvl.lua +++ b/libs/uvl/luasrc/uvl.lua @@ -19,7 +19,9 @@ $Id$ -- @class module -- @cstyle instance -local fs = require "luci.fs" +require "nixio.util" + +local fs = require "nixio.fs" local uci = require "luci.model.uci" local util = require "luci.util" local table = require "table" @@ -403,11 +405,11 @@ function UVL.read_scheme( self, shm, alias ) local bc = "%s/bytecode/%s.lua" %{ self.schemedir, shm } if not fs.access(bc) then - local files = fs.glob(self.schemedir .. '/*/' .. shm) + local files = nixio.util.consume(fs.glob(self.schemedir .. '/*/' .. shm)) - if files then + if #files > 0 then local ok, err - for i, file in ipairs( files ) do + for file in files do if not fs.access(file) then return false, so:error(ERR.SME_READ(so,file)) end diff --git a/libs/uvl/luasrc/uvl/datatypes.lua b/libs/uvl/luasrc/uvl/datatypes.lua index 1ad0891f2..c6a5de398 100644 --- a/libs/uvl/luasrc/uvl/datatypes.lua +++ b/libs/uvl/luasrc/uvl/datatypes.lua @@ -14,7 +14,7 @@ $Id$ ]]-- -local fs = require "luci.fs" +local fs = require "nixio.fs" local ip = require "luci.ip" local math = require "math" local util = require "luci.util" diff --git a/libs/uvl/luasrc/uvl/validation.lua b/libs/uvl/luasrc/uvl/validation.lua index 90fde64f1..47eed6b1c 100644 --- a/libs/uvl/luasrc/uvl/validation.lua +++ b/libs/uvl/luasrc/uvl/validation.lua @@ -15,7 +15,7 @@ $Id$ ]]-- local os = require "os" -local fs = require "luci.fs" +local fs = require "nixio.fs" local sys = require "luci.sys" local ERR = require "luci.uvl.errors" diff --git a/libs/uvldoc/luasrc/uvldoc/renderer.lua b/libs/uvldoc/luasrc/uvldoc/renderer.lua index 7a188f6cf..79b6cdb28 100644 --- a/libs/uvldoc/luasrc/uvldoc/renderer.lua +++ b/libs/uvldoc/luasrc/uvldoc/renderer.lua @@ -14,7 +14,7 @@ $Id$ ]]-- local io = require "io" -local fs = require "luci.fs" +local fs = require "nixio.fs" local uvl = require "luci.uvl" local util = require "luci.util" local ltn12 = require "luci.ltn12" @@ -48,7 +48,7 @@ function Generator.make(self) fs.mkdir(self.output) for i, file in ipairs(self.additionals) do - fs.copy(self.sourcedir .. file, self.output .. "/" .. file) + fs.datacopy(self.sourcedir .. file, self.output .. "/" .. file) end template.compiler_mode = "memory" diff --git a/libs/web/luasrc/dispatcher.lua b/libs/web/luasrc/dispatcher.lua index 8fddf0212..37008b594 100644 --- a/libs/web/luasrc/dispatcher.lua +++ b/libs/web/luasrc/dispatcher.lua @@ -25,7 +25,7 @@ limitations under the License. ]]-- --- LuCI web dispatcher. -local fs = require "luci.fs" +local fs = require "nixio.fs" local sys = require "luci.sys" local init = require "luci.init" local util = require "luci.util" @@ -394,19 +394,16 @@ end function createindex_plain(path, suffixes) local controllers = { } for _, suffix in ipairs(suffixes) do - controllers = util.combine( - controllers, - luci.fs.glob(path .. "*" .. suffix) or {}, - luci.fs.glob(path .. "*/*" .. suffix) or {} - ) + nixio.util.consume((fs.glob(path .. "*" .. suffix)), controllers) + nixio.util.consume((fs.glob(path .. "*/*" .. suffix)), controllers) end if indexcache then - local cachedate = fs.mtime(indexcache) + local cachedate = fs.stat(indexcache, "mtime") if cachedate then local realdate = 0 for _, obj in ipairs(controllers) do - local omtime = fs.mtime(path .. "/" .. obj) + local omtime = fs.stat(path .. "/" .. obj, "mtime") realdate = (omtime and omtime > realdate) and omtime or realdate end diff --git a/libs/web/luasrc/sauth.lua b/libs/web/luasrc/sauth.lua index e5cb17845..8ae24a541 100644 --- a/libs/web/luasrc/sauth.lua +++ b/libs/web/luasrc/sauth.lua @@ -15,7 +15,6 @@ $Id$ --- LuCI session library. module("luci.sauth", package.seeall) -require("luci.fs") require("luci.util") require("luci.sys") require("luci.config") @@ -30,17 +29,17 @@ sessiontime = tonumber(luci.config.sauth.sessiontime) or 15 * 60 --- Manually clean up expired sessions. function clean() local now = os.time() - local files = luci.fs.dir(sessionpath) + local files = fs.dir(sessionpath) if not files then return nil end - for i, file in pairs(files) do + for file in files do local fname = sessionpath .. "/" .. file - local stat = luci.fs.stat(fname) + local stat = fs.stat(fname) if stat and stat.type == "reg" and stat.mtime + sessiontime < now then - luci.fs.unlink(fname) + fs.unlink(fname) end end end @@ -68,8 +67,8 @@ function read(id) if not sane(sessionpath .. "/" .. id) then return end - luci.fs.utime(sessionpath .. "/" .. id) - return luci.fs.readfile(sessionpath .. "/" .. id) + fs.utimes(sessionpath .. "/" .. id) + return fs.readfile(sessionpath .. "/" .. id) end @@ -77,8 +76,8 @@ end -- @return Boolean status function sane(file) return luci.sys.process.info("uid") - == luci.fs.stat(file or sessionpath, "uid") - and luci.fs.stat(file or sessionpath, "modestr") + == fs.stat(file or sessionpath, "uid") + and fs.stat(file or sessionpath, "modestr") == (file and "rw-------" or "rwx------") end @@ -106,5 +105,5 @@ function kill(id) if not id:match("^%w+$") then error("Session ID is not sane!") end - luci.fs.unlink(sessionpath .. "/" .. id) -end
\ No newline at end of file + fs.unlink(sessionpath .. "/" .. id) +end diff --git a/libs/web/luasrc/template.lua b/libs/web/luasrc/template.lua index c8f4daa2d..e8f65e3be 100644 --- a/libs/web/luasrc/template.lua +++ b/libs/web/luasrc/template.lua @@ -24,7 +24,7 @@ limitations under the License. ]]-- -local fs = require "luci.fs" +local fs = require "nixio.fs" local sys = require "luci.sys" local util = require "luci.util" local table = require "table" @@ -173,18 +173,18 @@ function Template.__init__(self, name) local err if compiler_mode == "file" then - local tplmt = fs.mtime(sourcefile) or fs.mtime(sourcefile .. ".htm") - local commt = fs.mtime(compiledfile) + local tplmt = fs.stat(sourcefile, "mtime") or fs.stat(sourcefile .. ".htm", "mtime") + local commt = fs.stat(compiledfile, "mtime") if not fs.mtime(cdir) then - fs.mkdir(cdir, true) + fs.mkdirr(cdir) fs.chmod(fs.dirname(cdir), 777) end assert(tplmt or commt, "No such template: " .. name) -- Build if there is no compiled file or if compiled file is outdated - if not commt or (commt and tplmt and commt < tplmt) then + if not commt or (commt and tplmt and commt < tplmt) then local source source, err = fs.readfile(sourcefile) or fs.readfile(sourcefile .. ".htm") |