From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 0D73813832E for ; Thu, 21 Jul 2016 18:08:35 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id C0DFF21C19C; Thu, 21 Jul 2016 18:07:52 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 08D9221C19C for ; Thu, 21 Jul 2016 18:07:46 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 9B05B33D3C5 for ; Thu, 21 Jul 2016 18:07:45 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id C4BB37DF for ; Thu, 21 Jul 2016 18:07:43 +0000 (UTC) From: "Robin H. Johnson" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Robin H. Johnson" Message-ID: <1469124440.374585264af6d60d48a89271e5e5b4fc7e66aded.robbat2@gentoo> Subject: [gentoo-commits] proj/elections:master commit in: / X-VCS-Repository: proj/elections X-VCS-Files: Votify.pm X-VCS-Directories: / X-VCS-Committer: robbat2 X-VCS-Committer-Name: Robin H. Johnson X-VCS-Revision: 374585264af6d60d48a89271e5e5b4fc7e66aded X-VCS-Branch: master Date: Thu, 21 Jul 2016 18:07:43 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 0504c56e-2e31-4fa5-a959-e5ed315ddd30 X-Archives-Hash: 5a1f3eccc0a4f0c8220aa3945de83f97 commit: 374585264af6d60d48a89271e5e5b4fc7e66aded Author: Robin H. Johnson gentoo org> AuthorDate: Thu Jul 21 17:58:24 2016 +0000 Commit: Robin H. Johnson gentoo 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 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 {