Skip to content

Commit

Permalink
[change] Remove options and sections coming from remote configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
devkapilbansal committed Nov 29, 2021
1 parent 10f0740 commit e39625f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
31 changes: 25 additions & 6 deletions openwisp-config/files/sbin/openwisp-update-config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,6 @@ if lfs.attributes(remote_config_dir, 'mode') == 'directory' then
end
end
end
-- remove entire section if empty
local result = standard:get_all(file, section['.name'])
if result and utils.is_uci_empty(result) then
standard:delete(file, section['.name'])
end
end
end
standard:commit(file)
Expand Down Expand Up @@ -148,8 +143,32 @@ if lfs.attributes(remote_config_dir, 'mode') == 'directory' then
-- ensure we are acting on a file
if lfs.attributes(remote_path, 'mode') == 'file' then
-- if there's no backup of the file yet, create one
if (not utils.file_exists(stored_path) and not utils.file_exists(remote_path)) then
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 ~= nil 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 ~= nil then
-- if option is in remote configuration, remove it
stored:delete(file, section['.name'], option)
end
end
end
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
end
-- MERGE mode
if MERGE then
Expand Down
2 changes: 1 addition & 1 deletion openwisp-config/tests/test_update_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function TestUpdateConfig.test_update()
-- ensure network and configuration file is not backed up as it is overwritten by remote
local storedNetworkFile = io.open(openwisp_dir .. '/etc/config/network')
luaunit.assertNil(storedNetworkFile)
local storedSystemFile = io.open(stored_dir .. '/etc/config/system')
local storedSystemFile = io.open(openwisp_dir .. '/etc/config/system')
luaunit.assertNil(storedSystemFile)
end

Expand Down

0 comments on commit e39625f

Please sign in to comment.