From: Stoiko Ivanov <s.ivanov@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH installer] tui: fix interface sort order
Date: Fri, 17 Nov 2023 18:30:23 +0100 [thread overview]
Message-ID: <20231117173023.1484541-1-s.ivanov@proxmox.com> (raw)
currently when multiple nics are present in a system the TUI
sometimes selects the wrong interface (not the one that has the
default gateway/dhcp lease)
I assume this is due to HashMap's values yielding an iterator in
arbitrary order
Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
---
sadly a bit difficult to test due to the randomnes - but at least the 3
tests on a VM were consistent.
proxmox-tui-installer/src/main.rs | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/proxmox-tui-installer/src/main.rs b/proxmox-tui-installer/src/main.rs
index 4c14482..85b6811 100644
--- a/proxmox-tui-installer/src/main.rs
+++ b/proxmox-tui-installer/src/main.rs
@@ -488,16 +488,23 @@ fn network_dialog(siv: &mut Cursive) -> InstallerView {
let state = siv.user_data::<InstallerState>().unwrap();
let options = &state.options.network;
let ifaces = state.runtime_info.network.interfaces.values();
- let ifnames = ifaces
+ let ifname_entries = ifaces
.clone()
.map(|iface| (iface.render(), iface.name.clone()));
- let mut ifaces_selection = SelectView::new().popup().with_all(ifnames.clone());
+ let mut ifaces_selection = SelectView::new().popup().with_all(ifname_entries.clone());
+
+ let mut ifnames = ifaces
+ .clone()
+ .map(|iface| iface.name.clone())
+ .collect::<Vec<String>>();
+ ifnames.sort();
ifaces_selection.sort();
ifaces_selection.set_selection(
ifnames
+ .iter()
.clone()
- .position(|iface| iface.1 == options.ifname)
+ .position(|iface| *iface == options.ifname)
.unwrap_or(ifaces.len() - 1),
);
--
2.39.2
next reply other threads:[~2023-11-17 17:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-17 17:30 Stoiko Ivanov [this message]
2023-11-17 18:34 ` [pve-devel] applied: " Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231117173023.1484541-1-s.ivanov@proxmox.com \
--to=s.ivanov@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.