commit:     9629cf285e461313b68438ecc4f6a25532c0c137
Author:     Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
AuthorDate: Thu Jun 30 22:36:10 2022 +0000
Commit:     Robin H. Johnson <robbat2 <AT> gentoo <DOT> 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 <robbat2 <AT> 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++;
                }
        }

Reply via email to