module("ffluci.fs", package.seeall)
-require("lfs")
+require("posix")
-- Checks whether a file exists
function isfile(filename)
-- 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")
-- 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
-- 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()
-- 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