Skip to content

Commit

Permalink
[refactor] Remove unnecessary if block
Browse files Browse the repository at this point in the history
  • Loading branch information
devkapilbansal committed Dec 2, 2021
1 parent 21358d6 commit 0d15300
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions openwisp-config/files/sbin/openwisp-update-config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -154,34 +154,33 @@ if lfs.attributes(remote_config_dir, 'mode') == 'directory' then
-- if there's no backup of the file yet, create one
if not utils.file_exists(stored_path) then
os.execute('cp ' .. standard_path .. ' ' .. stored_path)
if utils.file_exists(remote_path) then
for key, section in pairs(stored:get_all(file)) do
-- check if section is in remote configuration
local section_check = check:get(file, section['.name'])
if section_check then
-- check if options is in remote configuration
for option, value in pairs(section) do
if not utils.starts_with_dot(option) then
local option_check = check:get(file, section['.name'], option)
if option_check then
-- if option is in remote configuration, remove it
stored:delete(file, section['.name'], option)
end

for _, section in pairs(stored:get_all(file)) do
-- check if section is in remote configuration
local section_check = check:get(file, section['.name'])
if section_check then
-- check if options is in remote configuration
for option, value in pairs(section) do
if not utils.starts_with_dot(option) then
local option_check = check:get(file, section['.name'], option)
if option_check then
-- if option is in remote configuration, remove it
stored:delete(file, section['.name'], option)
end
end
-- remove entire section if empty
local result = stored:get_all(file, section['.name'])
if result and utils.is_uci_empty(result) then
stored:delete(file, section['.name'])
end
end
-- remove entire section if empty
local result = stored:get_all(file, section['.name'])
if result and utils.is_uci_empty(result) then
stored:delete(file, section['.name'])
end
end
stored:commit(file)
-- remove uci file if empty
local uci_file = stored:get_all(file)
if uci_file and utils.is_table_empty(uci_file) then
os.remove(stored_path)
end
end
stored:commit(file)
-- remove uci file if empty
local uci_file = stored:get_all(file)
if uci_file and utils.is_table_empty(uci_file) then
os.remove(stored_path)
end
end
-- MERGE mode
Expand Down

0 comments on commit 0d15300

Please sign in to comment.