| 1 | package Mogura::Server::Store; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 4 | ▶ | use Mojo::Base -base; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use DBI; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use Digest::SHA qw(sha256_hex); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use Mojo::File qw(path); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Mojo::JSON qw(to_json from_json); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use Mogura::Protocol qw(random_id valid_id now artifact_name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use Mogura::Server::Tags; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use constant BLOCKS_REMOVAL => q{finished=0 OR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 4 | COALESCE(json_extract(record, '$.cleanup_status'), '') NOT IN ('unmounted', 'not_needed')}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | has state => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 0 | ▶ | sub { path($ENV{XDG_STATE_HOME} || path($ENV{HOME}, '.local/state'), 'mogura')->to_string }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=14.0
Condition0%0/3
$ENV{'XDG_STATE_HOME'} || path($ENV{'HOME'}, '.local/state')
MC/DC0%0/2
$ENV{'XDG_STATE_HOME'} || path($ENV{'HOME'}, '.local/state')
$ENV{'XDG_STATE_HOME'}
path($ENV{'HOME'}, '.local/state')
Truth table0%0/3
A || B
A= $ENV{'XDG_STATE_HOME'}B= path($ENV{'HOME'}, '.local/state')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 508 | ▶ | sub db { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
db: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 508 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 508 | ▶ | return $self->{db} if ($self->{pid} // 0) == $$; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$self->{"pid"} // 0
MC/DC100%1/1
$self->{"pid"} // 0
$self->{"pid"}
Truth table100%2/2
A
A= $self->{"pid"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 6 | path($self->state)->make_path({mode => 0700}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 6 | my $db = DBI->connect('dbi:SQLite:dbname=' . path($self->state, 'mogura.sqlite'), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | '', '', {RaiseError => 1, PrintError => 0, sqlite_unicode => 1, AutoInactiveDestroy => 1}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 6 | $db->do('PRAGMA busy_timeout=5000'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 6 | $db->do('PRAGMA synchronous=FULL'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 6 | $self->{pid} = $$; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 6 | return $self->{db} = $db; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 10 | ▶ | sub initialize { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
initialize: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 10 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 10 | my $db = $self->db; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 10 | $db->do('PRAGMA journal_mode=WAL'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 10 | $db->do('CREATE TABLE IF NOT EXISTS settings(name TEXT PRIMARY KEY, value TEXT NOT NULL)'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 10 | $db->do("INSERT OR IGNORE INTO settings VALUES ('session', ?)", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | undef, random_id() . random_id()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 10 | $db->do("INSERT OR IGNORE INTO settings VALUES ('id',?)", undef, random_id()); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 10 | $db->do( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 'CREATE TABLE IF NOT EXISTS scanners(id TEXT PRIMARY KEY, digest TEXT UNIQUE, seen INTEGER, inventory TEXT)' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 10 | $db->do( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | q{CREATE TABLE IF NOT EXISTS jobs(id TEXT PRIMARY KEY, scanner TEXT NOT NULL, token TEXT NOT NULL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | run TEXT, created TEXT NOT NULL, tags TEXT NOT NULL, note TEXT NOT NULL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | record TEXT NOT NULL, finished INTEGER NOT NULL DEFAULT 0)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 10 | $db->do('CREATE INDEX IF NOT EXISTS assigned ON jobs(scanner,finished,created)'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 10 | $db->do('CREATE INDEX IF NOT EXISTS removal_blockers ON jobs(scanner) WHERE ' . BLOCKS_REMOVAL); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 10 | $db->do( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 'CREATE TABLE IF NOT EXISTS receipts(job TEXT, run TEXT, kind TEXT, hash TEXT NOT NULL, indexed INTEGER NOT NULL DEFAULT 0, PRIMARY KEY(job,run,kind))' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 10 | $db->do('CREATE INDEX IF NOT EXISTS pending_indexes ON receipts(job,kind) WHERE indexed=0'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 10 | $db->do('CREATE INDEX IF NOT EXISTS history ON jobs(created DESC,id DESC)'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 10 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 42 | ▶ | sub transaction { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
transaction: called CC=2 SCAR=7.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 42 | my ($self, $operation) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 42 | my $db = $self->db; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 42 | $db->begin_work; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 42 | my $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 42 | ▶ | eval { $result = $operation->($db); $db->commit; 1 } or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | my $error = $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | $db->rollback; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | die $error; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 42 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 8 | ▶ | sub register { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
register: called CC=3 SCAR=11.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 8 | my ($self, $id, $token) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 8 | ▶ | die 'Invalid scanner name' unless ($id // '') =~ /\A[a-zA-Z0-9_-]{1,64}\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$id // ""
MC/DC0%0/1
$id // ""
$id
Truth table50%1/2
A
A= $id
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 8 | $self->db->do('INSERT INTO scanners(id,digest) VALUES (?,?)', undef, $id, sha256_hex($token)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 38 | ▶ | sub authenticate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
authenticate: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 38 | my ($self, $header) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 38 | ▶ | return unless ($header // '') =~ /\ABearer ([a-f0-9]{64})\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$header // ""
MC/DC100%1/1
$header // ""
$header
Truth table100%2/2
A
A= $header
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 37 | scalar $self->db->selectrow_array('SELECT id FROM scanners WHERE digest=?', undef, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | sha256_hex($1)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 17 | ▶ | sub inventories { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
inventories: called CC=4 SCAR=14.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 17 | my ($self, $page) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 17 | ▶ | my $rows = $self->db->selectall_arrayref( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$page // 1
MC/DC0%0/1
$page // 1
$page
Truth table50%1/2
A
A= $page
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 'SELECT id,seen,inventory FROM scanners WHERE digest IS NOT NULL ORDER BY id LIMIT 5 OFFSET ?', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | {Slice => {}}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | (($page // 1) - 1) * 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | return [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 17 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 17 | ▶ | %{from_json($_->{inventory} // '{"disks":[]}')}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
$_->{"inventory"} // "{\"disks\":[]}"
$_->{"seen"} // 0
MC/DC0%0/1
$_->{"inventory"} // "{\"disks\":[]}"
$_->{"inventory"}
MC/DC0%0/1
$_->{"seen"} // 0
$_->{"seen"}
Truth table50%1/2
A
A= $_->{"inventory"}
Truth table50%1/2
A
A= $_->{"seen"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | scanner_id => $_->{id}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 17 | stale => ($_->{seen} // 0) < | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | time - 30 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } @$rows | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 35 | ▶ | sub selectable { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
selectable: called CC=10 SCAR=23.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 35 | my ($self, $scanner, $token) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 35 | my ($json) = $self->db->selectrow_array( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 'SELECT inventory FROM scanners WHERE id=? AND digest IS NOT NULL AND seen>=?', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | undef, $scanner, time - 30); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 35 | ▶ | return unless $json; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 34 | my $inv = from_json($json); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 34 | ▶ | return if @{$inv->{blocked} // []} || @{$inv->{errors} // []}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition85%6/7
@{$inv->{"blocked"} // [];} or @{$inv->{"errors"} // [];}
$inv->{"blocked"} // []
$inv->{"errors"} // []
MC/DC50%1/2
@{$inv->{"blocked"} // [];} or @{$inv->{"errors"} // [];}
@{$inv->{"blocked"} // [];}
@{$inv->{"errors"} // [];}
MC/DC100%1/1
$inv->{"blocked"} // []
$inv->{"blocked"}
MC/DC100%1/1
$inv->{"errors"} // []
$inv->{"errors"}
Truth table66%2/3
A or B
A= @{$inv->{"blocked"} // [];}B= @{$inv->{"errors"} // [];}
Truth table100%2/2
A
A= $inv->{"blocked"}
Truth table100%2/2
A
A= $inv->{"errors"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 107 | ▶ | my @targets = grep { $_ && $_->{selectable} && ($_->{token} // '') eq $token } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition87%7/8
$_ && $_->{'selectable'} && ($_->{'token'} // '') eq $token
$_ and $_->{"selectable"}
$_->{"token"} // ""
MC/DC66%2/3
$_ && $_->{'selectable'} && ($_->{'token'} // '') eq $token
$_
$_->{"selectable"}
$_->{"token"}
Truth table75%3/4
A and B && C
A= $_B= $_->{"selectable"}C= $_->{"token"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 33 | ($inv->{host}, map { @{$_->{targets}} } @{$inv->{disks}}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 33 | ▶ | return @targets == 1 ? $targets[0] : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | # Linux assigns a disk sequence to the whole attachment for the lifetime of a boot. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 44 | ▶ | sub _attachment { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_attachment: called CC=8 SCAR=21.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 44 | my ($target) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 44 | ▶ | return unless ref($target) eq 'HASH' && ref($target->{disk}) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $target eq "HASH" and ref $target->{"disk"} eq "HASH"
MC/DC50%1/2
ref $target eq "HASH" and ref $target->{"disk"} eq "HASH"
ref $target eq "HASH"
ref $target->{"disk"} eq "HASH"
Truth table66%2/3
A and B
A= ref $target eq "HASH"B= ref $target->{"disk"} eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 37 | my ($boot, $sequence) = ($target->{boot_id}, $target->{disk}{diskseq}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 37 | ▶ | unless defined($boot) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition81%9/11
defined $boot and not ref $boot and $boot =~ /\S/u and ($sequence // "") =~ /\A[1-9][0-9]*\z/u
defined $boot and not ref $boot and $boot =~ /\S/u
defined $boot and not ref $boot
$sequence // ""
MC/DC50%2/4
defined $boot and not ref $boot and $boot =~ /\S/u and ($sequence // "") =~ /\A[1-9][0-9]*\z/u
defined $boot
not ref $boot
$boot =~ /\S/u
$sequence
Truth table60%3/5
A and not(B) and C and D
A= defined $bootB= not ref $bootC= $boot =~ /\S/uD= $sequence
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | && !ref($boot) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | && $boot =~ /\S/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | && ($sequence // '') =~ /\A[1-9][0-9]*\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 34 | return "$boot:$sequence"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 21 | ▶ | sub can_disconnect { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
can_disconnect: called CC=22 SCAR=33.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 21 | my ($self, $scan) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 21 | ▶ | return unless ($scan->{cleanup_status} // '') eq 'unmounted'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$scan->{"cleanup_status"} // ""
MC/DC0%0/1
$scan->{"cleanup_status"} // ""
$scan->{"cleanup_status"}
Truth table50%1/2
A
A= $scan->{"cleanup_status"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 19 | ▶ | my $attachment = _attachment($scan->{target}) // return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
_attachment($scan->{"target"}) // (return)
MC/DC100%1/1
_attachment($scan->{"target"}) // (return)
_attachment($scan->{"target"})
Truth table100%2/2
A
A= _attachment($scan->{"target"})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 12 | ▶ | my $current = $self->selectable($scan->{scanner_id}, $scan->{token}) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 12 | ▶ | return unless (_attachment($current->{identity}) // '') eq $attachment; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
_attachment($current->{"identity"}) // ""
MC/DC100%1/1
_attachment($current->{"identity"}) // ""
_attachment($current->{"identity"})
Truth table100%2/2
A
A= _attachment($current->{"identity"})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 9 | my $disk = $scan->{target}{disk}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 9 | ▶ | return unless length($disk->{serial} // '') || length($disk->{wwn} // ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition28%2/7
length($disk->{"serial"} // "") or length($disk->{"wwn"} // "")
$disk->{"serial"} // ""
$disk->{"wwn"} // ""
MC/DC0%0/2
length($disk->{"serial"} // "") or length($disk->{"wwn"} // "")
$disk->{"serial"}
$disk->{"wwn"}
Truth table33%1/3
A or B
A= $disk->{"serial"}B= $disk->{"wwn"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 9 | for my $field (qw(serial wwn)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 17 | ▶ | return if ($disk->{$field} // '') ne ($current->{identity}{disk}{$field} // ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%4/4
$disk->{$field} // ""
$current->{"identity"}{"disk"}{$field} // ""
MC/DC100%1/1
$disk->{$field} // ""
$disk->{$field}
MC/DC100%1/1
$current->{"identity"}{"disk"}{$field} // ""
$current->{"identity"}{"disk"}{$field}
Truth table100%2/2
A
A= $disk->{$field}
Truth table100%2/2
A
A= $current->{"identity"}{"disk"}{$field}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 8 | my $jobs = $self->db->prepare( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | q{SELECT json_extract(record, '$.target') FROM jobs WHERE scanner=? AND id<>? AND (} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | . BLOCKS_REMOVAL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | . ')'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 8 | $jobs->execute($scan->{scanner_id}, $scan->{id}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 8 | ▶ | while (my $row = $jobs->fetchrow_arrayref) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 13 | ▶ | my $target = defined($row->[0]) ? from_json($row->[0]) : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 13 | ▶ | next if ref($target) eq 'HASH' && ($target->{kind} // '') eq 'host'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition40%2/5
ref $target eq "HASH" and ($target->{"kind"} // "") eq "host"
$target->{"kind"} // ""
MC/DC0%0/2
ref $target eq "HASH" and ($target->{"kind"} // "") eq "host"
ref $target eq "HASH"
$target->{"kind"}
Truth table33%1/3
A and B
A= ref $target eq "HASH"B= $target->{"kind"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 13 | ▶ | my $other = _attachment($target) // return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
_attachment($target) // (return)
MC/DC100%1/1
_attachment($target) // (return)
_attachment($target)
Truth table100%2/2
A
A= _attachment($target)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 12 | ▶ | return if $attachment eq $other; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 3 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 22 | ▶ | sub submit { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
submit: called CC=4 SCAR=14.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 22 | my ($self, $id, $scanner, $token, $tags, $note) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 22 | ▶ | die 'Invalid job' unless valid_id($id) && ($token // '') =~ /\A[a-f0-9]{64}\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition40%2/5
valid_id($id) and ($token // "") =~ /\A[a-f0-9]{64}\z/u
$token // ""
MC/DC0%0/2
valid_id($id) and ($token // "") =~ /\A[a-f0-9]{64}\z/u
valid_id($id)
$token
Truth table33%1/3
A and B
A= valid_id($id)B= $token
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | return $self->transaction( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 22 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 22 | my ($db) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 22 | my $old = $self->get($id); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 22 | ▶ | return $old->{scanner_id} eq $scanner && $old->{token} eq $token ? 200 : 409 if $old; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$old->{"scanner_id"} eq $scanner and $old->{"token"} eq $token
MC/DC0%0/2
$old->{"scanner_id"} eq $scanner and $old->{"token"} eq $token
$old->{"scanner_id"} eq $scanner
$old->{"token"} eq $token
Truth table33%1/3
A and B
A= $old->{"scanner_id"} eq $scannerB= $old->{"token"} eq $token
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 20 | ▶ | my $target = $self->selectable($scanner, $token) or return 409; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 17 | ▶ | return 409 if $db->selectrow_array( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | q{SELECT 1 FROM jobs WHERE scanner=? AND token=? AND | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | (finished=0 OR json_extract(record,'$.cleanup_status')='needs_cleanup')}, undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | $scanner, $token | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | my $record = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | status => 'queued', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | phase => 'queued', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | cleanup_status => 'unknown', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | target => $target->{identity}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 15 | warnings => [] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 15 | $db->do( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 'INSERT INTO jobs(id,scanner,token,created,tags,note,record) VALUES (?,?,?,?,?,?,?)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | undef, $id, $scanner, $token, now(), to_json($tags), $note, to_json($record) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 15 | return 202; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 22 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 2 | ▶ | sub cancel { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cancel: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 2 | my ($self, $id) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | return $self->transaction( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 2 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 2 | my ($db) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 2 | ▶ | my $scan = $self->get($id) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 2 | my $status = $scan->{status}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 2 | ▶ | if ($status eq 'queued') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 1 | $db->do( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | q{UPDATE jobs SET finished=1, record=json_set(record, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | '$.status','cancelled','$.phase','finished','$.finished_at',?, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | '$.cleanup_status','not_needed') WHERE id=?}, undef, now(), $id | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | elsif ($status eq 'running') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 1 | $db->do( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | q{UPDATE jobs SET record=json_set(record,'$.status','cancelling') WHERE id=?}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | undef, $id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | # A repeated click or a completion racing the form keeps the last result. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 2 | ▶ | sub pending_cancellations { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pending_cancellations: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 2 | my ($self, $scanner) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 2 | return $self->db->selectall_arrayref( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | q{SELECT id,run FROM jobs WHERE scanner=? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | AND finished=0 AND json_extract(record,'$.status')='cancelling' AND run IS NOT NULL}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | {Slice => {}}, $scanner | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 2 | ▶ | sub offer { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
offer: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 2 | my ($self, $scanner) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 2 | return $self->db->selectrow_hashref( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 'SELECT id,token FROM jobs WHERE scanner=? AND run IS NULL AND finished=0 ORDER BY created,id LIMIT 1', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | undef, $scanner | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 6 | ▶ | sub claim { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
claim: called CC=1 SCAR=0.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 6 | my ($self, $scanner, $id, $run) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | return $self->transaction( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 6 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=22.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 6 | my ($db) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 6 | ▶ | my $row = $db->selectrow_hashref( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | q{SELECT run,token,finished,json_extract(record,'$.status') AS status FROM jobs WHERE scanner=? AND id=?}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | undef, $scanner, $id | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | ) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 5 | ▶ | if (defined $row->{run}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 2 | ▶ | return unless $row->{run} eq $run; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 1 | ▶ | return 'cancel' if $row->{status} eq 'cancelling' || $row->{status} eq 'cancelled'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$row->{"status"} eq "cancelling" or $row->{"status"} eq "cancelled"
MC/DC0%0/2
$row->{"status"} eq "cancelling" or $row->{"status"} eq "cancelled"
$row->{"status"} eq "cancelling"
$row->{"status"} eq "cancelled"
Truth table33%1/3
A or B
A= $row->{"status"} eq "cancelling"B= $row->{"status"} eq "cancelled"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 3 | ▶ | return 'expired' if $row->{finished}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 3 | ▶ | unless ($self->selectable($scanner, $row->{token})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | $db->do( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | q{UPDATE jobs SET finished=1,record=json_set(record,'$.status','failed','$.phase','finished','$.error','Target no longer available','$.cleanup_status','not_needed') WHERE id=?}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | undef, $id | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | return 'expired'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | $db->do( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 3 | q{UPDATE jobs SET run=?, record=json_set(record,'$.status','running','$.phase','validating') WHERE id=?}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | undef, $run, $id | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 3 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 6 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 23 | ▶ | sub owns { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
owns: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 23 | my ($self, $scanner, $id, $run) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 23 | scalar $self->db->selectrow_array('SELECT 1 FROM jobs WHERE scanner=? AND id=? AND run=?', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | undef, $scanner, $id, $run); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 121 | ▶ | sub get { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 121 | my ($self, $id) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 121 | ▶ | return unless valid_id($id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 120 | ▶ | my $row = $self->db->selectrow_hashref('SELECT * FROM jobs WHERE id=?', undef, $id) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 99 | %{from_json($row->{record})}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | id => $id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | scanner_id => $row->{scanner}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | token => $row->{token}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | created_at => $row->{created}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | tags => from_json($row->{tags}), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | note => $row->{note} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 99 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 5 | ▶ | sub history { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
history: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 5 | my ($self, $tag, $page) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 5 | ▶ | my $filter = length($tag) ? 'WHERE EXISTS(SELECT 1 FROM json_each(tags) WHERE value=?)' : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 5 | ▶ | my $rows = $self->db->selectall_arrayref( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | "SELECT id, scanner AS scanner_id, created AS created_at, tags, json_extract(record,'\$.status') AS status, json_extract(record,'\$.phase') AS phase, json_extract(record,'\$.cleanup_status') AS cleanup_status FROM jobs $filter ORDER BY created DESC,id DESC LIMIT 51 OFFSET ?", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | {Slice => {}}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | (length($tag) ? ($tag) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | ($page - 1) * 50 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 5 | $_->{tags} = from_json($_->{tags}) for @$rows; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 5 | return $rows; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 2 | ▶ | sub change_tags { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
change_tags: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 2 | my ($self, $id, $operation, $values) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | return $self->transaction( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 2 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 2 | my $tags = $self->get($id)->{tags}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | $tags = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | $operation eq 'add' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | ? Mogura::Server::Tags->validate([@$tags, @$values]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 2 | ▶ | : [grep { $_ ne $values->[0] } @$tags]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 2 | $self->db->do('UPDATE jobs SET tags=? WHERE id=?', undef, to_json($tags), $id); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 2 | return $tags; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 51 | ▶ | sub directory { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
directory: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 51 | my ($self, $id) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 51 | ▶ | die 'Invalid job' unless valid_id($id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 51 | return path($self->state, 'artifacts', $id); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 127 | ▶ | sub artifact { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
artifact: called CC=6 SCAR=18.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 127 | my ($self, $id, $kind) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 127 | ▶ | my $name = artifact_name($kind) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 126 | ▶ | unless valid_id($id) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
valid_id($id) and $self->db->selectrow_array("SELECT 1 FROM receipts WHERE job=? AND kind=?", undef, $id, $kind)
MC/DC100%2/2
valid_id($id) and $self->db->selectrow_array("SELECT 1 FROM receipts WHERE job=? AND kind=?", undef, $id, $kind)
valid_id($id)
$self->db->selectrow_array("SELECT 1 FROM receipts WHERE job=? AND kind=?", undef, $id, $kind)
Truth table100%3/3
A and B
A= valid_id($id)B= $self->db->selectrow_array("SELECT 1 FROM receipts WHERE job=? AND kind=?", undef, $id, $kind)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | && $self->db->selectrow_array('SELECT 1 FROM receipts WHERE job=? AND kind=?', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | undef, $id, $kind); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 44 | my $file = $self->directory($id)->child($name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 44 | ▶ | return -f $file && !-l $file ? $file : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-f $file and not -l $file
MC/DC0%0/2
-f $file and not -l $file
-f $file
not -l $file
Truth table33%1/3
A and not(B)
A= -f $fileB= not -l $file
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | ▶ | sub receive { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
receive: not called CC=23 SCAR=63.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | my ($self, $scanner, $id, $run, $kind, $source, $size, $digest) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | ▶ | my $name = artifact_name($kind) or die 'Invalid kind'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | ▶ | die 'Unassigned run' unless $self->owns($scanner, $id, $run); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | ▶ | die 'Incomplete upload' unless -s $source == $size; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | ▶ | open my $fh, '<:raw', $source or die "Open upload: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | die 'Checksum mismatch' unless Digest::SHA->new(256)->addfile($fh)->hexdigest eq $digest; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | my ($accepted) = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | $self->db->selectrow_array('SELECT hash FROM receipts WHERE job=? AND run=? AND kind=?', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | undef, $id, $run, $kind); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | die 'Conflicting receipt' if defined($accepted) && $accepted ne $digest; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $accepted and $accepted ne $digest
MC/DC0%0/2
defined $accepted and $accepted ne $digest
defined $accepted
$accepted ne $digest
Truth table0%0/3
A and B
A= defined $acceptedB= $accepted ne $digest
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | ▶ | return if defined($accepted) && $self->artifact($id, $kind); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $accepted and $self->artifact($id, $kind)
MC/DC0%0/2
defined $accepted and $self->artifact($id, $kind)
defined $accepted
$self->artifact($id, $kind)
Truth table0%0/3
A and B
A= defined $acceptedB= $self->artifact($id, $kind)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | ▶ | if ($kind eq 'log') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | seek $fh, 0, 0 or die "Seek log: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | my $read = read $fh, my $chunk, 65536; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | ▶ | die "Read log: $!" unless defined $read; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | ▶ | last unless $read; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | ▶ | die 'Expected a text log' if index($chunk, "\0") >= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | require Mogura::ResultStream; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | Mogura::ResultStream->valid_artifact($source, $kind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | my $file = $self->directory($id)->make_path({mode => 0700})->child($name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | # An immutable link survives a crash before the receipt commits. A retry | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | # checks the actual file before adopting an orphaned publication. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | ▶ | $fh->sync or die "Sync upload: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | ▶ | unless (link $source, $file) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | die "Publish upload: $!" unless $!{EEXIST}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | ▶ | open my $old, '<:raw', $file or die "Open published artifact: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | ▶ | die 'Conflicting artifact' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-s $old == $size and "Digest::SHA"->new(256)->addfile($old)->hexdigest eq $digest
MC/DC0%0/2
-s $old == $size and "Digest::SHA"->new(256)->addfile($old)->hexdigest eq $digest
-s $old == $size
"Digest::SHA"->new(256)->addfile($old)->hexdigest eq $digest
Truth table0%0/3
A and B
A= -s $old == $sizeB= "Digest::SHA"->new(256)->addfile($old)->hexdigest eq $digest
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | unless -s $old == $size && Digest::SHA->new(256)->addfile($old)->hexdigest eq $digest; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | my $dir = $file->dirname; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | for my $parent ($dir, $dir->dirname, path($self->state)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | ▶ | $parent->open('<')->sync or die "Sync artifact directory: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | $self->db->do('INSERT OR IGNORE INTO receipts(job,run,kind,hash) VALUES (?,?,?,?)', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | undef, $id, $run, $kind, $digest); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 10 | ▶ | sub update_run { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update_run: called CC=1 SCAR=0.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 10 | my ($self, $scanner, $id, $run, $data, $final) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | return $self->transaction( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 10 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=37 SCAR=40.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 10 | my ($db) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 10 | ▶ | my $row = $db->selectrow_hashref( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 'SELECT record,finished FROM jobs WHERE id=? AND scanner=? AND run=?', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | undef, $id, $scanner, $run) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 9 | my $old = from_json($row->{record}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 9 | ▶ | if ($row->{finished}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 3 | ▶ | if ($final | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition69%9/13
$final and ($old->{"cleanup_status"} // "") eq "needs_cleanup" and ($data->{"cleanup_status"} // "") eq "unmounted" and $data->{"sequence"} > $old->{"sequence"}
$final and ($old->{"cleanup_status"} // "") eq "needs_cleanup" and ($data->{"cleanup_status"} // "") eq "unmounted"
$final and ($old->{"cleanup_status"} // "") eq "needs_cleanup"
$old->{"cleanup_status"} // ""
$data->{"cleanup_status"} // ""
MC/DC25%1/4
$final and ($old->{"cleanup_status"} // "") eq "needs_cleanup" and ($data->{"cleanup_status"} // "") eq "unmounted" and $data->{"sequence"} > $old->{"sequence"}
$final
$old->{"cleanup_status"}
$data->{"cleanup_status"}
$data->{"sequence"} > $old->{"sequence"}
Truth table40%2/5
A and B and C and D
A= $finalB= $old->{"cleanup_status"}C= $data->{"cleanup_status"}D= $data->{"sequence"} > $old->{"sequence"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | && ($old->{cleanup_status} // '') eq 'needs_cleanup' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | && ($data->{cleanup_status} // '') eq 'unmounted' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | && $data->{sequence} > $old->{sequence}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | $db->do( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | q{UPDATE jobs SET record=json_set(record,'$.cleanup_status','unmounted','$.sequence',?) WHERE id=?}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 1 | undef, 0 + $data->{sequence}, $id | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 3 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 6 | ▶ | return !$final if ($old->{sequence} // 0) > $data->{sequence}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$old->{"sequence"} // 0
MC/DC100%1/1
$old->{"sequence"} // 0
$old->{"sequence"}
Truth table100%2/2
A
A= $old->{"sequence"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 6 | ▶ | return 1 if !$final && ($old->{sequence} // 0) == $data->{sequence}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition60%3/5
not $final and ($old->{"sequence"} // 0) == $data->{"sequence"}
$old->{"sequence"} // 0
MC/DC0%0/2
not $final and ($old->{"sequence"} // 0) == $data->{"sequence"}
not $final
$old->{"sequence"}
Truth table66%2/3
not(A) and B
A= not $finalB= $old->{"sequence"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 6 | ▶ | my $cleanup = $data->{cleanup_status} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$data->{"cleanup_status"} // ""
MC/DC0%0/1
$data->{"cleanup_status"} // ""
$data->{"cleanup_status"}
Truth table50%1/2
A
A= $data->{"cleanup_status"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 6 | ▶ | return unless $cleanup =~ /\A(?:unknown|mounted|unmounted|not_needed|needs_cleanup)\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | my $record = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 6 | ▶ | {map { exists $data->{$_} ? ($_ => $data->{$_}) : () } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | qw(sequence phase started_at finished_at warnings error failed_phase syft_version grype_version grype_db sbom_sha256 exclusions) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 6 | $record->{target} = $old->{target}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | $record->{status} = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | $final ? $data->{status} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 6 | ▶ | : ($data->{phase} // '') eq 'finished' ? 'transferring' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%1/2
$data->{"phase"} // ""
MC/DC0%0/1
$data->{"phase"} // ""
$data->{"phase"}
Truth table50%1/2
A
A= $data->{"phase"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | : 'running'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 6 | ▶ | if ($old->{status} eq 'cancelling') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 1 | ▶ | if (!$final) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | $record->{status} = 'cancelling'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | elsif ($record->{status} eq 'interrupted') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | $record->{status} = 'cancelled'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | $record->{outcome} = $final ? $record->{status} : $data->{status} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 6 | ▶ | if ($data->{phase} // '') eq 'finished'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%1/2
$data->{"phase"} // ""
MC/DC0%0/1
$data->{"phase"} // ""
$data->{"phase"}
Truth table50%1/2
A
A= $data->{"phase"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 6 | $record->{cleanup_status} = $cleanup; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 6 | ▶ | if ($final) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 5 | ▶ | unless ($record->{status} // '') =~ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$record->{"status"} // ""
MC/DC0%0/1
$record->{"status"} // ""
$record->{"status"}
Truth table50%1/2
A
A= $record->{"status"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | /\A(?:completed|partial|failed|interrupted|cancelled)\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 5 | ▶ | return if $record->{status} eq 'cancelled' && $old->{status} ne 'cancelling'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$record->{"status"} eq "cancelled" and $old->{"status"} ne "cancelling"
MC/DC0%0/2
$record->{"status"} eq "cancelled" and $old->{"status"} ne "cancelling"
$record->{"status"} eq "cancelled"
$old->{"status"} ne "cancelling"
Truth table33%1/3
A and B
A= $record->{"status"} eq "cancelled"B= $old->{"status"} ne "cancelling"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 5 | ▶ | if ($record->{status} eq 'completed') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | unless $cleanup eq | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 3 | ▶ | (($old->{target}{kind} // '') eq 'host' ? 'not_needed' : 'unmounted'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%1/2
$old->{"target"}{"kind"} // ""
MC/DC0%0/1
$old->{"target"}{"kind"} // ""
$old->{"target"}{"kind"}
Truth table50%1/2
A
A= $old->{"target"}{"kind"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 2 | ▶ | return if grep { !$self->artifact($id, $_) } qw(syft cdx grype); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 4 | ▶ | $db->do('UPDATE jobs SET record=?,finished=? WHERE id=?', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | undef, to_json($record), $final ? 1 : 0, $id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 4 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 10 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||