commit: 374585264af6d60d48a89271e5e5b4fc7e66aded
Author: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
AuthorDate: Thu Jul 21 17:58:24 2016 +0000
Commit: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
CommitDate: Thu Jul 21 18:07:20 2016 +0000
URL: https://gitweb.gentoo.org/proj/elections.git/commit/?id=37458526
get_elections_list: readwrite for readability and fix cwd bug
Signed-off-by: Robin H. Johnson <robbat2 <AT> gentoo.org>
Votify.pm | 41 ++++++++++++++++++++++++++++++-----------
1 file changed, 30 insertions(+), 11 deletions(-)
diff --git a/Votify.pm b/Votify.pm
index e09d279..d53cfcb 100644
--- a/Votify.pm
+++ b/Votify.pm
@@ -75,19 +75,38 @@ sub validate_election_dir {
sub get_elections_list {
my @elections;
+
+ # Raw data:
opendir(D, $Votify::basedir) or die;
- @elections = sort grep {
- -d $_ and
- $_ ne "." and
- $_ ne ".." and
- $_ ne "" and
- substr($_, 0, 1) ne ".";
- } grep {
- my $valid_election_dir = validate_election_dir($_);
- defined $valid_election_dir;
- } readdir D;
+ @elections = readdir D;
closedir D;
- return @elections;
+
+ # Pass 1:
+ # Get rid of some definetly non-elections
+ @elections = grep {
+ my $state = List::Util::reduce { $a and $b } [
+ # All of these must be true:
+ -d(catfile($Votify::basedir, $_)),
+ ($_ ne "."), # Exclude current dir
+ ($_ ne ".."), # Exclude parent
+ ($_ ne ""), # Exclude bugs
+ substr($_, 0, 1) ne ".", # No hidden items
+ 1, # Fallback for when the items are commented out
+ ];
+ #printf "2: %s %d\n", $_, ($state);
+ $state;
+ } @elections;
+
+ # Pass 2:
+ # Full validation
+ @elections = grep {
+ my $valid_election_dir = validate_election_dir($_);
+ my $state = (defined $valid_election_dir) && $valid_election_dir;
+ #printf "1: validate_election_dir(%s) = %s, state=%d\n", $_,
$valid_election_dir, $state;
+ $state;
+ } @elections;
+
+ return sort @elections;
}
sub grabfile_int {