diff options
author | Ted Trask <ttrask01@yahoo.com> | 2008-07-11 20:52:58 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2008-07-11 20:52:58 +0000 |
commit | f6baf459cde6258511c94c0e1324d630af675cb5 (patch) | |
tree | eae0ea9ed851e1a527987044fe8263ae09b9b0fd | |
parent | 43a9488d38abb2ea6001afd8c6c36433bf44bc71 (diff) | |
download | acf-core-f6baf459cde6258511c94c0e1324d630af675cb5.tar.bz2 acf-core-f6baf459cde6258511c94c0e1324d630af675cb5.tar.xz |
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
-rw-r--r-- | lib/modelfunctions.lua | 25 |
1 files changed, 23 insertions, 2 deletions
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) |