From b1712a70f888a4cf2f766a9c1d051274f9a2a81d Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Mon, 29 Jun 2015 09:43:28 -0400 Subject: Modify listfiles to return full file details and drop non-existing files Changes file.filesize to file.size --- postfix-listfiles-html.lsp | 18 ++---------------- postfix-model.lua | 7 +++++-- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/postfix-listfiles-html.lsp b/postfix-listfiles-html.lsp index 2a5a0c4..d21b875 100644 --- a/postfix-listfiles-html.lsp +++ b/postfix-listfiles-html.lsp @@ -3,20 +3,6 @@ htmlviewfunctions = require("htmlviewfunctions") html = require("acf.html") %> -<% -function convertsize(size) - if string.find(size, "k$") then - return tonumber(string.match(size, "[%d.]*")) * 1024.0 - elseif string.find(size, "M$") then - return tonumber(string.match(size, "[%d.]*")) * 1024.0 * 1024.0 - elseif string.find(size, "G$") then - return tonumber(string.match(size, "[%d.]*")) + 1024.0 * 1024.0 * 1024.0 - else - return tonumber(string.match(size, "[%d.]*")) - end -end -%> - @@ -63,7 +49,7 @@ end %> <% end %> <%= html.html_escape(file.filename) %> - <%= convertsize(file.filesize) %>b<%= html.html_escape(file.filesize) %> + <%= html.html_escape(file.orig_size) %>b<%= html.html_escape(file.size) %> <%= html.html_escape(file.mtime) %> <% end %> diff --git a/postfix-model.lua b/postfix-model.lua index 06436e5..1c71401 100644 --- a/postfix-model.lua +++ b/postfix-model.lua @@ -66,8 +66,11 @@ function mymodule.getfilelist() local listed_files = {} for i,name in ipairs(geteditablefilelist()) do - local filedetails = fs.stat(name) or {} - table.insert ( listed_files , {filename=name, mtime=filedetails.mtime or "---", filesize=filedetails.size or "0"} ) + local filedetails = fs.stat(name) + if filedetails then + filedetails.filename = name + table.insert ( listed_files, filedetails ) + end end table.sort(listed_files, function (a,b) return (a.filename < b.filename) end ) -- cgit v1.2.3