Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[update-config] Only remove items which are not in the downloaded configuration #73

Merged
merged 1 commit into from
Oct 12, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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