From e840dfdc1f9cb640007a7dd52c1d0bbeab533f44 Mon Sep 17 00:00:00 2001 From: Olivier Blin Date: Fri, 5 Aug 2005 13:47:38 +0000 Subject: overwrite previous wpa_supplicant entries with same ssid or bssid --- perl-install/network/wireless.pm | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/perl-install/network/wireless.pm b/perl-install/network/wireless.pm index bdfc9fd55..784d45851 100644 --- a/perl-install/network/wireless.pm +++ b/perl-install/network/wireless.pm @@ -99,7 +99,7 @@ sub wpa_supplicant_get_driver { sub wpa_supplicant_add_network { my ($essid, $enc_mode, $key) = @_; my $conf = wpa_supplicant_read_conf(); - push @$conf, { + my $network = { ssid => qq("$essid"), scan_ssid => 1, $enc_mode eq 'wpa-psk' ? @@ -115,9 +115,19 @@ sub wpa_supplicant_add_network { ) : () }; + @$conf = difference2($conf, [ wpa_supplicant_find_similar($conf, $network) ]); + push @$conf, $network; wpa_supplicant_write_conf($conf); } +sub wpa_supplicant_find_similar { + my ($conf, $network) = @_; + grep { + my $current = $_; + any { exists $network->{$_} && $network->{$_} eq $current->{$_} } qw(ssid bssid); + } @$conf; +} + sub wpa_supplicant_read_conf() { my @conf; my $network; @@ -154,11 +164,7 @@ sub wpa_supplicant_write_conf { #- end of network block, write it $buf .= "network={$network->{comment}\n"; - my $new_network = find { - my $current = $_; - any { exists $network->{$_} && $network->{$_} eq $current->{$_} } qw(ssid bssid); - } @conf; - + my $new_network = first(wpa_supplicant_find_similar(\@conf, $network)); foreach (@{$network->{entries}}) { my $key = $_->{key}; if ($new_network) { -- cgit v1.2.1