Skip to content

Commit

Permalink
Merge pull request #73 from TDT-AG/tdt-fix-update-config
Browse files Browse the repository at this point in the history
[update-config] Only remove items which are not in the downloaded configuration
  • Loading branch information
nemesifier authored Oct 12, 2018
2 parents d9f2efb + 505ae53 commit 2a0008e
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions openwisp-config/files/sbin/openwisp-update-config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ if lfs.attributes(check_config_dir, 'mode') == 'directory' then
end
end
end
os.execute('rm -rf '..check_dir)

-- update UCI configuration
-- (overwrite or merge)
Expand All @@ -69,7 +68,27 @@ if lfs.attributes(remote_config_dir, 'mode') == 'directory' then
local standard_path = standard_config_dir .. '/' .. file
if lfs.attributes(standard_path, 'mode') == 'file' then
for key, section in pairs(remote:get_all(file)) do
utils.remove_uci_options(standard, file, section)
-- search section in the downloaded configuration
local section_check = check:get(file, section['.name'])
-- remove section from current configuration if not in downloaded configuration
if section_check == nil then
utils.remove_uci_options(standard, file, section)
else
-- compare each option in current and downloaded configuration
for option, value in pairs(section) do
if not utils.starts_with_dot(option) then
-- remove option from current configuration if not in downloaded configuration
if check:get(file, section['.name'], option) == nil then
standard:delete(file, section['.name'], option)
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)
-- remove uci file if empty
Expand All @@ -80,6 +99,7 @@ if lfs.attributes(remote_config_dir, 'mode') == 'directory' then
end
end
end
os.execute('rm -rf '..check_dir)

-- persist remote config in /etc/openwisp/remote
os.execute('rm -rf '..remote_dir)
Expand Down

0 comments on commit 2a0008e

Please sign in to comment.