summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2009-01-13 16:01:06 +0000
committerTed Trask <ttrask01@yahoo.com>2009-01-13 16:01:06 +0000
commit168d1ee9a8eaf3142e76e4e8b04cc39b5b1769c3 (patch)
treedc407ffb93a17b5c1cc9f65d656d53b3fe29e48c
parent1b185b43be5d6fab2fc0bd46690aae84e5ab6d14 (diff)
downloadacf-dhcp-168d1ee9a8eaf3142e76e4e8b04cc39b5b1769c3.tar.bz2
acf-dhcp-168d1ee9a8eaf3142e76e4e8b04cc39b5b1769c3.tar.xz
Modified fs.lua to survive nil parameters. Added create_directory and used within create_file and write_file. Reviewed each read_file call to make sure handles nil return value.
git-svn-id: svn://svn.alpinelinux.org/acf/dhcp/trunk@1677 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r--dhcp-model.lua20
1 files changed, 10 insertions, 10 deletions
diff --git a/dhcp-model.lua b/dhcp-model.lua
index ccbbb57..d5a676f 100644
--- a/dhcp-model.lua
+++ b/dhcp-model.lua
@@ -192,7 +192,7 @@ local find_section_end = function(file, section_start)
end
local host_write = function(host)
- local file = fs.read_file(configfile)
+ local file = fs.read_file(configfile) or ""
config = config or parseconfigfile(file)
-- First, add the host line if necessary
@@ -249,7 +249,7 @@ local host_write = function(host)
end
local subnet_write = function(net)
- local file = fs.read_file(configfile)
+ local file = fs.read_file(configfile) or ""
config = config or parseconfigfile(file)
-- First, add or update the submet line
@@ -414,7 +414,7 @@ create_new_host = function()
end
host_read = function( name )
- config = config or parseconfigfile(fs.read_file(configfile))
+ config = config or parseconfigfile(fs.read_file(configfile) or "")
local host = create_new_host()
host.value.host.value = name
@@ -480,7 +480,7 @@ host_create = function( host )
end
host_delete = function(name)
- local file = fs.read_file(configfile)
+ local file = fs.read_file(configfile) or ""
config = config or parseconfigfile(file)
local cmdresult = cfe({ value="Failed to delete host - not found", label="Delete host result" })
local hosts = get_hosts()
@@ -500,7 +500,7 @@ host_delete = function(name)
end
get_hosts = function ()
- config = config or parseconfigfile(fs.read_file(configfile))
+ config = config or parseconfigfile(fs.read_file(configfile) or "")
local retval = {}
for i,entry in ipairs(config) do
if string.lower(entry[1] or "") == "host" then
@@ -530,7 +530,7 @@ create_new_subnet = function()
end
subnet_read = function( name )
- config = config or parseconfigfile(fs.read_file(configfile))
+ config = config or parseconfigfile(fs.read_file(configfile) or "")
local net = create_new_subnet()
net.value.subnet.value = name
local pools = 0
@@ -639,7 +639,7 @@ subnet_create = function( net )
end
subnet_delete = function(name)
- local file = fs.read_file(configfile)
+ local file = fs.read_file(configfile) or ""
config = config or parseconfigfile(file)
local cmdresult = cfe({ value="Failed to delete subnet - not found", label="Delete subnet result" })
local subnets = get_subnets()
@@ -659,7 +659,7 @@ subnet_delete = function(name)
end
get_subnets = function ()
- config = config or parseconfigfile(fs.read_file(configfile))
+ config = config or parseconfigfile(fs.read_file(configfile) or "")
local retval = {}
for i,entry in ipairs(config) do
if string.lower(entry[1] or "") == "subnet" then
@@ -671,7 +671,7 @@ get_subnets = function ()
end
read_settings = function()
- config = config or parseconfigfile(fs.read_file(configfile))
+ config = config or parseconfigfile(fs.read_file(configfile) or "")
local settings = {}
settings.domainname = cfe({ label="Domain Name" })
settings.domainnameservers = cfe({ label="Domain Name Servers", descr="Comma-separated addresses" })
@@ -700,7 +700,7 @@ end
update_settings = function ( settings )
success, settings = validate_settings(settings)
if success then
- local file = fs.read_file(configfile)
+ local file = fs.read_file(configfile) or ""
config = config or parseconfigfile(file)
-- set up the lines we want to enter