From 368d659a675f2682ab8d1d2c9dad12928f49bfb4 Mon Sep 17 00:00:00 2001 From: Jamie McClelland Date: Tue, 21 Dec 2010 23:22:21 -0500 Subject: On dkg's suggestion, using hash index as more elegant way to ensure we don't repeat users. --- examples/monkeysphere-monitor-keys | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/examples/monkeysphere-monitor-keys b/examples/monkeysphere-monitor-keys index 562c896..a5877d6 100755 --- a/examples/monkeysphere-monitor-keys +++ b/examples/monkeysphere-monitor-keys @@ -128,7 +128,7 @@ sub get_watcher { sub watch { my $watcher = get_watcher(); while ( my @events = $watcher->wait_for_events() ) { - my @users; + my %users; for my $event (@events) { if($event->path eq "$user_update_file") { debug("Reloading user list\n"); @@ -142,23 +142,17 @@ sub watch { # file is gone. if( -f $event->path) { my $username = $watch_files { $event->path }; - - # FIXME: this seems like it is trying to treat an array as a - # set. Maybe it'd be better to use the keys of a hash (or - # hashref) instead? - if ( !grep $_ eq $username, @users ) { - push(@users,$username); - } + $users{ $username } = 1; } } } - for my $user (@users) { - debug("Updating user: %s\n", $user); + for ((my $username) = each(%users)) { + debug("Updating user: %s\n", $username); # FIXME: this call blocks until m-a u finishes running, i think. # what happens if other changes occur in the meantime? Can we # rate-limit this? Could we instead spawn child processes that # run this command directly? - system('monkeysphere-authentication', 'update-users', $user); + system('monkeysphere-authentication', 'update-users', $username); } } } -- cgit v1.2.3