]> git.proxmox.com Git - pve-installer.git/commitdiff
tui: fix interface sort order
authorStoiko Ivanov <s.ivanov@proxmox.com>
Fri, 17 Nov 2023 17:30:23 +0000 (18:30 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 17 Nov 2023 18:31:26 +0000 (19:31 +0100)
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>
Co-authored-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
 [ TL: avoid intermediate vector, reuse the SelectView's iter()]
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
proxmox-tui-installer/src/main.rs

index 4c1448248575facea743bd8725e76f69277501da..4b6b5b24e75e34bb9d7240effd1939afb5b4174e 100644 (file)
@@ -493,13 +493,14 @@ fn network_dialog(siv: &mut Cursive) -> InstallerView {
         .map(|iface| (iface.render(), iface.name.clone()));
     let mut ifaces_selection = SelectView::new().popup().with_all(ifnames.clone());
 
+    // sort first to always have stable view
     ifaces_selection.sort();
-    ifaces_selection.set_selection(
-        ifnames
-            .clone()
-            .position(|iface| iface.1 == options.ifname)
-            .unwrap_or(ifaces.len() - 1),
-    );
+    let selected = ifaces_selection
+        .iter()
+        .position(|(_label, iface)| *iface == options.ifname)
+        .unwrap_or(ifaces.len() - 1);
+
+    ifaces_selection.set_selection(selected);
 
     let inner = FormView::new()
         .child("Management interface", ifaces_selection)