From c69ac570705d815f6c0406169f307c71b8376398 Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Fri, 4 Apr 2008 13:00:17 +0000 Subject: Showing config errors in expert tab. git-svn-id: svn://svn.alpinelinux.org/acf/alpine-conf/trunk@922 ab2d0c66-481e-0410-8bed-d214d4d58bed --- lbu-model.lua | 62 +++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 43 insertions(+), 19 deletions(-) (limited to 'lbu-model.lua') diff --git a/lbu-model.lua b/lbu-model.lua index 044d877..da5e22c 100644 --- a/lbu-model.lua +++ b/lbu-model.lua @@ -287,35 +287,59 @@ function editconfig (self,variable,value) return value end function get_filedetails() - local filedetails = {} local path = configfile - local filestats = fs.stat(path) - filedetails.name = cfe ({ - name="name", + local file = {} + local filedetails = {} + local config = {} + local filenameerrtxt + if (fs.is_file(path)) then + filedetails = fs.stat(path) + config = getconfig(path) + else + config = {} + config.filename = {} + config["filename"]["errtxt"]="Config file '".. path .. "' is missing!" + end + + file["filename"] = cfe({ + name="filename", + label="File name", value=path, - label="File name" + errtxt=filenameerrtxt }) - - filedetails.size = cfe ({ - name="size", - value=filestats.size or "0", + file["filesize"] = cfe({ + name="filesize", label="File size", + value=filedetails.size or 0, }) - - filedetails.mtime = cfe ({ + file["mtime"] = cfe({ name="mtime", - value=filestats.mtime or "---", - label="File modified", + label="File date", + value=filedetails.mtime or "---", }) - - filedetails.modifications = cfe ({ - name="modifications", - value=fs.read_file(path), - label="File content", + file["filecontent"] = cfe({ type="longtext", + name="filecontent", + label="File content", + value=fs.read_file(path), }) - return filedetails + -- Sum all errors into one cfe + local sumerrors = "" + for k,v in pairs(config) do + if (config[k]) and (config[k]["errtxt"]) and (config[k]["errtxt"] ~= "") then + sumerrors = sumerrors .. config[k]["errtxt"] .. "\n" + end + end + if (sumerrors ~= "") then + file["sumerrors"] = cfe ({ + name="sumerrors", + label = "Configuration errors", + errtxt = string.match(sumerrors, "(.-)\n$"), + }) + end + + return file end function update_filecontent (self, modifications) local path = configfile -- cgit v1.2.3