diff --git a/openwisp-config/files/sbin/openwisp-update-config.lua b/openwisp-config/files/sbin/openwisp-update-config.lua index e7ba722..d5deaa4 100755 --- a/openwisp-config/files/sbin/openwisp-update-config.lua +++ b/openwisp-config/files/sbin/openwisp-update-config.lua @@ -148,7 +148,7 @@ 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) then + if (not utils.file_exists(stored_path) and not utils.file_exists(remote_path)) then os.execute('cp '..standard_path..' '..stored_path) end -- MERGE mode diff --git a/openwisp-config/tests/test_update_config.lua b/openwisp-config/tests/test_update_config.lua index 6265f8f..48e7051 100644 --- a/openwisp-config/tests/test_update_config.lua +++ b/openwisp-config/tests/test_update_config.lua @@ -123,16 +123,11 @@ function TestUpdateConfig.test_update() luaunit.assertNotNil(restoreFile) luaunit.assertEquals(restoreFile:read('*all'), 'restore-me\n') luaunit.assertNil(io.open(openwisp_dir..'/stored/etc/restore-me')) - -- ensure network configuration file is backed up - local storedNetworkFile = io.open(stored_dir .. '/etc/config/network') - luaunit.assertNotNil(storedNetworkFile) - local initialNetworkFile = io.open('update/network') - luaunit.assertEquals(storedNetworkFile:read('*all'), initialNetworkFile:read('*all')) - -- ensure system configuration file is backed up + -- ensure network and configuration file is not backed up as it is coming from remote + local storedNetworkFile = io.open(openwisp_dir .. '/etc/config/network') + luaunit.assertNil(storedNetworkFile) local storedSystemFile = io.open(stored_dir .. '/etc/config/system') - luaunit.assertNotNil(storedSystemFile) - local initialSystemFile = io.open('update/system') - luaunit.assertEquals(storedSystemFile:read('*all'), initialSystemFile:read('*all')) + luaunit.assertNil(storedSystemFile) end function TestUpdateConfig.test_update_conf_arg()