Skip to content

Commit 668de1d

Browse files
[fix] Use stored dir for storing configuration and minor changes #153
Store only when configuration is not in remote Close #153
1 parent f08c7df commit 668de1d

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

openwisp-config/files/sbin/openwisp-update-config.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ local test_root_dir = working_dir .. '/update-test'
3232
local remote_dir = openwisp_dir .. '/remote'
3333
local remote_config_dir = remote_dir .. '/etc/config'
3434
local stored_dir = openwisp_dir .. '/stored'
35-
local stored_config_dir = openwisp_dir .. '/etc/config'
35+
local stored_config_dir = stored_dir .. '/etc/config'
3636
local added_file = openwisp_dir .. '/added.list'
3737
local modified_file = openwisp_dir .. '/modified.list'
3838
local get_standard = function() return uci.cursor(standard_config_dir) end
@@ -84,8 +84,8 @@ if lfs.attributes(remote_config_dir, 'mode') == 'directory' then
8484
if section_stored == nil then
8585
utils.remove_uci_options(standard, file, section)
8686
-- section is in the backup configuration -> restore
87-
-- delete all options first
8887
else
88+
-- delete all options first
8989
for option, value in pairs(section) do
9090
if not utils.starts_with_dot(option) then
9191
standard:delete(file, section['.name'], option)
@@ -148,7 +148,7 @@ if lfs.attributes(remote_config_dir, 'mode') == 'directory' then
148148
-- ensure we are acting on a file
149149
if lfs.attributes(remote_path, 'mode') == 'file' then
150150
-- if there's no backup of the file yet, create one
151-
if not utils.file_exists(stored_path) then
151+
if (not utils.file_exists(stored_path) and not utils.file_exists(remote_path)) then
152152
os.execute('cp '..standard_path..' '..stored_path)
153153
end
154154
-- MERGE mode

openwisp-config/tests/test_update_config.lua

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ local update_config = assert(loadfile("../files/sbin/openwisp-update-config.lua"
77
local write_dir = './update-test/'
88
local config_dir = write_dir .. 'etc/config/'
99
local openwisp_dir = './openwisp/'
10+
local stored_dir = openwisp_dir .. '/stored/'
1011
local remote_config_dir = openwisp_dir .. 'remote/etc/config'
1112

1213
local function string_count(base, pattern)
@@ -38,8 +39,8 @@ TestUpdateConfig = {
3839
os.execute('echo restore-me > '..openwisp_dir..'/stored/etc/restore-me')
3940
os.execute('echo /etc/restore-me > '..openwisp_dir..'/modified.list')
4041
-- this file is stored in the backup
41-
os.execute('mkdir -p ' .. openwisp_dir ..'etc/config/')
42-
os.execute("cp ./update/stored_wireless " ..openwisp_dir.. '/etc/config/wireless')
42+
os.execute('mkdir -p ' .. stored_dir ..'etc/config/')
43+
os.execute("cp ./update/stored_wireless " ..stored_dir.. '/etc/config/wireless')
4344
end,
4445
tearDown = function()
4546
os.execute('rm -rf ' .. write_dir)
@@ -123,12 +124,12 @@ function TestUpdateConfig.test_update()
123124
luaunit.assertEquals(restoreFile:read('*all'), 'restore-me\n')
124125
luaunit.assertNil(io.open(openwisp_dir..'/stored/etc/restore-me'))
125126
-- ensure network configuration file is backed up
126-
local storedNetworkFile = io.open(openwisp_dir .. '/etc/config/network')
127+
local storedNetworkFile = io.open(stored_dir .. '/etc/config/network')
127128
luaunit.assertNotNil(storedNetworkFile)
128129
local initialNetworkFile = io.open('update/network')
129130
luaunit.assertEquals(storedNetworkFile:read('*all'), initialNetworkFile:read('*all'))
130131
-- ensure system configuration file is backed up
131-
local storedSystemFile = io.open(openwisp_dir .. '/etc/config/system')
132+
local storedSystemFile = io.open(stored_dir .. '/etc/config/system')
132133
luaunit.assertNotNil(storedSystemFile)
133134
local initialSystemFile = io.open('update/system')
134135
luaunit.assertEquals(storedSystemFile:read('*all'), initialSystemFile:read('*all'))

0 commit comments

Comments
 (0)