diff --git a/openwisp-config/files/sbin/openwisp-update-config.lua b/openwisp-config/files/sbin/openwisp-update-config.lua index 78fda48..64cefba 100755 --- a/openwisp-config/files/sbin/openwisp-update-config.lua +++ b/openwisp-config/files/sbin/openwisp-update-config.lua @@ -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