@@ -112,11 +112,6 @@ if lfs.attributes(remote_config_dir, 'mode') == 'directory' then
112112 end
113113 end
114114 end
115- -- remove entire section if empty
116- local result = standard :get_all (file , section [' .name' ])
117- if result and utils .is_uci_empty (result ) then
118- standard :delete (file , section [' .name' ])
119- end
120115 end
121116 end
122117 standard :commit (file )
@@ -148,8 +143,32 @@ if lfs.attributes(remote_config_dir, 'mode') == 'directory' then
148143 -- ensure we are acting on a file
149144 if lfs .attributes (remote_path , ' mode' ) == ' file' then
150145 -- if there's no backup of the file yet, create one
151- if (not utils .file_exists (stored_path ) and not utils . file_exists ( remote_path ) ) then
146+ if (not utils .file_exists (stored_path )) then
152147 os.execute (' cp ' .. standard_path .. ' ' .. stored_path )
148+ if (utils .file_exists (remote_path )) then
149+ for key , section in pairs (stored :get_all (file )) do
150+ -- check if section is in remote configuration
151+ local section_check = check :get (file , section [' .name' ])
152+ if section_check ~= nil then
153+ -- check if options is in remote configuration
154+ for option , value in pairs (section ) do
155+ if not utils .starts_with_dot (option ) then
156+ local option_check = check :get (file , section [' .name' ], option )
157+ if option_check ~= nil then
158+ -- if option is in remote configuration, remove it
159+ stored :delete (file , section [' .name' ], option )
160+ end
161+ end
162+ end
163+ end
164+ end
165+ stored :commit (file )
166+ -- remove uci file if empty
167+ local uci_file = stored :get_all (file )
168+ if uci_file and utils .is_table_empty (uci_file ) then
169+ os.remove (stored_path )
170+ end
171+ end
153172 end
154173 -- MERGE mode
155174 if MERGE then
0 commit comments