cli: merge branch 'th/cli-select-by-uuid'

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1393
This commit is contained in:
Thomas Haller 2022-09-28 13:29:07 +02:00
commit 1c067fe4c6
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -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;