From d4aada92487fdaab6cbd3ad52f7f43830695d66b Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Sun, 27 Sep 2015 10:43:46 -0700 Subject: [PATCH] Cache status of a password file, rather than re-reading it over and over --- useradmin/user-lib.pl | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/useradmin/user-lib.pl b/useradmin/user-lib.pl index 41d90a9fe..75291c299 100755 --- a/useradmin/user-lib.pl +++ b/useradmin/user-lib.pl @@ -43,14 +43,24 @@ Returns true if some file looks like a valid Unix password file =cut sub password_file { -if (!$_[0]) { return 0; } -elsif (&open_readfile(SHTEST, $_[0])) { - local($line); - $line = ; - close(SHTEST); - return $line =~ /^\S+:\S*:/; +my ($file) = @_; +if (!$file) { + return 0; } -else { return 0; } +my $rv = $password_file_cache{$file}; +if (defined($rv)) { + return $rv; + } +if (&open_readfile(SHTEST, $_[0])) { + my $line = ; + close(SHTEST); + $rv = $line =~ /^\S+:\S*:/ ? 1 : 0; + } +else { + $rv = 0; + } +$password_file_cache{$file} = $rv; +return $rv; } =head2 list_users