diff options
author | Mika Havela <mika.havela@gmail.com> | 2008-01-15 17:32:29 +0000 |
---|---|---|
committer | Mika Havela <mika.havela@gmail.com> | 2008-01-15 17:32:29 +0000 |
commit | b49907bb90004ddd89420e1714bdac631d4cf4bd (patch) | |
tree | ce6018c6db5a5d950017ad77ccf6de3b06ec2e54 /logfiles-model.lua | |
parent | 0df0224d97673e818e198dd3bbcd30e39e1bd66c (diff) | |
download | acf-alpine-baselayout-b49907bb90004ddd89420e1714bdac631d4cf4bd.tar.bz2 acf-alpine-baselayout-b49907bb90004ddd89420e1714bdac631d4cf4bd.tar.xz |
Cleaned up the code and using some librarys instead.
git-svn-id: svn://svn.alpinelinux.org/acf/alpine-baselayout/trunk@582 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'logfiles-model.lua')
-rw-r--r-- | logfiles-model.lua | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/logfiles-model.lua b/logfiles-model.lua index e0e0888..f00f7f4 100644 --- a/logfiles-model.lua +++ b/logfiles-model.lua @@ -1,19 +1,15 @@ -- acf model for displaying logfiles recusivly module (..., package.seeall) +require("fs") -- no initializer in model - use controller.init for that -- Function to get detailed information on a specific file. local function file_info ( path ) - -- Load dependencys - split = require("split") - -- Get size, changedate... - local file = io.popen("ls -lh " .. path ) - local file_info_result = file:read("*a") or "unknown" - file:close() - local size = rawget(split("%s+", file_info_result),5) - local lastmod = rawget(split("%s+", file_info_result),6) .. " " .. rawget(split("%s+", file_info_result),7) .. " " .. rawget(split("%s+", file_info_result),8) -- Check if file is in use + local st = fs.stat(path) + local size = st.size + local lastmod = st.mtime local file_inuse = io.popen("fuser " .. path ) local fileinuseresult = file_inuse:read("*a") or "unkown" file_inuse:close() @@ -89,21 +85,27 @@ local function checkfilefordelete ( filetodelete ) end local function checkfileforview ( path ) - local file = {} - -- Get a list of files that could be viewed + local filecontent = nil local available_files = get() - filecontent = cfe{value=nil, type="longtext", option=nil, errtxt="You are not allowed to view this file!"} for k,v in pairs(available_files) do if ( available_files[k].name == path ) then - local file = io.open( path ) - local file_result = file:read("*a") or "unknown" - file:close() - filecontent = cfe{value=file_result, type="text", option=nil, name=basename(path), errtxt=nil} + filecontent = path end end return filecontent end +function get_filedetails(self,path) + local filedetails = {} + if (checkfileforview(path)) then + filedetails.details = fs.stat(path) + filedetails.value = fs.read_file(path) + filedetails.name = basename(path) + end + return filedetails +end + + get = function (self) -- These folders (and their subfolers) are going to be listed return list_files( "/var/log", "/tmp/squid/log" ) |