cli: fix resetting values via property alias

Property aliases should really just be shortcuts for one fully spelled
out property (sometimes, they do more like "master").

Anyway, we must also handle resetting the value, otherwise:

  $ nmcli connection add type gsm apn ""

will still result in "gsm.apn=internet", unlike

  $ nmcli connection add type gsm gsm.apn ""
This commit is contained in:
Thomas Haller
2021-04-26 11:45:39 +02:00
parent a97c6f70ed
commit 40032f4614
2 changed files with 14 additions and 18 deletions

4
NEWS
View File

@@ -10,7 +10,9 @@ USE AT YOUR OWN RISK. NOT RECOMMENDED FOR PRODUCTION USE!
* Add an 'accept-all-mac-addresses' property to the ethernet setting
to accept frames with any MAC address (also known as promiscuous
mode)
mode).
* nmcli: fix setting property aliases to empty value to reset the
default value.
=============================================
NetworkManager-1.30

View File

@@ -4182,23 +4182,17 @@ set_option(NmCli * nmc,
NULL);
if (option && option->check_and_set) {
return option->check_and_set(nmc, connection, option, value, error);
} else if (value) {
return set_property(nmc->client,
connection,
setting_name,
property_name,
value,
inf_flags & NM_META_PROPERTY_INF_FLAG_MULTI
? NM_META_ACCESSOR_MODIFIER_ADD
: NM_META_ACCESSOR_MODIFIER_SET,
error);
} else if (inf_flags & NM_META_PROPERTY_INF_FLAG_REQD) {
g_set_error(error,
NMCLI_ERROR,
NMC_RESULT_ERROR_USER_INPUT,
_("Error: '%s' is mandatory."),
option_name);
return FALSE;
} else {
set_property(nmc->client,
connection,
setting_name,
property_name,
value,
!value ? NM_META_ACCESSOR_MODIFIER_DEL
: (inf_flags & NM_META_PROPERTY_INF_FLAG_MULTI
? NM_META_ACCESSOR_MODIFIER_ADD
: NM_META_ACCESSOR_MODIFIER_SET),
error);
}
return TRUE;