From f6baf459cde6258511c94c0e1324d630af675cb5 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Fri, 11 Jul 2008 20:52:58 +0000 Subject: Modified modelfunctios to add setfiledetails and add validation to getfiledetils. git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@1297 ab2d0c66-481e-0410-8bed-d214d4d58bed --- lib/modelfunctions.lua | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'lib/modelfunctions.lua') diff --git a/lib/modelfunctions.lua b/lib/modelfunctions.lua index 1cd19a9..0e81d75 100644 --- a/lib/modelfunctions.lua +++ b/lib/modelfunctions.lua @@ -44,7 +44,7 @@ function getstatus(processname, packagename, label) return cfe({ type="group", value=status, label=label }) end -function getfiledetails(file) +function getfiledetails(file, validatefunction) local filename = cfe({ value=file, label="File name" }) local filecontent = cfe({ type="longtext", label="File content" }) local filesize = cfe({ value="0", label="File size" }) @@ -57,7 +57,28 @@ function getfiledetails(file) else filename.errtxt = "File not found" end - return cfe({ type="group", value={filename=filename, filecontent=filecontent, filesize=filesize, mtime=mtime}, label="Config file details" }) + local filedetails = cfe({ type="group", value={filename=filename, filecontent=filecontent, filesize=filesize, mtime=mtime}, label="Config file details" }) + local success = true + if validatefunction then + success, filedetails = validatefunction(filedetails) + end + return filedetails +end + +function setfiledetails(filedetails, validatefunction) + filedetails.value.filecontent.value = string.gsub(format.dostounix(filedetails.value.filecontent.value), "\n+$", "") + local success = true + if validatefunction then + success, filedetails = validatefunction(filedetails) + end + if success then + fs.write_file(filedetails.value.filename.value, filedetails.value.filecontent.value) + filedetails = getfiledetails(filedetails.value.filename.value) + else + filedetails.errtxt = "Failed to set file" + end + + return filedetails end function validateselect(select) -- cgit v1.2.3