summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2016-03-11 14:58:56 +0000
committerTed Trask <ttrask01@yahoo.com>2016-03-11 14:58:56 +0000
commitb852f09ad5d7acd6dbf5dad08fa7401634c70035 (patch)
tree9567f401a846bb2b85428f4e65bb19cdb560f271
parent79f8431289ac679652005707351c799d503f48ad (diff)
downloadacf-provisioning-b852f09ad5d7acd6dbf5dad08fa7401634c70035.tar.bz2
acf-provisioning-b852f09ad5d7acd6dbf5dad08fa7401634c70035.tar.xz
Fix bulkcreatedevices to handle DOS line endings and blank lines
-rw-r--r--provisioning-model.lua12
1 files changed, 9 insertions, 3 deletions
diff --git a/provisioning-model.lua b/provisioning-model.lua
index 57880b5..943267e 100644
--- a/provisioning-model.lua
+++ b/provisioning-model.lua
@@ -2387,7 +2387,9 @@ mymodule.bulk_create_devices = function(self, devicelist)
-- To allow uploading a file, check the bulkdevicedata format
-- Haserl will pass a temporary file name if a file is uploaded
if #devicelist.value.bulkdevicedata.value == 1 and string.find(devicelist.value.bulkdevicedata.value[1], "^/tmp/[^.]+$") and fs.is_file(devicelist.value.bulkdevicedata.value[1]) then
- devicelist.value.bulkdevicedata.value = fs.read_file_as_array(devicelist.value.bulkdevicedata.value[1]) or {}
+ -- Need to account for possible DOS line endings
+ --devicelist.value.bulkdevicedata.value = fs.read_file_as_array(devicelist.value.bulkdevicedata.value[1]) or {}
+ devicelist.value.bulkdevicedata.value = format.string_to_table(fs.read_file(devicelist.value.bulkdevicedata.value[1]), "\r?\n")
end
local res, err = pcall(function()
connected = databaseconnect()
@@ -2439,7 +2441,11 @@ mymodule.bulk_create_devices = function(self, devicelist)
reverseheaders[h] = i
end
- for i=2,#devicelist.value.bulkdevicedata.value do
+ -- The repeat at the end of the line gives us a 'continue'-like feature by calling break
+ -- see http://stackoverflow.com/a/13825260
+ for i=2,#devicelist.value.bulkdevicedata.value do repeat
+ -- continue if blank line
+ if "" == devicelist.value.bulkdevicedata.value[i] then break end
local values = csv_parseline(devicelist.value.bulkdevicedata.value[i], ",")
-- Create the device
@@ -2525,7 +2531,7 @@ mymodule.bulk_create_devices = function(self, devicelist)
if params.errtxt then
error("Failed to create device in line "..i.."\n"..params:print_errtxt())
end
- end
+ until true end
if connected then databasedisconnect() end
end)
if not res and err then