diff options
author | Thomas Haller <thaller@redhat.com> | 2022-09-28 13:29:07 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2022-09-28 13:29:07 +0200 |
commit | 1c067fe4c69047260544e3ce40201835a75e952e (patch) | |
tree | c9695715fff5d07b56f758ff25977369466f1801 | |
parent | 98197386078a471ed993d009e34e08a6aa7c22d9 (diff) | |
parent | 046e36b4fd7a8c52061657d94d0279ed5978136e (diff) |
cli: merge branch 'th/cli-select-by-uuid'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1393
-rw-r--r-- | src/nmcli/common.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/nmcli/common.c b/src/nmcli/common.c index ff4c15c37e..ad67a81043 100644 --- a/src/nmcli/common.c +++ b/src/nmcli/common.c @@ -432,10 +432,13 @@ nmc_find_connection(const GPtrArray *connections, GPtrArray *result = out_result ? *out_result : NULL; const guint result_inital_len = result ? result->len : 0u; guint i, j; + gboolean must_match_uniquely; nm_assert(connections); nm_assert(filter_val); + must_match_uniquely = NM_IN_STRSET(filter_type, "uuid", "path"); + for (i = 0; i < connections->len; i++) { gboolean match_by_uuid = FALSE; NMConnection *connection; @@ -452,6 +455,12 @@ nmc_find_connection(const GPtrArray *connections, match_by_uuid = TRUE; goto found; } + if (filter_type && !nm_str_is_empty(filter_val) && g_str_has_prefix(v, filter_val)) { + /* If the selector is qualified by "uuid", prefix matches for the UUID are + * also OK. At least, if they result in a unique match. */ + nm_assert(must_match_uniquely); + goto found; + } } if (NM_IN_STRSET(filter_type, NULL, "id")) { @@ -483,14 +492,26 @@ nmc_find_connection(const GPtrArray *connections, continue; found: + + if (must_match_uniquely && (best_candidate || best_candidate_uuid)) { + /* We found duplicates. This is wrong. */ + if (out_result && *out_result) { + /* Remove the element that we added before. */ + g_ptr_array_set_size(*out_result, result_inital_len); + } + return NULL; + } + if (match_by_uuid) { if (!complete && !out_result) return connection; - best_candidate_uuid = connection; + if (!best_candidate_uuid) + best_candidate_uuid = connection; } else { if (!best_candidate) best_candidate = connection; } + if (out_result) { gboolean already_tracked = FALSE; |