1 |
commit: 9629cf285e461313b68438ecc4f6a25532c0c137 |
2 |
Author: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org> |
3 |
AuthorDate: Thu Jun 30 22:36:10 2022 +0000 |
4 |
Commit: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org> |
5 |
CommitDate: Thu Jun 30 22:36:10 2022 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/elections.git/commit/?id=9629cf28 |
7 |
|
8 |
Votify: accept symlinks as well as files |
9 |
|
10 |
Signed-off-by: Robin H. Johnson <robbat2 <AT> gentoo.org> |
11 |
|
12 |
Votify.pm | 20 ++++++++++++-------- |
13 |
statify | 4 ++-- |
14 |
2 files changed, 14 insertions(+), 10 deletions(-) |
15 |
|
16 |
diff --git a/Votify.pm b/Votify.pm |
17 |
index 35a717f..db311ea 100644 |
18 |
--- a/Votify.pm |
19 |
+++ b/Votify.pm |
20 |
@@ -56,9 +56,9 @@ sub validate_election_dir { |
21 |
my %REQUIRED_FILES_valid = map { |
22 |
my $file_valid = 0; |
23 |
# Legacy naming: |
24 |
- $file_valid = 1 if -f sprintf("%s/%s-%s", $election_dir, $_, $election_name); |
25 |
+ $file_valid = 1 if -r sprintf("%s/%s-%s", $election_dir, $_, $election_name); |
26 |
# New naming: |
27 |
- $file_valid = 1 if -f sprintf("%s/%s", $election_dir, $_); |
28 |
+ $file_valid = 1 if -r sprintf("%s/%s", $election_dir, $_); |
29 |
#printf "File %s valid=%d\n", $_, $file_valid; |
30 |
($_, $file_valid); |
31 |
} @REQUIRED_FILES; |
32 |
@@ -132,7 +132,7 @@ sub get_single_election_hashref { |
33 |
#print STDERR "Scan $fn\n"; |
34 |
my @filenames = (sprintf("%s/%s", "$basedir/$election_name", $fn), sprintf("%s/%s-%s", "$basedir/$election_name", $fn, $election_name)); |
35 |
#print STDERR Dumper(@filenames); |
36 |
- my $filename = abs_path(List::Util::first { $_ && -f $_ } @filenames); |
37 |
+ my $filename = abs_path(List::Util::first { $_ && -r $_ && -s $_ && ! -d $_ } @filenames); |
38 |
$election{"${fn}file"} = $filename; |
39 |
}; |
40 |
#print Dumper(%election); |
41 |
@@ -258,7 +258,7 @@ sub write_confs { |
42 |
$filename ||= $self->{'default_filename'}; |
43 |
$self->{'filename'} = $filename; |
44 |
|
45 |
- if (-f $filename) { |
46 |
+ if (-e $filename) { |
47 |
die "$filename already exists; please remove it first"; |
48 |
} |
49 |
|
50 |
@@ -319,7 +319,11 @@ sub collect { |
51 |
next; |
52 |
} |
53 |
|
54 |
- if (-f "$home/.ballot-$self->{election}-submitted") { |
55 |
+ my $submitted_filename = "$home/.ballot-$self->{election}-submitted"; |
56 |
+ if (-d $submitted_filename) {} |
57 |
+ print STDERR "Warning: $v has a directory instead of a ballot\n"; |
58 |
+ } |
59 |
+ elsif (-e $submitted_filename && -r $submitted_filename) { |
60 |
my ($b) = Ballot->new($self->{'election'}); |
61 |
$b->read("$home/.ballot-$self->{election}-submitted"); |
62 |
if ($b->verify) { |
63 |
@@ -329,7 +333,7 @@ sub collect { |
64 |
$self->{'ballots'}{$c} = $b; |
65 |
$self->{'casting_voters'}{$v} = 1; |
66 |
} |
67 |
- elsif (-f "$home/.ballot-$self->{election}") { |
68 |
+ elsif (-e "$home/.ballot-$self->{election}") { |
69 |
print STDERR "Warning: $v did not submit their ballot\n"; |
70 |
} |
71 |
} |
72 |
@@ -341,7 +345,7 @@ sub write_master { |
73 |
$filename ||= $self->{'default_filename'}; |
74 |
$self->{'filename'} = $filename; |
75 |
|
76 |
- if (-f $filename) { |
77 |
+ if (-e $filename) { |
78 |
die "$filename already exists; please remove it first"; |
79 |
} |
80 |
|
81 |
@@ -380,7 +384,7 @@ sub write_casting_voters { |
82 |
$filename ||= $self->{'default_filename'}; |
83 |
$self->{'filename'} = $filename; |
84 |
|
85 |
- if (-f $filename) { |
86 |
+ if (-e $filename) { |
87 |
die "$filename already exists; please remove it first"; |
88 |
} |
89 |
|
90 |
|
91 |
diff --git a/statify b/statify |
92 |
index b7c9396..0cccff1 100755 |
93 |
--- a/statify |
94 |
+++ b/statify |
95 |
@@ -86,9 +86,9 @@ for my $election_name (keys %open_elections) { |
96 |
my ($count_voters, $count_submit, $count_pending) = (0, 0,0); |
97 |
for my $votername (@voters) { |
98 |
$count_voters++; |
99 |
- if(-f catfile('/home', $votername, ".ballot-${election_name}-submitted")) { |
100 |
+ if(-e catfile('/home', $votername, ".ballot-${election_name}-submitted")) { |
101 |
$count_submit++; |
102 |
- } elsif (-f catfile('/home', $votername, ".ballot-${election_name}")) { |
103 |
+ } elsif (-e catfile('/home', $votername, ".ballot-${election_name}")) { |
104 |
$count_pending++; |
105 |
} |
106 |
} |