diff --git a/cli/src/connections.c b/cli/src/connections.c index 3646147601..8225cce979 100644 --- a/cli/src/connections.c +++ b/cli/src/connections.c @@ -5318,8 +5318,13 @@ property_edit_submenu (NmCli *nmc, g_clear_error (&tmp_err); } g_free (option); - } else - nmc_property_set_default_value (curr_setting, prop_name); + } else { + if (!nmc_setting_reset_property (curr_setting, prop_name, &tmp_err)) { + printf (_("Error: failed to remove value of '%s': %s\n"), prop_name, + tmp_err->message); + g_clear_error (&tmp_err); + } + } break; case NMC_EDITOR_SUB_CMD_DESCRIBE: @@ -5775,6 +5780,7 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t /* Remove setting from connection, or delete value of a property */ if (!cmd_arg) { if (menu_ctx.level == 1) { + GError *tmp_err = NULL; const char *prop_name; prop_name = ask_check_property (cmd_arg, @@ -5784,7 +5790,11 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t break; /* Delete property value */ - nmc_property_set_default_value (menu_ctx.curr_setting, prop_name); + if (!nmc_setting_reset_property (menu_ctx.curr_setting, prop_name, &tmp_err)) { + printf (_("Error: failed to remove value of '%s': %s\n"), prop_name, + tmp_err->message); + g_clear_error (&tmp_err); + } } else printf (_("Error: no argument given; valid are [%s]\n"), valid_settings_str); } else { @@ -5821,7 +5831,11 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t char *prop_name = is_property_valid (ss, cmd_arg_p, &tmp_err); if (prop_name) { /* Delete property value */ - nmc_property_set_default_value (ss, prop_name); + if (!nmc_setting_reset_property (ss, prop_name, &tmp_err)) { + printf (_("Error: failed to remove value of '%s': %s\n"), prop_name, + tmp_err->message); + g_clear_error (&tmp_err); + } } else { /* If the string is not a property, try it as a setting */ NMSetting *s_tmp; diff --git a/cli/src/settings.c b/cli/src/settings.c index fb2369dde3..6d7a7908e3 100644 --- a/cli/src/settings.c +++ b/cli/src/settings.c @@ -4769,6 +4769,32 @@ nmc_property_set_default_value (NMSetting *setting, const char *prop) } } +/* + * Generic function for reseting (single value) properties. + * + * The function resets the property value to the default one. It respects + * nmcli restrictions for changing properties. So if 'set_func' is NULL, + * reseting the value is denied. + * + * Returns: TRUE on success; FALSE on failure and sets error + */ +gboolean +nmc_setting_reset_property (NMSetting *setting, const char *prop, GError **error) +{ + const NmcPropertyFuncs *item; + + g_return_val_if_fail (NM_IS_SETTING (setting), FALSE); + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + item = nmc_properties_find (nm_setting_get_name (setting), prop); + if (item && item->set_func) { + nmc_property_set_default_value (setting, prop); + return TRUE; + } + g_set_error_literal (error, 1, 0, _("the property can't be changed")); + return FALSE; +} + /* * Generic function for removing items for collection-type properties. * diff --git a/cli/src/settings.h b/cli/src/settings.h index 84fa3bae22..8c14364c60 100644 --- a/cli/src/settings.h +++ b/cli/src/settings.h @@ -66,6 +66,9 @@ gboolean nmc_setting_set_property (NMSetting *setting, const char *prop, const char *val, GError **error); +gboolean nmc_setting_reset_property (NMSetting *setting, + const char *prop, + GError **error); gboolean nmc_setting_remove_property_option (NMSetting *setting, const char *prop, const char *option,