summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2008-08-04 20:58:15 +0000
committerTed Trask <ttrask01@yahoo.com>2008-08-04 20:58:15 +0000
commitaf43f4566cf43ab0a1a700685c0286840c124d0a (patch)
tree9693a2b84db3971de2bced0220a29e8844d2463c /lib
parent1859be8e5e3325aca01fff1f2555132ebcf8afda (diff)
downloadacf-core-af43f4566cf43ab0a1a700685c0286840c124d0a.tar.bz2
acf-core-af43f4566cf43ab0a1a700685c0286840c124d0a.tar.xz
Modified getopts to allow writing to blank files and adding in a missing section.
git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@1371 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'lib')
-rw-r--r--lib/getopts.lua9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/getopts.lua b/lib/getopts.lua
index 59333db..68271b9 100644
--- a/lib/getopts.lua
+++ b/lib/getopts.lua
@@ -76,7 +76,7 @@ end
-- If the search_section is not found, we'll add it at the end of the file
-- If the search_name is not found, we'll add it at the end of the section
function setoptsinfile (file, search_section, search_name, value, to_table, optionvalue)
- if not file or file == "" or not search_name or search_name == "" or (to_table == true and not value) then
+ if not file or not search_name or search_name == "" or (to_table == true and not value) then
return false, nil, "Invalid input for getopts.setoptsinfile()", file
end
search_section = search_section or ""
@@ -268,7 +268,7 @@ function getsection (file, search_section)
end
function setsection (file, search_section, section_content)
- if not file or file == "" then
+ if not file then
return false, nil, "Invalid input for getopts.setoptsinfile()", file
end
search_section = search_section or ""
@@ -307,6 +307,11 @@ function setsection (file, search_section, section_content)
new_conf_file[#new_conf_file + 1] = l
end
+ if not done then
+ -- we didn't find the section, add it now
+ new_conf_file[#new_conf_file + 1] = '[' .. search_section .. ']\n' .. (section_content or "")
+ end
+
if (fs.is_file(file)) then
fs.write_file(file, table.concat(new_conf_file, '\n'))
else