summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--logfiles-model.lua44
1 files changed, 32 insertions, 12 deletions
diff --git a/logfiles-model.lua b/logfiles-model.lua
index d5df7b9..d68662c 100644
--- a/logfiles-model.lua
+++ b/logfiles-model.lua
@@ -1,6 +1,7 @@
-- acf model for displaying logfiles
module (..., package.seeall)
require("fs")
+require("posix")
require("format")
require("modelfunctions")
@@ -8,6 +9,9 @@ require("modelfunctions")
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))
+ end
local size = st.size or "0"
local lastmod = st.mtime or "---"
local file_inuse = io.popen("fuser " .. format.escapespecialcharacters(path) )
@@ -26,9 +30,13 @@ local function recursedir(path, filearray)
if not string.match(v, "^%.") then
local f = path .. "/" .. v
-- If subfolder exists, list files in this subfolder
- if (posix.stat(f).type == "directory") then
+ local st = fs.stat(f)
+ while st and st.type == "link" do
+ st = fs.stat(posix.readlink(st.path))
+ end
+ if st and st.type == "directory" then
recursedir(f, filearray)
- else
+ elseif st then
table.insert(filearray, f)
end
end
@@ -74,16 +82,24 @@ local do_grep = function(filecontent, grep)
end
get_filedetails = function (path, grep)
+ local success = false
local available_files = get()
- local filedetails = modelfunctions.getfiledetails(path,
- function(filename)
- for i,file in ipairs(available_files.value) do
- if file.value.filename.value == filename then
- return true
- end
- end
- return false
- end)
+ for i,file in ipairs(available_files.value) do
+ if file.value.filename.value == path then
+ success = true
+ break
+ end
+ end
+ local file = path
+ if success then
+ local st = fs.stat(path)
+ while st.type == "link" do
+ st = fs.stat(posix.readlink(st.path))
+ end
+ file = st.path
+ end
+ local filedetails = modelfunctions.getfiledetails(file, function(filename) return success end)
+ filedetails.value.filename.value = path
if not filedetails.errtxt then
do_grep(filedetails.value.filecontent, grep)
end
@@ -140,7 +156,11 @@ delete = function (filetodelete)
if ( file.value.filename.value == filetodelete ) then
-- Check if file is deletable (or in use)
if ( not file.value.inuse.value ) then
- local status, err = os.remove( filetodelete )
+ local st = fs.stat(filetodelete)
+ while st.type == "link" do
+ st = fs.stat(posix.readlink(st.path))
+ end
+ local status, err = os.remove( st.path )
if not ( err ) then
deletedfile.value = "File '"..filetodelete.."' has been successfully deleted!"
else