[pve-devel] [PATCH installer] tui: fix interface sort order

Stoiko Ivanov s.ivanov at proxmox.com
Fri Nov 17 18:30:23 CET 2023


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 at 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






More information about the pve-devel mailing list