aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin H. Johnson <robbat2@gentoo.org>2016-07-21 10:58:24 -0700
committerRobin H. Johnson <robbat2@gentoo.org>2016-07-21 11:07:20 -0700
commit374585264af6d60d48a89271e5e5b4fc7e66aded (patch)
tree2e465a1a1e08d4031c2e65ba3e7f4d654f7fc14e /Votify.pm
parentResolve symlinks to find the correct elections directory. (diff)
downloadelections-374585264af6d60d48a89271e5e5b4fc7e66aded.tar.gz
elections-374585264af6d60d48a89271e5e5b4fc7e66aded.tar.bz2
elections-374585264af6d60d48a89271e5e5b4fc7e66aded.zip
get_elections_list: readwrite for readability and fix cwd bug
Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
Diffstat (limited to 'Votify.pm')
-rw-r--r--Votify.pm41
1 files 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 {