summaryrefslogtreecommitdiffstats
path: root/logfiles-model.lua
diff options
context:
space:
mode:
Diffstat (limited to 'logfiles-model.lua')
-rw-r--r--logfiles-model.lua37
1 files changed, 31 insertions, 6 deletions
diff --git a/logfiles-model.lua b/logfiles-model.lua
index 590b3ae..9fa36e7 100644
--- a/logfiles-model.lua
+++ b/logfiles-model.lua
@@ -1,7 +1,8 @@
-- acf model for displaying logfiles
local mymodule = {}
-posix = require("posix")
+dirent = require("posix.dirent")
+unistd = require("posix.unistd")
modelfunctions = require("modelfunctions")
fs = require("acf.fs")
format = require("acf.format")
@@ -11,7 +12,12 @@ local function file_info ( path )
-- Check if file is in use
local st = fs.stat(path)
while st.type == "link" do
- st = fs.stat(posix.readlink(st.path))
+ local ok,link = pcall(unistd.readlink, st.path)
+ if ok and link then
+ st = fs.stat(link)
+ else
+ break
+ end
end
local size = st.size or "0"
local lastmod = st.mtime or "---"
@@ -24,14 +30,23 @@ end
local function recursedir(path, filearray)
filearray = filearray or {}
local k,v
- for k,v in pairs(posix.dir(path) or {}) do
+ local ok, files = pcall(dirent.dir, path)
+ if not ok then
+ return {}
+ end
+ for k,v in pairs(files) do
-- Ignore files that begins with a '.'
if not string.match(v, "^%.") then
local f = path .. "/" .. v
-- If subfolder exists, list files in this subfolder
local st = fs.stat(f)
while st and st.type == "link" do
- st = fs.stat(posix.readlink(st.path))
+ local ok,link = pcall(unistd.readlink, st.path)
+ if ok and link then
+ st = fs.stat(link)
+ else
+ break
+ end
end
if st and st.type == "directory" then
recursedir(f, filearray)
@@ -93,7 +108,12 @@ mymodule.get_filedetails = function (path, grep)
if success then
local st = fs.stat(path)
while st.type == "link" do
- st = fs.stat(posix.readlink(st.path))
+ local ok,link = pcall(unistd.readlink, st.path)
+ if ok and link then
+ st = fs.stat(link)
+ else
+ break
+ end
end
file = st.path
end
@@ -170,7 +190,12 @@ mymodule.delete = function (self, filetodelete)
else
local st = fs.stat(filetodelete.value.filename.value)
while st.type == "link" do
- st = fs.stat(posix.readlink(st.path))
+ local ok,link = pcall(unistd.readlink, st.path)
+ if ok and link then
+ st = fs.stat(link)
+ else
+ break
+ end
end
local status, err = os.remove( st.path )
if err then