| 1 | # Copyright (c) 2025-2026 Philipp Schafft | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | # licensed under Artistic License 2.0 (see LICENSE file) | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | # ABSTRACT: Module for interacting with file stores | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | package File::FStore::Migration; | ||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use v5.10; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use Fcntl qw(SEEK_CUR); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use parent 'File::FStore::Base'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | our $VERSION = v0.08; | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | ▶ | sub upgrade { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
upgrade: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | croak 'Stray options passed' if scalar @args; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | # Currently a no-op. | ||||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | #@returns File::FStore::Adder | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | sub new_adder { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_adder: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | return $self->store->new_adder(@args); | |||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | sub import_data { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import_data: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | my ($self, $handle, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | my $store = $self->store; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | my $format = delete($opts{format}) // 'json'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
delete $opts{"format"} // "json"
MC/DC0%0/1
delete $opts{"format"} // "json"
delete $opts{"format"}
Truth table0%0/2
A
A= delete $opts{"format"}
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | my $use_contentise = delete($opts{use_contentise}); | |||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | croak 'Stray options passed' if scalar keys %opts; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | $handle->binmode; | |||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | $store->in_transaction(rw => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=47 SCAR=77.2
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | if ($format eq 'json') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | require JSON; | |||||||||||||||||||||||||||||||||||||||||
| 50 | my $json = do { | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | local $/ = undef; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | JSON::decode_json(<$handle>); | |||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | }->{files}; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | foreach my $dbname (keys %{$json}) { | |||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | my $d = $json->{$dbname}; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | my $file; | |||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | if ($use_contentise) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | $file = $store->query(properties => contentise => $d->{properties}{contentise} // croak 'No contentise'); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$d->{"properties"}{"contentise"} // croak("No contentise")
MC/DC0%0/1
$d->{"properties"}{"contentise"} // croak("No contentise")
$d->{"properties"}{"contentise"}
Truth table0%0/2
A
A= $d->{"properties"}{"contentise"}
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | $file = $store->query(dbname => $dbname); | |||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | $d = { | ||||||||||||||||||||||||||||||||||||||||||
| 65 | properties => $d->{properties} // {}, | ||||||||||||||||||||||||||||||||||||||||||
| 66 | digests => $d->{hashes} // {}, | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/4
$d->{"properties"} // {}
$d->{"hashes"} // {}
MC/DC0%0/1
$d->{"properties"} // {}
$d->{"properties"}
MC/DC0%0/1
$d->{"hashes"} // {}
$d->{"hashes"}
Truth table0%0/2
A
A= $d->{"properties"}
Truth table0%0/2
A
A= $d->{"hashes"}
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | $file->set($d); | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | } elsif ($format eq 'bundle') { | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | my $data; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my $len = $handle->read($data, 8); | |||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | my %index; | |||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | croak 'Bad magic' unless $len == 8 && $data eq "!<arch>\x0A"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$len == 8 and $data eq "!<arch>\n"
MC/DC0%0/2
$len == 8 and $data eq "!<arch>\n"
$len == 8
$data eq "!<arch>\n"
Truth table0%0/3
A and B
A= $len == 8B= $data eq "!<arch>\n"
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | # Read index: | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | $len = $handle->read($data, 60); | |||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | croak 'Bad archive header' unless $len == 60; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | { | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | my ($name, $date, $uid, $gid, $mode, $size, $magic) = unpack('A16A12A6A6A8A10a2', $data); | |||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | croak 'Bad archive header data' unless $magic eq "\x60\x0A" && $mode =~ /^[4-7]{3}\z/ && $name eq '.FSTORE_INDEX/'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$magic eq "`\n" and $mode =~ /^[4-7]{3}\z/ and $name eq ".FSTORE_INDEX/"
$magic eq "`\n" and $mode =~ /^[4-7]{3}\z/
MC/DC0%0/3
$magic eq "`\n" and $mode =~ /^[4-7]{3}\z/ and $name eq ".FSTORE_INDEX/"
$magic eq "`\n"
$mode =~ /^[4-7]{3}\z/
$name eq ".FSTORE_INDEX/"
Truth table0%0/4
A and B and C
A= $magic eq "`\n"B= $mode =~ /^[4-7]{3}\z/C= $name eq ".FSTORE_INDEX/"
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | $size = int $size; | |||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | $len = $handle->read($data, $size); | |||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | croak 'IO error while reading index body' unless $len == $size; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | while ($data =~ s/^(data-\S+)\s+(\S+)\s+(\S+\/\S+|-)\s+(\S.+)\x0A//) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | my ($filename, $contentise, $mediasubtype, $hashes) = ($1, $2, $3, $4); | |||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | my %digests; | |||||||||||||||||||||||||||||||||||||||||
| 94 | my %properties; | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | my %info = (properties => \%properties, digests => \%digests); | |||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | my $given_size; | |||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | croak 'Index entries without contentise are current not supported' unless length($contentise) == 36; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | $index{$filename} = {filename => $filename, contentise => $contentise, info => \%info}; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | $properties{contentise} = $contentise; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | $properties{mediasubtype} = $mediasubtype if $mediasubtype ne '-'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | while ($hashes =~ s/^(v0m?) ([a-z]+)-([0-9]+)-([0-9]+) bytes 0-([0-9]+)\/([0-9]+) ([0-9a-f]+)( |$)//) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | my ($type, $name, $version, $bits, $end, $size, $hash, $mark) = ($1, $2, $3, $4, $5, $6, $7, $8); | |||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | next if $end != ($size - 1); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | die if (length($hash) * 4) != $bits; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | die if $type eq 'v0' && length($mark); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$type eq "v0" and length $mark
MC/DC0%0/2
$type eq "v0" and length $mark
$type eq "v0"
length $mark
Truth table0%0/3
A and B
A= $type eq "v0"B= length $mark
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | $given_size //= $size; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$given_size //= $size
MC/DC0%0/2
$given_size //= $size
$given_size
$size
Truth table0%0/3
A //= B
A= $given_sizeB= $size
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | die unless $given_size == $size; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | $digests{join('-', $name, $version, $bits)} = $hash; | |||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | $properties{size} = int($given_size) if defined $given_size; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | croak 'Corrupted or unsupported index' if length($data); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | # Read actual files: | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | my ($name, $date, $uid, $gid, $mode, $size, $magic); | |||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | my $ent; | |||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | my $file; | |||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | $len = $handle->read($data, 60); | |||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | last if $len == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | croak 'Bad archive header' unless $len == 60; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ($name, $date, $uid, $gid, $mode, $size, $magic) = unpack('A16A12A6A6A8A10a2', $data); | |||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | croak 'Bad archive header data' unless $magic eq "\x60\x0A" && $mode =~ /^[4-7]{3}\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$magic eq "`\n" and $mode =~ /^[4-7]{3}\z/
MC/DC0%0/2
$magic eq "`\n" and $mode =~ /^[4-7]{3}\z/
$magic eq "`\n"
$mode =~ /^[4-7]{3}\z/
Truth table0%0/3
A and B
A= $magic eq "`\n"B= $mode =~ /^[4-7]{3}\z/
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | $size = int $size; | |||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | $name =~ s#/\z##; | |||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | $ent = delete $index{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | croak 'Invalid file in archive' unless defined $ent; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | $ent->{info}{properties}{size} //= $size; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$ent->{"info"}{"properties"}{"size"} //= $size
MC/DC0%0/2
$ent->{"info"}{"properties"}{"size"} //= $size
$ent->{"info"}{"properties"}{"size"}
$size
Truth table0%0/3
A //= B
A= $ent->{"info"}{"properties"}{"size"}B= $size
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | croak 'Entry size mismatch' unless $ent->{info}{properties}{size} == $size; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ($file) = $store->query(properties => {contentise => $ent->{contentise}, size => $size}); | |||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | if (defined $file) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | # we found the file | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | unless ($handle->seek($size, SEEK_CUR)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | # seek didn't work, so we need to read... | ||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | my $left = $size; | |||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | while ($left > 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | my $todo = $left < 65536 ? $left : 65536; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | $len = $handle->read($data, $todo); | |||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | if ($len < $todo) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | croak 'IO error reading bundle'; | |||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | $left -= $len; | |||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | $file->set($ent->{info}); | |||||||||||||||||||||||||||||||||||||||||
| 166 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 167 | # we need to add the file | ||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | my $adder = $self->new_adder; | |||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | my $filename = $adder->_temp_filename; # TODO: FIXME: Not part of public API! | |||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | $adder->set($ent->{info}); | |||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | { | ||||||||||||||||||||||||||||||||||||||||||
| 174 | # IO transfer loop | ||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | my $left = $size; | |||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | open(my $out, '>', $filename) or die $!; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | $out->binmode; | |||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | while ($left > 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | my $todo = $left < 65536 ? $left : 65536; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | $len = $handle->read($data, $todo); | |||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | if ($len < $todo) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | croak 'IO error reading bundle'; | |||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | $out->print($data); | |||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | $left -= $len; | |||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | $file = $adder->insert; | |||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | if ($size & 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | # We need to read the padding. | ||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | $len = $handle->read($data, 1); | |||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | croak 'Corrupted archive, bad padding' unless $len == 1 && $data eq "\x0A"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$len == 1 and $data eq "\n"
MC/DC0%0/2
$len == 1 and $data eq "\n"
$len == 1
$data eq "\n"
Truth table0%0/3
A and B
A= $len == 1B= $data eq "\n"
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | if (keys %index) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | croak 'Unused index entries'; | |||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||
| 206 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | croak 'Unsupported format given: '.$format; | |||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | sub export_data { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
export_data: not called CC=31 SCAR=69.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | my ($self, $handle, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | my $format = delete($opts{format}) // 'json'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
delete $opts{"format"} // "json"
MC/DC0%0/1
delete $opts{"format"} // "json"
delete $opts{"format"}
Truth table0%0/2
A
A= delete $opts{"format"}
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | my $list = delete($opts{list}); | |||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | my $query = delete($opts{query}); | |||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | croak 'Stray options passed' if scalar keys %opts; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | $handle->binmode; | |||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | $list //= do { | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$list //= do {
$query //= ["all"];
[$self->store->query(@{$query;})]
}
MC/DC0%0/2
$list //= do {
$query //= ["all"];
[$self->store->query(@{$query;})]
}
$list
do {
$query //= ["all"];
[$self->store->query(@{$query;})]
}
Truth table0%0/3
A //= B
A= $listB= do {
$query //= ["all"];
[$self->store->query(@{$query;})]
}
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | $query //= ['all']; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$query //= ["all"]
MC/DC0%0/1
$query //= ["all"]
$query
Truth table0%0/2
A
A= $query
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | [$self->store->query(@{$query})]; | |||||||||||||||||||||||||||||||||||||||||
| 226 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | if ($format eq 'json') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | require JSON; | |||||||||||||||||||||||||||||||||||||||||
| 230 | $handle->say(JSON::encode_json({ | ||||||||||||||||||||||||||||||||||||||||||
| 231 | files => { | ||||||||||||||||||||||||||||||||||||||||||
| 232 | map { | ||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | my $res = $_->get; | |||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | $res->{hashes} = delete $res->{digests}; | |||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | $_->dbname => $res | |||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | } @{$list} | |||||||||||||||||||||||||||||||||||||||||
| 237 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 238 | })); | ||||||||||||||||||||||||||||||||||||||||||
| 239 | } elsif ($format eq 'valuefile') { | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | require File::ValueFile::Simple::Writer; | |||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | my $writer = File::ValueFile::Simple::Writer->new($handle, format => 'e5da6a39-46d5-48a9-b174-5c26008e208e'); | |||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | my %mediasubtype_cache; | |||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | foreach my $file (@{$list}) { | |||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | my Data::Identifier $ise = Data::Identifier->new(uuid => $file->contentise(as => 'uuid'), displayname => $file->dbname); | |||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | my $size = eval {$file->get(properties => 'size')}; | |||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | my $mediasubtype = eval {$file->get(properties => 'mediasubtype')}; | |||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | my $digests = $file->get('digests'); | |||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | ▶ | if (defined $mediasubtype) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | $mediasubtype = $mediasubtype_cache{$mediasubtype} //= Data::Identifier::Generate->generic( | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$mediasubtype_cache{$mediasubtype} //= "Data::Identifier::Generate"->generic("namespace", "50d7c533-2d9b-4208-b560-bcbbf75ce3f9", "input", $mediasubtype)
MC/DC0%0/2
$mediasubtype_cache{$mediasubtype} //= "Data::Identifier::Generate"->generic("namespace", "50d7c533-2d9b-4208-b560-bcbbf75ce3f9", "input", $mediasubtype)
$mediasubtype_cache{$mediasubtype}
"Data::Identifier::Generate"->generic("namespace", "50d7c533-2d9b-4208-b560-bcbbf75ce3f9", "input", $mediasubtype)
Truth table0%0/3
A //= B
A= $mediasubtype_cache{$mediasubtype}B= "Data::Identifier::Generate"->generic("namespace", "50d7c533-2d9b-4208-b560-bcbbf75ce3f9", "input", $mediasubtype)
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | namespace => '50d7c533-2d9b-4208-b560-bcbbf75ce3f9', | ||||||||||||||||||||||||||||||||||||||||||
| 253 | input => $mediasubtype, | ||||||||||||||||||||||||||||||||||||||||||
| 254 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | $writer->write; | |||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | $writer->write_tag_ise($ise); | |||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | if (defined $size) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | $writer->write_tag_metadata($ise, '1cd4a6c6-0d7c-48d1-81e7-4e8d41fdb45d', $size); | |||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | foreach my $digest (sort keys %{$digests}) { | |||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | $writer->write_tag_metadata($ise, '79385945-0963-44aa-880a-bca4a42e9002', sprintf('v0 %s bytes 0-%u/%u %s', $digest, $size - 1, $size, $digests->{$digest})); | |||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | $writer->write_tag_relation($ise, '448c50a8-c847-4bc7-856e-0db5fea8f23b', $mediasubtype) if defined $mediasubtype; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | $writer->write_tag_relation($ise, 'd2750351-aed7-4ade-aa80-c32436cc6030', '52a516d0-25d8-47c7-a6ba-80983e576c54'); # also-has-role: proto-file | |||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||
| 269 | } elsif ($format eq 'bundle') { | ||||||||||||||||||||||||||||||||||||||||||
| 270 | # Write magic: | ||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | $handle->print("!<arch>\x0A"); | |||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||
| 273 | # Write index: | ||||||||||||||||||||||||||||||||||||||||||
| 274 | { | ||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | my $index = ''; | |||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | my $algos = $self->store->_used_digests; | |||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | ▶ | for (my $idx = 0; $idx < scalar(@{$list}); $idx++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | my $file = $list->[$idx]; | |||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | my $info = $file->get; | |||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | my $size = $info->{properties}{size}; | |||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | my $name = 'data-'.$idx; | |||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | my $ext = $file->_ext; | |||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | my $hashes = ''; | |||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | my @hashes; | |||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | ▶ | $name .= '.'.$ext if defined $ext; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | foreach my $key (@{$algos}) { | |||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | ▶ | my $value = $info->{digests}{$key} // next; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$info->{"digests"}{$key} // (next)
MC/DC0%0/1
$info->{"digests"}{$key} // (next)
$info->{"digests"}{$key}
Truth table0%0/2
A
A= $info->{"digests"}{$key}
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | ▶ | if ($size > 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | push(@hashes, sprintf('%s bytes 0-%u/%u %s', $key, $size - 1, $size, $value)); | |||||||||||||||||||||||||||||||||||||||||
| 294 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | push(@hashes, sprintf('%s bytes 0-/%u %s', $key, $size, $value)); | |||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | ▶ | if (scalar(@hashes) > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | my $last = pop(@hashes); | |||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | $hashes = 'v0m '.join(' v0m ', @hashes).' v0 '.$last; | |||||||||||||||||||||||||||||||||||||||||
| 302 | } elsif (scalar(@hashes)) { | ||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | $hashes = 'v0 '.$hashes[0]; | |||||||||||||||||||||||||||||||||||||||||
| 304 | } elsif ($size > 0) { | ||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | $hashes = sprintf('v0 sha-3-512 0-%u/%u ...', $size - 1, $size); | |||||||||||||||||||||||||||||||||||||||||
| 306 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | $hashes = 'v0 sha-3-512 0-/0 ...'; | |||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | ▶ | $index .= sprintf("%s %s %s %s\x0A", $name, $file->contentise, $info->{properties}{mediasubtype} // '-', $hashes); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$info->{"properties"}{"mediasubtype"} // "-"
MC/DC0%0/1
$info->{"properties"}{"mediasubtype"} // "-"
$info->{"properties"}{"mediasubtype"}
Truth table0%0/2
A
A= $info->{"properties"}{"mediasubtype"}
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | $handle->print(pack('A16A12A6A6A8A10A2', '.FSTORE_INDEX/', 0, 0, 0, '444', length($index), "\x60\x0A")); | |||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | $handle->print($index); | |||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | ▶ | $handle->print("\x0A") if length($index) & 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | # Write data files: | ||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | ▶ | for (my $idx = 0; $idx < scalar(@{$list}); $idx++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | my $file = $list->[$idx]; | |||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | my $fh = $file->open; | |||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | my $size = $file->get(properties => 'size'); | |||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | my $name = 'data-'.$idx; | |||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | my $ext = $file->_ext; | |||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | ▶ | my $date = ($file->stat)[9] // 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
($file->stat)[9] // 0
MC/DC0%0/1
($file->stat)[9] // 0
($file->stat)[9]
Truth table0%0/2
A
A= ($file->stat)[9]
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | my $pad = $size & 1; | |||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | ▶ | $name .= '.'.$ext if defined $ext; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | $name .= '/'; | |||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | $handle->print(pack('A16A12A6A6A8A10A2', $name, $date, 0, 0, '444', $size, "\x60\x0A")); | |||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||
| 333 | # Write data: | ||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | $fh->binmode; | |||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | ▶ | while ($size) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | ▶ | my $todo = $size < 65536 ? $size : 65536; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | my $done = $fh->read(my $data, $todo); | |||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | ▶ | if ($done < $todo) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | croak 'IO error reading '.$file->dbname; | |||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | $handle->print($data); | |||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | $size -= $done; | |||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | ▶ | $handle->print("\x0A") if $pad; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||
| 350 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | croak 'Unsupported format given: '.$format; | |||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | sub insert_directory { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
insert_directory: not called CC=19 SCAR=59.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | my ($self, $directory, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | my $adder = $self->new_adder; | |||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | my $basename_filter = $opts{basename_filter}; | |||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | my $on_pre_insert = $opts{on_pre_insert}; | |||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | my $on_post_insert = $opts{on_post_insert}; | |||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | ▶ | my $on_error = $opts{on_error} // sub {croak $@}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
$opts{"on_error"} // sub {
croak($@);
}
MC/DC0%0/2
$opts{"on_error"} // sub {
croak($@);
}
$opts{"on_error"}
sub {
croak($@);
}
Truth table0%0/3
A // B
A= $opts{"on_error"}B= sub {
croak($@);
}
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | ▶ | my $update = $opts{update} // 'none'; # FIXME: $adder->insert already calls update, so this does not work as expected. | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$opts{"update"} // "none"
MC/DC0%0/1
$opts{"update"} // "none"
$opts{"update"}
Truth table0%0/2
A
A= $opts{"update"}
| |||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | ▶ | my $in_mode = $opts{in_mode} // 'link_in'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$opts{"in_mode"} // "link_in"
MC/DC0%0/1
$opts{"in_mode"} // "link_in"
$opts{"in_mode"}
Truth table0%0/2
A
A= $opts{"in_mode"}
| |||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | ▶ | my $in_func = $in_mode eq 'move_in' ? $adder->can('move_in') : $adder->can('link_in'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | ▶ | $update = 'new' if $update eq 'all'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | ▶ | $on_error = undef if $on_error eq 'ignore'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | ▶ | opendir(my $d, $directory) or croak $!; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | ▶ | while (defined(my $e = readdir($d))) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | my $path; | |||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | ▶ | next if $e =~ /^\./; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | ▶ | next if defined($basename_filter) && $e !~ $basename_filter; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $basename_filter and not $e =~ /$basename_filter/
MC/DC0%0/2
defined $basename_filter and not $e =~ /$basename_filter/
defined $basename_filter
not $e =~ /$basename_filter/
Truth table0%0/3
A and not(B)
A= defined $basename_filterB= not $e =~ /$basename_filter/
| |||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | $path = File::Spec->catfile($directory, $e); | |||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | ▶ | if (-f $path) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | my $file; | |||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | $adder->$in_func($path); | |||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | ▶ | $on_pre_insert->($adder, path => $path, basename => $e) if defined $on_pre_insert; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | $file = eval { $adder->insert }; | |||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | ▶ | $on_error->(undef, path => $path, basename => $e) if $on_error && $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$on_error and $@
MC/DC0%0/2
$on_error and $@
$on_error
$@
Truth table0%0/3
A and B
A= $on_errorB= $@
| |||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | $adder->reset; | |||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | ▶ | if (defined $file) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | ▶ | if ($update eq 'new') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | $file->update(%opts{qw(on_pre_set on_post_set)}); | |||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | ▶ | $on_post_insert->($file, path => $path, basename => $e) if defined $on_post_insert; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||
| 395 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | $path = File::Spec->catdir($directory, $e); | |||||||||||||||||||||||||||||||||||||||||
| 397 | #warn 'D: '.$path; | ||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | $self->insert_directory($path, %opts); | |||||||||||||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | closedir($d); | |||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | ▶ | sub insert_tagpool { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
insert_tagpool: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | my ($self, $path, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | my $on_pre_insert = $opts{on_pre_insert}; | |||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | ▶ | $opts{on_pre_insert} = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | my ($adder, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | my ($uuid) = $opts{basename} =~ /^file\.([0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12})(?:\..*)?$/; | |||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | ▶ | $adder->set(properties => inodeise => $uuid) if defined $uuid; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | ▶ | $on_pre_insert->($adder, %opts) if defined $on_pre_insert; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | $opts{basename_filter} = qr/^file\./; | |||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | $self->insert_directory( | |||||||||||||||||||||||||||||||||||||||||
| 421 | File::Spec->catdir($path, 'data'), | ||||||||||||||||||||||||||||||||||||||||||
| 422 | %opts, | ||||||||||||||||||||||||||||||||||||||||||
| 423 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||
| 426 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||
| 428 | __END__ | ||||||||||||||||||||||||||||||||||||||||||