FStore/Migration.pm

filter: Statementstmt 9.3% 24 / 258 Branchbran 0.7% 1 / 142 Conditioncond 0.0% 0 / 61 MC/DCmcdc 0.0% 0 / 36 Subroutinesub 50.0% 8 / 16 Podpod 100% 6 / 6 totaltotal 7.5% 39 / 519 CC 100 SCAR 71.3
CC
100
Cov
5%
__ANON__
2256.0
export_data
992.0
insert_directory
380.0
CRAP 1253.0
↑ Summary FStore/File.pm »
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
BranchTrueFalseTotal
if scalar @args 0 1 1
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"
l!l
00
MC/DC0%0/1
delete $opts{"format"} // "json"
delete $opts{"format"}
Truth table0%0/2
A
A= delete $opts{"format"}
Aresult
11
00
41 0 my $use_contentise = delete($opts{use_contentise});
42  
43 0 ▶ croak 'Stray options passed' if scalar keys %opts;
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %opts 0 0 0
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
BranchTrueFalseTotal
if ($format eq 'json') { } 0 0 0
elsif ($format eq 'bundle') { } 0 0 0
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
BranchTrueFalseTotal
if ($use_contentise) { } 0 0 0
59 0 ▶ $file = $store->query(properties => contentise => $d->{properties}{contentise} // croak 'No contentise');
Condition0%0/2
$d->{"properties"}{"contentise"} // croak("No contentise")
l!l
00
MC/DC0%0/1
$d->{"properties"}{"contentise"} // croak("No contentise")
$d->{"properties"}{"contentise"}
Truth table0%0/2
A
A= $d->{"properties"}{"contentise"}
Aresult
11
00
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"} // {}
l!l
00
$d->{"hashes"} // {}
l!l
00
MC/DC0%0/1
$d->{"properties"} // {}
$d->{"properties"}
MC/DC0%0/1
$d->{"hashes"} // {}
$d->{"hashes"}
Truth table0%0/2
A
A= $d->{"properties"}
Aresult
11
00
Truth table0%0/2
A
A= $d->{"hashes"}
Aresult
11
00
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
BranchTrueFalseTotal
unless $len == 8 and $data eq "!<arch>\n" 0 0 0
Condition0%0/3
$len == 8 and $data eq "!<arch>\n"
!ll&&!rl&&r
000
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"
ABresult
0X0
100
111
76  
77 # Read index:
78 0 $len = $handle->read($data, 60);
79 0 ▶ croak 'Bad archive header' unless $len == 60;
Branch: 1 branch
BranchTrueFalseTotal
unless $len == 60 0 0 0
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
BranchTrueFalseTotal
unless $magic eq "`\n" and $mode =~ /^[4-7]{3}\z/ and $name eq ".FSTORE_INDEX/" 0 0 0
Condition0%0/6
$magic eq "`\n" and $mode =~ /^[4-7]{3}\z/ and $name eq ".FSTORE_INDEX/"
!ll&&!rl&&r
000
$magic eq "`\n" and $mode =~ /^[4-7]{3}\z/
!ll&&!rl&&r
000
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/"
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
unless $len == $size 0 0 0
90  
91 0 ▶ while ($data =~ s/^(data-\S+)\s+(\S+)\s+(\S+\/\S+|-)\s+(\S.+)\x0A//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data =~ s[^(data-\S+)\s+(\S+)\s+(\S+/\S+|-)\s+(\S.+)\x0A][]) 0 0 0
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
BranchTrueFalseTotal
unless length $contentise == 36 0 0 0
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
BranchTrueFalseTotal
if $mediasubtype ne "-" 0 0 0
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
BranchTrueFalseTotal
if ($hashes =~ s[^(v0m?) ([a-z]+)-([0-9]+)-([0-9]+) bytes 0-([0-9]+)/([0-9]+) ([0-9a-f]+)( |$)][]) 0 0 0
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
BranchTrueFalseTotal
if $end != $size - 1 0 0 0
107 0 ▶ die if (length($hash) * 4) != $bits;
Branch: 1 branch
BranchTrueFalseTotal
if length($hash) * 4 != $bits 0 0 0
108 0 ▶ die if $type eq 'v0' && length($mark);
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "v0" and length $mark 0 0 0
Condition0%0/3
$type eq "v0" and length $mark
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
109  
110 0 ▶ $given_size //= $size;
Condition0%0/3
$given_size //= $size
l!l&&r!l&&!r
000
MC/DC0%0/2
$given_size //= $size
$given_size $size
Truth table0%0/3
A //= B
A= $given_sizeB= $size
ABresult
1X1
011
000
111 0 ▶ die unless $given_size == $size;
Branch: 1 branch
BranchTrueFalseTotal
unless $given_size == $size 0 0 0
112 0 $digests{join('-', $name, $version, $bits)} = $hash;
113 }
114 0 ▶ $properties{size} = int($given_size) if defined $given_size;
Branch: 1 branch
BranchTrueFalseTotal
if defined $given_size 0 0 0
115 }
116  
117 0 ▶ croak 'Corrupted or unsupported index' if length($data);
Branch: 1 branch
BranchTrueFalseTotal
if length $data 0 0 0
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
BranchTrueFalseTotal
if $len == 0 0 0 0
129  
130 0 ▶ croak 'Bad archive header' unless $len == 60;
Branch: 1 branch
BranchTrueFalseTotal
unless $len == 60 0 0 0
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
BranchTrueFalseTotal
unless $magic eq "`\n" and $mode =~ /^[4-7]{3}\z/ 0 0 0
Condition0%0/3
$magic eq "`\n" and $mode =~ /^[4-7]{3}\z/
!ll&&!rl&&r
000
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/
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless defined $ent 0 0 0
142  
143 0 ▶ $ent->{info}{properties}{size} //= $size;
Condition0%0/3
$ent->{"info"}{"properties"}{"size"} //= $size
l!l&&r!l&&!r
000
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
ABresult
1X1
011
000
144 0 ▶ croak 'Entry size mismatch' unless $ent->{info}{properties}{size} == $size;
Branch: 1 branch
BranchTrueFalseTotal
unless $ent->{"info"}{"properties"}{"size"} == $size 0 0 0
145  
146 0 ($file) = $store->query(properties => {contentise => $ent->{contentise}, size => $size});
147  
148 0 ▶ if (defined $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file) { } 0 0 0
149 # we found the file
150 0 ▶ unless ($handle->seek($size, SEEK_CUR)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($handle->seek($size, 1)) 0 0 0
151 # seek didn't work, so we need to read...
152 0 my $left = $size;
153 0 ▶ while ($left > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($left > 0) 0 0 0
154 0 ▶ my $todo = $left < 65536 ? $left : 65536;
Branch: 1 branch
BranchTrueFalseTotal
$left < 65536 ? : 0 0 0
155 0 $len = $handle->read($data, $todo);
156  
157 0 ▶ if ($len < $todo) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len < $todo) 0 0 0
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
BranchTrueFalseTotal
open my $out, ">", $filename or die $! 0 0 0
177 0 $out->binmode;
178  
179 0 ▶ while ($left > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($left > 0) 0 0 0
180 0 ▶ my $todo = $left < 65536 ? $left : 65536;
Branch: 1 branch
BranchTrueFalseTotal
$left < 65536 ? : 0 0 0
181 0 $len = $handle->read($data, $todo);
182  
183 0 ▶ if ($len < $todo) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len < $todo) 0 0 0
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
BranchTrueFalseTotal
if ($size & 1) 0 0 0
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
BranchTrueFalseTotal
unless $len == 1 and $data eq "\n" 0 0 0
Condition0%0/3
$len == 1 and $data eq "\n"
!ll&&!rl&&r
000
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"
ABresult
0X0
100
111
200 }
201 }
202  
203 0 ▶ if (keys %index) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %index) 0 0 0
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"
l!l
00
MC/DC0%0/1
delete $opts{"format"} // "json"
delete $opts{"format"}
Truth table0%0/2
A
A= delete $opts{"format"}
Aresult
11
00
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
BranchTrueFalseTotal
if scalar keys %opts 0 0 0
220  
221 0 $handle->binmode;
222  
223 0 ▶ $list //= do {
Condition0%0/3
$list //= do { $query //= ["all"]; [$self->store->query(@{$query;})] }
l!l&&r!l&&!r
000
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;})] }
ABresult
1X1
011
000
224 0 ▶ $query //= ['all'];
Condition0%0/2
$query //= ["all"]
l!l
00
MC/DC0%0/1
$query //= ["all"]
$query
Truth table0%0/2
A
A= $query
Aresult
11
00
225 0 [$self->store->query(@{$query})];
226 };
227  
228 0 ▶ if ($format eq 'json') {
Branch: 3 branches
BranchTrueFalseTotal
if ($format eq 'json') { } 0 0 0
elsif ($format eq 'valuefile') { } 0 0 0
elsif ($format eq 'bundle') { } 0 0 0
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
BranchTrueFalseTotal
if (defined $mediasubtype) 0 0 0
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)
l!l&&r!l&&!r
000
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)
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if (defined $size) 0 0 0
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
BranchTrueFalseTotal
if defined $mediasubtype 0 0 0
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
BranchTrueFalseTotal
if ($idx < scalar @{$list;}) 0 0 0
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
BranchTrueFalseTotal
if defined $ext 0 0 0
288  
289 0 foreach my $key (@{$algos}) {
290 0 ▶ my $value = $info->{digests}{$key} // next;
Condition0%0/2
$info->{"digests"}{$key} // (next)
l!l
00
MC/DC0%0/1
$info->{"digests"}{$key} // (next)
$info->{"digests"}{$key}
Truth table0%0/2
A
A= $info->{"digests"}{$key}
Aresult
11
00
291  
292 0 ▶ if ($size > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size > 0) { } 0 0 0
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
BranchTrueFalseTotal
if (scalar @hashes > 1) { } 0 0 0
elsif (scalar @hashes) { } 0 0 0
elsif ($size > 0) { } 0 0 0
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"} // "-"
l!l
00
MC/DC0%0/1
$info->{"properties"}{"mediasubtype"} // "-"
$info->{"properties"}{"mediasubtype"}
Truth table0%0/2
A
A= $info->{"properties"}{"mediasubtype"}
Aresult
11
00
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
BranchTrueFalseTotal
if length $index & 1 0 0 0
316 }
317  
318 # Write data files:
319 0 ▶ for (my $idx = 0; $idx < scalar(@{$list}); $idx++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idx < scalar @{$list;}) 0 0 0
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
l!l
00
MC/DC0%0/1
($file->stat)[9] // 0
($file->stat)[9]
Truth table0%0/2
A
A= ($file->stat)[9]
Aresult
11
00
326 0 my $pad = $size & 1;
327  
328 0 ▶ $name .= '.'.$ext if defined $ext;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ext 0 0 0
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
BranchTrueFalseTotal
if ($size) 0 0 0
336 0 ▶ my $todo = $size < 65536 ? $size : 65536;
Branch: 1 branch
BranchTrueFalseTotal
$size < 65536 ? : 0 0 0
337 0 my $done = $fh->read(my $data, $todo);
338  
339 0 ▶ if ($done < $todo) {
Branch: 1 branch
BranchTrueFalseTotal
if ($done < $todo) 0 0 0
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
BranchTrueFalseTotal
if $pad 0 0 0
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($@); }
l!l&&r!l&&!r
000
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($@); }
ABresult
1X1
011
000
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"
l!l
00
MC/DC0%0/1
$opts{"update"} // "none"
$opts{"update"}
Truth table0%0/2
A
A= $opts{"update"}
Aresult
11
00
364 0 ▶ my $in_mode = $opts{in_mode} // 'link_in';
Condition0%0/2
$opts{"in_mode"} // "link_in"
l!l
00
MC/DC0%0/1
$opts{"in_mode"} // "link_in"
$opts{"in_mode"}
Truth table0%0/2
A
A= $opts{"in_mode"}
Aresult
11
00
365 0 ▶ my $in_func = $in_mode eq 'move_in' ? $adder->can('move_in') : $adder->can('link_in');
Branch: 1 branch
BranchTrueFalseTotal
$in_mode eq 'move_in' ? : 0 0 0
366  
367 0 ▶ $update = 'new' if $update eq 'all';
Branch: 1 branch
BranchTrueFalseTotal
if $update eq "all" 0 0 0
368 0 ▶ $on_error = undef if $on_error eq 'ignore';
Branch: 1 branch
BranchTrueFalseTotal
if $on_error eq "ignore" 0 0 0
369  
370 0 ▶ opendir(my $d, $directory) or croak $!;
Branch: 1 branch
BranchTrueFalseTotal
opendir my $d, $directory or croak($!) 0 0 0
371 0 ▶ while (defined(my $e = readdir($d))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $e = readdir $d)) 0 0 0
372 0 my $path;
373  
374 0 ▶ next if $e =~ /^\./;
Branch: 1 branch
BranchTrueFalseTotal
if $e =~ /^\./ 0 0 0
375 0 ▶ next if defined($basename_filter) && $e !~ $basename_filter;
Branch: 1 branch
BranchTrueFalseTotal
if defined $basename_filter and not $e =~ /$basename_filter/ 0 0 0
Condition0%0/3
defined $basename_filter and not $e =~ /$basename_filter/
!ll&&!rl&&r
000
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/
ABresult
0X0
100
111
376  
377 0 $path = File::Spec->catfile($directory, $e);
378 0 ▶ if (-f $path) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $path) { } 0 0 0
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
BranchTrueFalseTotal
if defined $on_pre_insert 0 0 0
384 0 $file = eval { $adder->insert };
385 0 ▶ $on_error->(undef, path => $path, basename => $e) if $on_error && $@;
Branch: 1 branch
BranchTrueFalseTotal
if $on_error and $@ 0 0 0
Condition0%0/3
$on_error and $@
!ll&&!rl&&r
000
MC/DC0%0/2
$on_error and $@
$on_error $@
Truth table0%0/3
A and B
A= $on_errorB= $@
ABresult
0X0
100
111
386 0 $adder->reset;
387  
388 0 ▶ if (defined $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file) 0 0 0
389 0 ▶ if ($update eq 'new') {
Branch: 1 branch
BranchTrueFalseTotal
if ($update eq "new") 0 0 0
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
BranchTrueFalseTotal
if defined $on_post_insert 0 0 0
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
BranchTrueFalseTotal
if defined $uuid 0 0 0
414  
415 0 ▶ $on_pre_insert->($adder, %opts) if defined $on_pre_insert;
Branch: 1 branch
BranchTrueFalseTotal
if defined $on_pre_insert 0 0 0
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__
↑ Summary FStore/File.pm »