@@ -24,7 +24,7 @@ use crate::repeat_keyword::{
2424 RepeatInput , RepeatListInput , NameValueEntry ,
2525 add_or_update_entry, extract_single_keyword, remove_entry, parse_and_validate_entries
2626} ;
27- use crate :: util:: { build_command_info, get_default_sshd_config_path, invoke_sshd_config_validation} ;
27+ use crate :: util:: { build_command_info, ensure_sshd_config_exists , get_default_sshd_config_path, invoke_sshd_config_validation} ;
2828
2929/// Invoke the set command.
3030///
@@ -189,16 +189,9 @@ fn set_sshd_config(cmd_info: &mut CommandInfo) -> Result<(), SshdConfigError> {
189189 let mut get_cmd_info = cmd_info. clone ( ) ;
190190 get_cmd_info. include_defaults = false ;
191191 get_cmd_info. input = Map :: new ( ) ;
192+ ensure_sshd_config_exists ( get_cmd_info. metadata . filepath . clone ( ) ) ?;
192193
193- let mut existing_config = match get_sshd_settings ( & get_cmd_info, true ) {
194- Ok ( config) => config,
195- Err ( SshdConfigError :: FileNotFound ( _) ) => {
196- return Err ( SshdConfigError :: InvalidInput (
197- t ! ( "set.purgeFalseRequiresExistingFile" ) . to_string ( )
198- ) ) ;
199- }
200- Err ( e) => return Err ( e) ,
201- } ;
194+ let mut existing_config = get_sshd_settings ( & get_cmd_info, true ) ?;
202195 for ( key, value) in & cmd_info. input {
203196 if value. is_null ( ) {
204197 existing_config. remove ( key) ;
@@ -281,12 +274,6 @@ fn get_existing_config(cmd_info: &CommandInfo) -> Result<Map<String, Value>, Ssh
281274 let mut get_cmd_info = cmd_info. clone ( ) ;
282275 get_cmd_info. include_defaults = false ;
283276 get_cmd_info. input = Map :: new ( ) ;
284- match get_sshd_settings ( & get_cmd_info, false ) {
285- Ok ( config) => Ok ( config) ,
286- Err ( SshdConfigError :: FileNotFound ( _) ) => {
287- // If file doesn't exist, create empty config
288- Ok ( Map :: new ( ) )
289- }
290- Err ( e) => Err ( e) ,
291- }
277+ ensure_sshd_config_exists ( get_cmd_info. metadata . filepath . clone ( ) ) ?;
278+ get_sshd_settings ( & get_cmd_info, false )
292279}
0 commit comments