lib/App/FuguBench/Update.pm

filter: Statementstmt 27.6% 44 / 159 Branchbran 0.0% 0 / 62 Conditioncond 0.0% 0 / 37 MC/DCmcdc 0.0% 0 / 21 Subroutinesub 57.6% 15 / 26 Podpod 100% 1 / 1 totaltotal 19.6% 60 / 306 CC 48 SCAR 42.5
CC
48
Cov
17%
_run
240.0
_fetch
72.0
_outside_cache
42.0
CRAP 70.3
« lib/App/FuguBench/Deps.pm ↑ Summary lib/App/FuguBench/Doctor.pm »
1 # ex:ts=8 sw=4:
2 # $OpenBSD$
3 #
4 # Copyright (c) 2026 Dick Olsson <hi@senzilla.io>
5 #
6 # Permission to use, copy, modify, and distribute this software for any
7 # purpose with or without fee is hereby granted, provided that the above
8 # copyright notice and this permission notice appear in all copies.
9 #
10 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  
18 package App::FuguBench::Update;
19 117 our $VERSION = '0.1.1';
20  
21 117 ▶use v5.34;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 117 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 117 ▶use experimental 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
24 117 ▶no feature qw(indirect multidimensional bareword_filehandles);
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 117 ▶use Cwd ();
Subroutine BEGIN: called CC=1 SCAR=0.0
27 117 ▶use File::Spec ();
Subroutine BEGIN: called CC=1 SCAR=0.0
28 117 ▶use File::Temp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 117 ▶use Fugu::CLI qw(EXIT_SUCCESS EXIT_ERROR);
Subroutine BEGIN: called CC=1 SCAR=0.0
31 117 ▶use Fugu::Curl;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 117 ▶use Fugu::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 117 ▶use Fugu::Signify;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 117 ▶use App::FuguBench::Fetch;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 117 ▶use App::FuguBench::Keys;
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 # App::FuguBench::Update - the update verb.
39 #
40 # The verb replaces the running program with a release of the
41 # organization (DIST-UPDATE-1). The first fetch of the shim trusts
42 # HTTPS to GitHub, and every later download verifies against the
43 # release key, in this process (D-05).
44 #
45 # The keys come from App::FuguBench::Keys alone. The keys of a
46 # consumer never enter here, because a release decides what it
47 # trusts and no file of the host decides it (DIST-KEY-2).
48 #
49 # The verb reads no checkout (CLI-CHECKOUT-5), so an operator runs it
50 # from ~/.local/bin in any directory.
51 #
52 # Three files reach the downloader: SHA256, SHA256.sig, and fugubench.
53 # Every one of them goes through _fetch, and _fetch calls check_url of
54 # App::FuguBench::Fetch first (DEPS-FETCH-4). One funnel holds the
55 # three, because Fugu::Curl places the URL last and builds no '--'
56 # separator. FUGUBENCH_RELEASE_URL comes from the environment, and the
57 # check covers the address that it builds.
58 #
59 # The row of the verb unveils nothing, because Fugu::Curl runs a
60 # downloader as a child (CLI-SANDBOX-2). The verb replaces the running
61 # file where it sits, so no path list bounds that write.
62  
63 117 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
64  
65 # The release directory of the organization (DIST-ASSETS-1).
66 # FUGUBENCH_RELEASE_URL replaces this part, and a test points
67 # the verb at a loopback server with it (DIST-UPDATE-1).
68 117 URL => 'https://github.com/FuguBSD/FuguBench',
69  
70 # The three names of a release that the verb downloads.
71 MANIFEST => 'SHA256',
72 SIGNATURE => 'SHA256.sig',
73 PROGRAM => 'fugubench',
74  
75 # The version of a build that no release stamped. A checkout
76 # carries no stamp at all, so every release is above it
77 # (DIST-VERSION-1).
78 NO_STAMP => '0.0.0',
79  
80 # The mode of the replaced program (DIST-INSTALL-2).
81 MODE => 0755,
82  
83 # The published install command (DIST-INSTALL-3). A rotation
84 # of the release key can leave this program without the key of
85 # a later release, and the install script reads no embedded
86 # key. The failure of the signature names this command, so the
87 # operator reads the path out (DIST-KEY-3).
88 INSTALL => 'curl -fsSL https://bench.fugubsd.org/get | sh',
89 117 };
90  
91 # App::FuguBench::Update->command($verb):
92 # The entry of the Fugu::CLI table. The module holds one verb,
93 # so it ignores the name.
94 117 ▶sub command ( $, $ )
Subroutine command: called CC=1 SCAR=1.2
Pod documented
95 {
96 return {
97 summary => 'replace the program with a verified release',
98 usage => '[--version <tag>] [--allow-downgrade]',
99 options => {
100 'version=s' => 'the release tag, in place of the'
101 . ' latest release',
102 'allow-downgrade' => 'take a release below the'
103 . ' running version',
104 },
105 0 ▶ run => sub ( $app, @argv ) { return _run( $app, @argv ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
106 117 };
107 }
108  
109 # _run($app, @argv):
110 # The body of the verb. It takes no argument, and an argument is
111 # a usage error.
112 #
113 # The steps run in the order of DIST-UPDATE-1, and the first
114 # failure stops the verb. The signature check comes in front of
115 # the download of the packed file, so a release that no embedded
116 # key signed costs the manifest and its signature, and no more.
117 #
118 # Every failure returns 1 with the reason on standard error. A
119 # tag of another shape is a usage error, and it returns 2.
120 0 ▶sub _run ( $app, @argv )
Subroutine _run: not called CC=15 SCAR=54.8
121 {
122 0 my $cli = $app->cli;
123 0 my $log = $cli->log;
124  
125 0 ▶ return $cli->command_usage_error('update') if @argv;
Branch: 1 branch
BranchTrueFalseTotal
if @argv 0 0 0
126  
127 # The tag reaches a URL, and a release tag of this
128 # organization is v<MAJOR>.<MINOR>.<PATCH> (DIST-ASSETS-1). The
129 # shape check also holds the value to one path segment.
130 0 my $tag = $cli->option('version');
131 0 ▶ if ( defined $tag && $tag !~ /\Av[0-9]+[.][0-9]+[.][0-9]+\z/a ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tag and not $tag =~ /\Av[0-9]+[.][0-9]+[.][0-9]+\z/a) 0 0 0
Condition0%0/3
defined $tag and not $tag =~ /\Av[0-9]+[.][0-9]+[.][0-9]+\z/a
!ll&&!rl&&r
000
MC/DC0%0/2
defined $tag and not $tag =~ /\Av[0-9]+[.][0-9]+[.][0-9]+\z/a
defined $tag not $tag =~ /\Av[0-9]+[.][0-9]+[.][0-9]+\z/a
Truth table0%0/3
A and not(B)
A= defined $tagB= not $tag =~ /\Av[0-9]+[.][0-9]+[.][0-9]+\z/a
ABresult
0X0
100
111
132 0 $log->error( 'the tag %s is no v<MAJOR>.<MINOR>.<PATCH>',
133 $tag );
134 0 return $cli->command_usage_error('update');
135 }
136  
137 0 my $file = _running_file();
138 0 ▶ return EXIT_ERROR unless _outside_cache( $app, $file );
Branch: 1 branch
BranchTrueFalseTotal
unless _outside_cache($app, $file) 0 0 0
139  
140 0 my $temp = File::Temp->newdir(
141 TEMPLATE => 'fugubench-XXXXXXXX',
142 TMPDIR => 1
143 );
144 0 my $dir = "$temp";
145 0 my $base = _release_url($tag);
146 0 my $curl = Fugu::Curl->new;
147  
148 0 my $manifest = File::Spec->catfile( $dir, MANIFEST );
149 0 my $signature = File::Spec->catfile( $dir, SIGNATURE );
150 0 ▶ return EXIT_ERROR
Branch: 1 branch
BranchTrueFalseTotal
unless _fetch($app, $curl, $base, "SHA256", $manifest, $tag) and _fetch($app, $curl, $base, "SHA256.sig", $signature, $tag) 0 0 0
Condition0%0/3
_fetch($app, $curl, $base, "SHA256", $manifest, $tag) and _fetch($app, $curl, $base, "SHA256.sig", $signature, $tag)
!ll&&!rl&&r
000
MC/DC0%0/2
_fetch($app, $curl, $base, "SHA256", $manifest, $tag) and _fetch($app, $curl, $base, "SHA256.sig", $signature, $tag)
_fetch($app, $curl, $base, "SHA256", $manifest, $tag) _fetch($app, $curl, $base, "SHA256.sig", $signature, $tag)
Truth table0%0/3
A and B
A= _fetch($app, $curl, $base, "SHA256", $manifest, $tag)B= _fetch($app, $curl, $base, "SHA256.sig", $signature, $tag)
ABresult
0X0
100
111
151 unless _fetch( $app, $curl, $base, MANIFEST, $manifest, $tag )
152 && _fetch( $app, $curl, $base, SIGNATURE, $signature, $tag );
153  
154 0 my @keys = _key_files( $app, $dir );
155 0 ▶ return EXIT_ERROR unless @keys;
Branch: 1 branch
BranchTrueFalseTotal
unless @keys 0 0 0
156  
157 # The perl engine parses the signify(1) formats itself and
158 # checks the signature with Fugu::Ed25519, so no host needs
159 # signify(1).
160 0 my $signify = Fugu::Signify->new( engine => 'perl' );
161 0 ▶ unless (
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $signify->verify("keys", \@keys, "file", $manifest, "signature", $signature)) 0 0 0
162 defined $signify->verify(
163 keys => \@keys,
164 file => $manifest,
165 signature => $signature
166 ) )
167 {
168 0 $log->error( 'no embedded key verifies the signature of %s/%s',
169 $base, MANIFEST );
170 0 $log->error( ' %s', $signify->error );
171 0 $log->error( ' install the program again: %s', INSTALL );
172 0 return EXIT_ERROR;
173 }
174  
175 0 my $version = _manifest_version( $app, $signify, $manifest, $base );
176 0 ▶ return EXIT_ERROR unless defined $version;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $version 0 0 0
177  
178 0 my $running = _running_version();
179 0 ▶ if ( !$cli->option('allow-downgrade') && _below( $version, $running ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not $cli->option("allow-downgrade") and _below($version, $running)) 0 0 0
Condition0%0/3
not $cli->option("allow-downgrade") and _below($version, $running)
!ll&&!rl&&r
000
MC/DC0%0/2
not $cli->option("allow-downgrade") and _below($version, $running)
not $cli->option("allow-downgrade") _below($version, $running)
Truth table0%0/3
not(A) and B
A= not $cli->option("allow-downgrade")B= _below($version, $running)
ABresult
0X0
100
111
180 {
181 0 $log->error(
182 'the release %s is below the running %s, and a replay'
183 . ' of an earlier release is an attack',
184 $version, $running
185 );
186 0 $log->error(' pass --allow-downgrade to take it anyway');
187 0 return EXIT_ERROR;
188 }
189  
190 0 my $packed = File::Spec->catfile( $dir, PROGRAM );
191 0 ▶ return EXIT_ERROR
Branch: 1 branch
BranchTrueFalseTotal
unless _fetch($app, $curl, $base, "fugubench", $packed, $tag) 0 0 0
192 unless _fetch( $app, $curl, $base, PROGRAM, $packed, $tag );
193  
194 # The digest check comes from the module that verified the
195 # signature, so one library holds both checks. The call reads
196 # the signature again, and it digests no file before the
197 # manifest verifies.
198 0 my $name = PROGRAM;
199 0 ▶ unless (
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $signify->verify_manifest("keys", \@keys, "manifest", $manifest, "signature", $signature, "files", {$name, $packed})) 0 0 0
200 defined $signify->verify_manifest(
201 keys => \@keys,
202 manifest => $manifest,
203 signature => $signature,
204 files => { $name => $packed } ) )
205 {
206 0 $log->error( 'the packed file of %s failed its check', $base );
207 0 $log->error( ' %s', $signify->error );
208 0 return EXIT_ERROR;
209 }
210  
211 0 ▶ return EXIT_ERROR unless _replace( $app, $file, $packed );
Branch: 1 branch
BranchTrueFalseTotal
unless _replace($app, $file, $packed) 0 0 0
212  
213 # The result line of the verb (DIST-UPDATE-4).
214 0 say "fugubench $version";
215  
216 0 return EXIT_SUCCESS;
217 }
218  
219 # _running_file():
220 # The path of the running program, with every symlink resolved.
221 # The verb replaces that file where it sits, so a program under
222 # ~/.local/bin and a program of another directory each take the
223 # same path.
224 0 ▶sub _running_file ()
Subroutine _running_file: not called CC=2 SCAR=17.9
225 {
226 0 ▶ return Cwd::realpath($0) // $0;
Condition0%0/3
Cwd::realpath($0) // $0
l!l&&r!l&&!r
000
MC/DC0%0/2
Cwd::realpath($0) // $0
Cwd::realpath($0) $0
Truth table0%0/3
A // B
A= Cwd::realpath($0)B= $0
ABresult
1X1
011
000
227 }
228  
229 # _running_version():
230 # The version of the running program. The dist build stamps it
231 # into the package, and a checkout carries no stamp.
232 #
233 # A value of another shape reads as no stamp. The comparison of
234 # _below reads each field as a number, and a field that is no
235 # number would compare as zero without a word.
236 0 ▶sub _running_version ()
Subroutine _running_version: not called CC=3 SCAR=24.8
237 {
238 0 my $version = $App::FuguBench::VERSION;
239 0 ▶ return NO_STAMP unless defined $version;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $version 0 0 0
240 0 ▶ return NO_STAMP unless $version =~ /\A[0-9]+(?:[.][0-9]+)*\z/a;
Branch: 1 branch
BranchTrueFalseTotal
unless $version =~ /\A[0-9]+(?:[.][0-9]+)*\z/a 0 0 0
241  
242 0 return $version;
243 }
244  
245 # _release_url($tag):
246 # The release directory of the download, without a final
247 # solidus. The latest release and a named tag sit at two
248 # addresses of GitHub.
249 #
250 # FUGUBENCH_RELEASE_URL replaces the host and the repository
251 # (DIST-UPDATE-1). A developer and a test point the verb at
252 # another server with it, as the shim takes its own override
253 # from the environment (DIST-SHIM-2). The value can end with a
254 # solidus, and this method removes it, so no address holds two.
255 0 ▶sub _release_url ($tag)
Subroutine _release_url: not called CC=4 SCAR=30.0
256 {
257 0 my $base = $ENV{FUGUBENCH_RELEASE_URL};
258 0 ▶ $base = URL unless defined $base && length $base;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $base and length $base 0 0 0
Condition0%0/3
defined $base and length $base
!ll&&!rl&&r
000
MC/DC0%0/2
defined $base and length $base
defined $base length $base
Truth table0%0/3
A and B
A= defined $baseB= length $base
ABresult
0X0
100
111
259 0 $base =~ s{/+\z}{};
260  
261 0 ▶ return defined $tag
Branch: 1 branch
BranchTrueFalseTotal
defined $tag ? : 0 0 0
262 ? "$base/releases/download/$tag"
263 : "$base/releases/latest/download";
264 }
265  
266 # _outside_cache($app, $file):
267 # Hold the running file out of the shim cache (DIST-UPDATE-3).
268 # The method returns 1 for a file that the verb can replace, and
269 # 0 for one under the cache, which it reports. An unset or an
270 # empty HOME is a refusal as well, because the cache path starts
271 # with that value and the method cannot find the cache without
272 # it.
273 #
274 # The cache path carries the version, and the shim holds the
275 # cached file to the digest of that version. A replaced file
276 # fails that digest, so the shim stops and the operator has no
277 # program. A new version reaches a consumer through a sync of
278 # the org pack.
279 #
280 # The comparison resolves the cache directory, because HOME can
281 # hold a symlink and the running file carries the resolved form.
282 # An absent directory resolves to nothing, and the literal path
283 # stands then.
284 0 ▶sub _outside_cache ( $app, $file )
Subroutine _outside_cache: not called CC=6 SCAR=37.4
285 {
286 0 my $home = $ENV{HOME};
287 0 ▶ unless ( defined $home && length $home ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $home and length $home) 0 0 0
Condition0%0/3
defined $home and length $home
!ll&&!rl&&r
000
MC/DC0%0/2
defined $home and length $home
defined $home length $home
Truth table0%0/3
A and B
A= defined $homeB= length $home
ABresult
0X0
100
111
288 0 $app->cli->log->error( 'HOME is unset or empty, and the'
289 . ' shim cache sits under it' );
290 0 return 0;
291 }
292  
293 0 my $cache = File::Spec->catdir( $home, '.cache', 'fugubench' );
294 0 ▶ $cache = Cwd::realpath($cache) // $cache;
Condition0%0/3
Cwd::realpath($cache) // $cache
l!l&&r!l&&!r
000
MC/DC0%0/2
Cwd::realpath($cache) // $cache
Cwd::realpath($cache) $cache
Truth table0%0/3
A // B
A= Cwd::realpath($cache)B= $cache
ABresult
1X1
011
000
295  
296 # The separator is a solidus, as it is in File::Spec on every
297 # platform that pledge(2) and unveil(2) reach.
298 0 ▶ return 1
Branch: 1 branch
BranchTrueFalseTotal
unless $file eq $cache or index($file, "$cache/") == 0 0 0 0
Condition0%0/3
$file eq $cache or index($file, "$cache/") == 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$file eq $cache or index($file, "$cache/") == 0
$file eq $cache index($file, "$cache/") == 0
Truth table0%0/3
A or B
A= $file eq $cacheB= index($file, "$cache/") == 0
ABresult
1X1
011
000
299 unless $file eq $cache || index( $file, "$cache/" ) == 0;
300  
301 0 $app->cli->log->error( '%s sits under the shim cache %s',
302 $file, $cache );
303 0 $app->cli->log->error(
304 ' the shim holds that file to a digest, so a new version'
305 . ' comes from a sync of the org pack of FuguBSD/Tooling' );
306  
307 0 return 0;
308 }
309  
310 # _fetch($app, $curl, $base, $name, $path, $tag):
311 # Download one file of the release directory. The method returns
312 # 1 on success, and 0 after a failure, which it reports.
313 #
314 # Every download of the verb passes here, and the shape check of
315 # the URL runs first (DEPS-FETCH-4). Fugu::Curl places the URL
316 # last and writes no '--' separator, so a URL that starts with a
317 # dash would reach the downloader as an option.
318 #
319 # A 404 names the tag. An absent tag and an absent asset give
320 # that one answer, and no caller tells the two apart, so the
321 # message names both.
322 0 ▶sub _fetch ( $app, $curl, $base, $name, $path, $tag )
Subroutine _fetch: not called CC=8 SCAR=42.8
323 {
324 0 my $log = $app->cli->log;
325 0 my $url = "$base/$name";
326  
327 0 ▶ return 0
Branch: 1 branch
BranchTrueFalseTotal
unless App::FuguBench::Fetch::check_url($app, $url, "the release address") 0 0 0
328 unless App::FuguBench::Fetch::check_url( $app, $url,
329 'the release address' );
330  
331 0 ▶ return 1 if $curl->fetch( $url, $path );
Branch: 1 branch
BranchTrueFalseTotal
if $curl->fetch($url, $path) 0 0 0
332  
333 0 ▶ if ( ( $curl->status // q{} ) eq 'http' && ( $curl->code // 0 ) == 404 )
Branch: 1 branch
BranchTrueFalseTotal
if (($curl->status // "") eq "http" and ($curl->code // 0) == 404) 0 0 0
Condition0%0/7
($curl->status // "") eq "http" and ($curl->code // 0) == 404
!ll&&!rl&&r
000
$curl->status // ""
l!l
00
$curl->code // 0
l!l
00
MC/DC0%0/2
($curl->status // "") eq "http" and ($curl->code // 0) == 404
$curl->status $curl->code
Truth table0%0/3
A and B
A= $curl->statusB= $curl->code
ABresult
0X0
100
111
334 {
335 0 ▶ $log->error(
Condition0%0/2
$tag // "latest"
l!l
00
MC/DC0%0/1
$tag // "latest"
$tag
Truth table0%0/2
A
A= $tag
Aresult
11
00
336 'the release %s answers no %s: the tag names no'
337 . ' release, or that release holds no such asset',
338 $tag // 'latest',
339 $name
340 );
341 0 return 0;
342 }
343  
344 0 $log->error( '%s', $curl->error );
345  
346 0 return 0;
347 }
348  
349 # _key_files($app, $dir):
350 # One signify public key file for each embedded release key, in
351 # the trust order of App::FuguBench::Keys (DIST-KEY-1).
352 # Fugu::Signify reads a key from a path, so the verb writes the
353 # list that it holds.
354 #
355 # The method returns the paths, and the empty list after a
356 # failure, which it reports. A program that embeds no key
357 # verifies nothing, and that build is broken.
358 0 ▶sub _key_files ( $app, $dir )
Subroutine _key_files: not called CC=4 SCAR=30.0
359 {
360 0 my $log = $app->cli->log;
361 0 my @paths;
362  
363 0 for my $pair ( App::FuguBench::Keys->keys ) {
364 0 my ( $name, $body ) = @$pair;
365  
366 0 my $path = File::Spec->catfile( $dir, "$name.pub" );
367 0 my $text = "untrusted comment: $name public key\n$body\n";
368 0 ▶ unless ( Fugu::File->write( $path, $text ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ("Fugu::File"->write($path, $text)) 0 0 0
369 0 $log->error( 'cannot write the key file %s', $path );
370 0 return ();
371 }
372 0 push @paths, $path;
373 }
374  
375 0 ▶ $log->error('this build embeds no release key') unless @paths;
Branch: 1 branch
BranchTrueFalseTotal
unless @paths 0 0 0
376  
377 0 return @paths;
378 }
379  
380 # _manifest_version($app, $signify, $manifest, $base):
381 # The version of the release, from the versioned tarball name of
382 # the manifest (DIST-ASSETS-1). The method returns undef after a
383 # failure, which it reports.
384 #
385 # The manifest is the version, because the release workflow
386 # writes the tag into that name. The manifest also names the
387 # tarball of the stable name, and that one carries no version.
388 #
389 # The caller verifies the signature before this call, so the
390 # name that the method reads carries the signature of a release
391 # key.
392 0 ▶sub _manifest_version ( $app, $signify, $manifest, $base )
Subroutine _manifest_version: not called CC=5 SCAR=34.0
393 {
394 0 my $log = $app->cli->log;
395 0 my $text = Fugu::File->read($manifest);
396 0 ▶ unless ( defined $text ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $text) 0 0 0
397 0 $log->error( 'cannot read %s', $manifest );
398 0 return;
399 }
400  
401 0 my $digests = $signify->parse_manifest($text);
402 0 ▶ unless ($digests) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($digests) 0 0 0
403 0 $log->error( 'the manifest of %s does not parse: %s',
404 $base, $signify->error );
405 0 return;
406 }
407  
408 my @found = sort map {
409 0 ▶ /\AApp-FuguBench-([0-9]+(?:[.][0-9]+)+)[.]tar[.]gz\z/a ? $1 : ()
Branch: 1 branch
BranchTrueFalseTotal
/\AApp-FuguBench-([0-9]+(?:[.][0-9]+)+)[.]tar[.]gz\z/a ? : 0 0 0
410 } keys %$digests;
411  
412 0 ▶ unless ( @found == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@found == 1) 0 0 0
413 0 $log->error(
414 'the manifest of %s names %d versioned tarballs, and a'
415 . ' release holds one',
416 $base,
417 scalar @found
418 );
419 0 return;
420 }
421  
422 0 return $found[0];
423 }
424  
425 # _below($release, $running):
426 # Report if the release version sits below the running one
427 # (DIST-UPDATE-2). Each value is a dotted-decimal number, and
428 # the comparison reads field by field, so 1.10.0 sits above
429 # 1.9.0.
430 0 ▶sub _below ( $release, $running )
Subroutine _below: not called CC=6 SCAR=37.4
431 {
432 0 my @new = split /[.]/, $release;
433 0 my @old = split /[.]/, $running;
434  
435 0 for my $i ( 0 .. 2 ) {
436 0 ▶ my $a = $new[$i] // 0;
Condition0%0/2
$new[$i] // 0
l!l
00
MC/DC0%0/1
$new[$i] // 0
$new[$i]
Truth table0%0/2
A
A= $new[$i]
Aresult
11
00
437 0 ▶ my $b = $old[$i] // 0;
Condition0%0/2
$old[$i] // 0
l!l
00
MC/DC0%0/1
$old[$i] // 0
$old[$i]
Truth table0%0/2
A
A= $old[$i]
Aresult
11
00
438 0 ▶ return 1 if $a < $b;
Branch: 1 branch
BranchTrueFalseTotal
if $a < $b 0 0 0
439 0 ▶ return 0 if $a > $b;
Branch: 1 branch
BranchTrueFalseTotal
if $a > $b 0 0 0
440 }
441  
442 0 return 0;
443 }
444  
445 # _replace($app, $file, $packed):
446 # Put the verified bytes in the place of the running file. The
447 # method returns 1, and 0 after a failure, which it reports.
448 #
449 # The write is atomic, so a reader of the path sees the old
450 # program or the new one, and never a half-written file. The
451 # mode comes from a chmod, because the open of the write takes
452 # the umask of the operator.
453 0 ▶sub _replace ( $app, $file, $packed )
Subroutine _replace: not called CC=4 SCAR=30.0
454 {
455 0 my $log = $app->cli->log;
456 0 my $text = Fugu::File->read($packed);
457 0 ▶ unless ( defined $text ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $text) 0 0 0
458 0 $log->error( 'cannot read %s', $packed );
459 0 return 0;
460 }
461  
462 0 ▶ return 0 unless Fugu::File->write_atomic( $file, $text, mode => MODE );
Branch: 1 branch
BranchTrueFalseTotal
unless "Fugu::File"->write_atomic($file, $text, "mode", 493) 0 0 0
463  
464 0 ▶ unless ( chmod MODE, $file ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (chmod 0755, $file) 0 0 0
465 0 $log->error( 'cannot set the mode of %s: %s', $file, $! );
466 0 return 0;
467 }
468  
469 0 return 1;
470 }
471  
472 117 1;
« lib/App/FuguBench/Deps.pm ↑ Summary lib/App/FuguBench/Doctor.pm »