diff options
author | Ted Trask <ttrask01@yahoo.com> | 2016-03-11 14:58:56 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2016-03-11 15:03:00 +0000 |
commit | b7ee8e7ea3c182f4b1b96f2d6d914c83378932e6 (patch) | |
tree | aecd1c7129c8d3dd08a46421475b88454d36ff1f | |
parent | f4904bb1976d0ccf426b7f554455ef5ddaf44a97 (diff) | |
download | acf-provisioning-b7ee8e7ea3c182f4b1b96f2d6d914c83378932e6.tar.bz2 acf-provisioning-b7ee8e7ea3c182f4b1b96f2d6d914c83378932e6.tar.xz |
Fix bulkcreatedevices to handle DOS line endings and blank lines
(cherry picked from commit b852f09ad5d7acd6dbf5dad08fa7401634c70035)
-rw-r--r-- | provisioning-model.lua | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/provisioning-model.lua b/provisioning-model.lua index 983363c..169ff22 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 |