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

Thomas Lamprecht t.lamprecht at proxmox.com
Fri Nov 17 19:34:34 CET 2023


Am 17/11/2023 um 18:30 schrieb Stoiko Ivanov:
> 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(-)
> 
>

applied, thanks!

as talked off-list, I remolded this to avoid a separate vector by re-using the
SelectView's data, which is already sorted:

diff --git a/proxmox-tui-installer/src/main.rs b/proxmox-tui-installer/src/main.rs
index 4c14482..4b6b5b2 100644
--- a/proxmox-tui-installer/src/main.rs
+++ b/proxmox-tui-installer/src/main.rs
@@ -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)





More information about the pve-devel mailing list