* Added simple text editor
[project/luci.git] / src / ffluci / fs.lua
index fb9a9c1..e262caa 100644 (file)
@@ -26,7 +26,7 @@ limitations under the License.
 
 module("ffluci.fs", package.seeall)
 
-require("lfs")
+require("posix")
 
 -- Checks whether a file exists
 function isfile(filename)
@@ -37,10 +37,10 @@ end
 
 -- Returns the content of file
 function readfile(filename)
-       local fp = io.open(filename)
+       local fp, err = io.open(filename)
        
        if fp == nil then
-               error("Unable to open file for reading: " .. filename)
+               error(err)
        end
        
        local data = fp:read("*a")
@@ -50,12 +50,12 @@ end
 
 -- Returns the content of file as array of lines
 function readfilel(filename)
-       local fp = io.open(filename)
+       local fp, err = io.open(filename)
        local line = ""
        local data = {}
                
        if fp == nil then
-               error("Unable to open file for reading: " .. filename)
+               error(err)
        end
        
        while true do
@@ -70,9 +70,9 @@ end
 
 -- Writes given data to a file
 function writefile(filename, data)
-       local fp = io.open(filename, "w")
+       local fp, err = io.open(filename, "w")
        if fp == nil then
-               error("Unable to open file for writing: " .. filename)
+               error(err)
        end
        fp:write(data)
        fp:close()
@@ -80,21 +80,22 @@ end
 
 -- Returns the file modification date/time of "path"
 function mtime(path)
-       return lfs.attributes(path, "modification")
+       return posix.stat(path, "mtime")
 end
 
--- Simplified dirname function
-function dirname(file)
-       return string.gsub(file, "[^/]+$", "")
-end
+-- basename wrapper
+basename = posix.basename
+
+-- dirname wrapper
+dirname = posix.dirname
 
 -- Diriterator - alias for lfs.dir - filter . and ..
 function dir(path)
-       local e = {}
-       for entry in lfs.dir(path) do
-               if not(entry == "." or entry == "..") then
-                       table.insert(e, entry)
-               end
-       end
+       local e = posix.dir(path)
+       table.remove(e, 1)
+       table.remove(e, 1)
        return e
-end
\ No newline at end of file
+end
+
+-- Alias for lfs.mkdir
+mkdir = posix.mkdir
\ No newline at end of file