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.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 62DCA158094 for ; Thu, 30 Jun 2022 22:36:34 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 88AE6E0D08; Thu, 30 Jun 2022 22:36:33 +0000 (UTC) Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 63FE7E0D08 for ; Thu, 30 Jun 2022 22:36:33 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 6220E3415CF for ; Thu, 30 Jun 2022 22:36:32 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id CEB5450C for ; Thu, 30 Jun 2022 22:36:30 +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: <1656628570.9629cf285e461313b68438ecc4f6a25532c0c137.robbat2@gentoo> Subject: [gentoo-commits] proj/elections:master commit in: / X-VCS-Repository: proj/elections X-VCS-Files: Votify.pm statify X-VCS-Directories: / X-VCS-Committer: robbat2 X-VCS-Committer-Name: Robin H. Johnson X-VCS-Revision: 9629cf285e461313b68438ecc4f6a25532c0c137 X-VCS-Branch: master Date: Thu, 30 Jun 2022 22:36:30 +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-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: b73133bc-3ce0-441b-8b6c-4ef4d61f4da0 X-Archives-Hash: edc2b245ebae3812ea79ce8cad7b5a83 commit: 9629cf285e461313b68438ecc4f6a25532c0c137 Author: Robin H. Johnson gentoo org> AuthorDate: Thu Jun 30 22:36:10 2022 +0000 Commit: Robin H. Johnson gentoo org> CommitDate: Thu Jun 30 22:36:10 2022 +0000 URL: https://gitweb.gentoo.org/proj/elections.git/commit/?id=9629cf28 Votify: accept symlinks as well as files Signed-off-by: Robin H. Johnson gentoo.org> Votify.pm | 20 ++++++++++++-------- statify | 4 ++-- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Votify.pm b/Votify.pm index 35a717f..db311ea 100644 --- a/Votify.pm +++ b/Votify.pm @@ -56,9 +56,9 @@ sub validate_election_dir { my %REQUIRED_FILES_valid = map { my $file_valid = 0; # Legacy naming: - $file_valid = 1 if -f sprintf("%s/%s-%s", $election_dir, $_, $election_name); + $file_valid = 1 if -r sprintf("%s/%s-%s", $election_dir, $_, $election_name); # New naming: - $file_valid = 1 if -f sprintf("%s/%s", $election_dir, $_); + $file_valid = 1 if -r sprintf("%s/%s", $election_dir, $_); #printf "File %s valid=%d\n", $_, $file_valid; ($_, $file_valid); } @REQUIRED_FILES; @@ -132,7 +132,7 @@ sub get_single_election_hashref { #print STDERR "Scan $fn\n"; my @filenames = (sprintf("%s/%s", "$basedir/$election_name", $fn), sprintf("%s/%s-%s", "$basedir/$election_name", $fn, $election_name)); #print STDERR Dumper(@filenames); - my $filename = abs_path(List::Util::first { $_ && -f $_ } @filenames); + my $filename = abs_path(List::Util::first { $_ && -r $_ && -s $_ && ! -d $_ } @filenames); $election{"${fn}file"} = $filename; }; #print Dumper(%election); @@ -258,7 +258,7 @@ sub write_confs { $filename ||= $self->{'default_filename'}; $self->{'filename'} = $filename; - if (-f $filename) { + if (-e $filename) { die "$filename already exists; please remove it first"; } @@ -319,7 +319,11 @@ sub collect { next; } - if (-f "$home/.ballot-$self->{election}-submitted") { + my $submitted_filename = "$home/.ballot-$self->{election}-submitted"; + if (-d $submitted_filename) {} + print STDERR "Warning: $v has a directory instead of a ballot\n"; + } + elsif (-e $submitted_filename && -r $submitted_filename) { my ($b) = Ballot->new($self->{'election'}); $b->read("$home/.ballot-$self->{election}-submitted"); if ($b->verify) { @@ -329,7 +333,7 @@ sub collect { $self->{'ballots'}{$c} = $b; $self->{'casting_voters'}{$v} = 1; } - elsif (-f "$home/.ballot-$self->{election}") { + elsif (-e "$home/.ballot-$self->{election}") { print STDERR "Warning: $v did not submit their ballot\n"; } } @@ -341,7 +345,7 @@ sub write_master { $filename ||= $self->{'default_filename'}; $self->{'filename'} = $filename; - if (-f $filename) { + if (-e $filename) { die "$filename already exists; please remove it first"; } @@ -380,7 +384,7 @@ sub write_casting_voters { $filename ||= $self->{'default_filename'}; $self->{'filename'} = $filename; - if (-f $filename) { + if (-e $filename) { die "$filename already exists; please remove it first"; } diff --git a/statify b/statify index b7c9396..0cccff1 100755 --- a/statify +++ b/statify @@ -86,9 +86,9 @@ for my $election_name (keys %open_elections) { my ($count_voters, $count_submit, $count_pending) = (0, 0,0); for my $votername (@voters) { $count_voters++; - if(-f catfile('/home', $votername, ".ballot-${election_name}-submitted")) { + if(-e catfile('/home', $votername, ".ballot-${election_name}-submitted")) { $count_submit++; - } elsif (-f catfile('/home', $votername, ".ballot-${election_name}")) { + } elsif (-e catfile('/home', $votername, ".ballot-${election_name}")) { $count_pending++; } }