diff options
author | 2022-06-30 15:36:10 -0700 | |
---|---|---|
committer | 2022-06-30 15:36:10 -0700 | |
commit | 9629cf285e461313b68438ecc4f6a25532c0c137 (patch) | |
tree | 12a8ac430a48f13fc55a26b5d4178dbef2805b32 | |
parent | statify: fix chown (diff) | |
download | elections-9629cf285e461313b68438ecc4f6a25532c0c137.tar.gz elections-9629cf285e461313b68438ecc4f6a25532c0c137.tar.bz2 elections-9629cf285e461313b68438ecc4f6a25532c0c137.zip |
Votify: accept symlinks as well as files
Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
-rw-r--r-- | Votify.pm | 20 | ||||
-rwxr-xr-x | statify | 4 |
2 files changed, 14 insertions, 10 deletions
@@ -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"; } @@ -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++; } } |