FStore.pm

filter: Statementstmt 77.3% 317 / 410 Branchbran 51.2% 120 / 234 Conditioncond 37.9% 22 / 58 MC/DCmcdc 12.1% 4 / 33 Subroutinesub 84.4% 38 / 45 Podpod 100% 18 / 18 totaltotal 65.0% 519 / 798 CC 154 SCAR 40.4
CC
154
Cov
65%
query
178.0
new
64.1
__ANON__
56.0
CRAP 56.5
« FStore/File.pm ↑ Summary FStore/Adder.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;
9  
10 4 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 4 ▶use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 4 ▶use Data::Identifier;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 4 ▶use Data::Identifier::Generate;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 4 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 4 ▶use File::FStore::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 4 ▶use parent qw(Data::Identifier::Interface::Known Data::Identifier::Interface::Userdata Data::Identifier::Interface::Subobjects);
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 4 our $VERSION = v0.08;
26  
27 4 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
28 4 DEFAULT_LINK_STYLE => '1-level',
29 DEFAULT_STORE_STYLE => '1-level-contentise',
30 4 };
31  
32 4 my %_types = (
33 db => 'Data::TagDB',
34 extractor => 'Data::URIID',
35 fii => 'File::Information',
36 );
37  
38 40 our %_valid_digests = map {$_ => int((/^[^-]+-[^-]-([0-9]+)$/)[0]/4)} (
39 qw(md-5-128 sha-1-160),
40 4 (map {'sha-2-'.$_, 'sha-3-'.$_} 224, 256, 384, 512),
41 );
42  
43 4 our %_valid_link_styles = map {$_ => 1} qw(none 1-level 2-level);
44 4 our %_valid_store_styles = map {$_ => 1} qw(1-level-contentise 2-level-contentise);
45  
46 4 my %_flat_settings = map {$_ => $_} qw(link_style store_style);
47  
48 4 our %_ni_hashes = (
49 'sha-2-256' => 'sha-256',
50 'sha-2-384' => 'sha-384',
51 'sha-2-512' => 'sha-512',
52 'sha-3-224' => 'sha3-224',
53 'sha-3-256' => 'sha3-256',
54 'sha-3-384' => 'sha3-384',
55 'sha-3-512' => 'sha3-512',
56 );
57 4 my %_ni_hashes_reverse = map {$_ni_hashes{$_} => $_} keys %_ni_hashes;
58  
59  
60 2 ▶sub create {
Subroutine create: called CC=15 SCAR=28.8
Pod documented
61 2 my ($pkg, %opts) = @_;
62 2 my $path = delete($opts{path});
63 2 ▶ my $digests = delete($opts{digests}) // [keys %_valid_digests];
Condition50%1/2
delete $opts{"digests"} // [keys %File::FStore::_valid_digests]
l!l
02
MC/DC0%0/1
delete $opts{"digests"} // [keys %File::FStore::_valid_digests]
delete $opts{"digests"}
Truth table50%1/2
A
A= delete $opts{"digests"}
Aresult
11
00
64 2 my %extra;
65 my $dbh;
66  
67 2 foreach my $key (keys(%_types), qw(weak)) {
68 8 my $v = delete $opts{$key};
69 8 ▶ $extra{$key} = $v if defined $v;
Branch: 1 branch
BranchTrueFalseTotal
if defined $v 0 8 8
70 }
71  
72 2 ▶ croak 'Stray options passed' if scalar keys %opts;
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %opts 0 2 2
73  
74 2 ▶ $digests = [split(/\s*,\s*|\s+/, $digests)] unless ref $digests;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $digests 0 2 2
75 2 foreach my $digest (@{$digests}) {
76 20 ▶ croak 'Invalid digest: '.$digest unless defined $_valid_digests{$digest};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $File::FStore::_valid_digests{$digest} 0 20 20
77 }
78  
79 2 ▶ mkdir($path) or croak $!;
Branch: 1 branch
BranchTrueFalseTotal
mkdir $path or croak($!) 2 0 2
80 2 ▶ mkdir(File::Spec->catdir($path, qw(v2))) or croak $!;
Branch: 1 branch
BranchTrueFalseTotal
mkdir "File::Spec"->catdir($path, "v2") or croak($!) 2 0 2
81 2 ▶ mkdir(File::Spec->catdir($path, qw(v2 store))) or croak $!;
Branch: 1 branch
BranchTrueFalseTotal
mkdir "File::Spec"->catdir($path, ("v2", "store")) or croak($!) 2 0 2
82 2 ▶ mkdir(File::Spec->catdir($path, qw(v2 by))) or croak $!;
Branch: 1 branch
BranchTrueFalseTotal
mkdir "File::Spec"->catdir($path, ("v2", "by")) or croak($!) 2 0 2
83 2 foreach my $digest (@{$digests}) {
84 20 ▶ mkdir(File::Spec->catdir($path, qw(v2 by), $digest)) or croak $!;
Branch: 1 branch
BranchTrueFalseTotal
mkdir "File::Spec"->catdir($path, ("v2", "by"), $digest) or croak($!) 20 0 20
85 }
86  
87 2 $dbh = DBI->connect('dbi:SQLite:dbname='.File::Spec->catfile($path => v2 => store => 'db.sqlite'), undef, undef, { RaiseError => 1, PrintError => undef });
88 #@inject SQLITE
89 2 $dbh->do($_) for split /;/, << 'SQL';
90 CREATE TABLE file (
91 id INTEGER NOT NULL UNIQUE PRIMARY KEY AUTOINCREMENT,
92 filename VARCHAR(128) NOT NULL UNIQUE
93 );
94  
95 CREATE TABLE file_properties (
96 file INTEGER NOT NULL REFERENCES file (id),
97 key VARCHAR(64) NOT NULL,
98 value VARCHAR(128) NOT NULL,
99 UNIQUE (file, key)
100 );
101  
102 CREATE TABLE file_hash (
103 file INTEGER NOT NULL REFERENCES file (id),
104 algo VARCHAR(32) NOT NULL,
105 hash VARCHAR(255) NOT NULL UNIQUE,
106 UNIQUE (file, algo)
107 );
108 SQL
109 2 $dbh->disconnect;
110  
111 2 return $pkg->new(path => $path, %extra);
112 }
113  
114  
115 #@returns __PACKAGE__
116 4 ▶sub new {
Subroutine new: called CC=19 SCAR=41.6
Pod documented
117 4 my ($pkg, %opts) = @_;
118 4 ▶ my $path = delete $opts{path} // croak 'No path given';
Condition50%1/2
delete $opts{"path"} // croak("No path given")
l!l
40
MC/DC0%0/1
delete $opts{"path"} // croak("No path given")
delete $opts{"path"}
Truth table50%1/2
A
A= delete $opts{"path"}
Aresult
11
00
119 4 my $weak = delete $opts{weak};
120 4 my @used_digests;
121 my @used_digests_ni;
122 4 my $self = bless {
123 path => $path,
124 used_digests => \@used_digests,
125 used_digests_ni => \@used_digests_ni,
126 transaction_count => 0,
127 link_style => DEFAULT_LINK_STYLE,
128 store_style => DEFAULT_STORE_STYLE,
129 }, $pkg;
130  
131 4 foreach my $key (keys %_types) {
132 12 my $v = delete $opts{$key};
133 12 ▶ next unless defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 12 0 12
134 0 $self->so_attach($key => $v, weak => $weak);
135 }
136  
137 4 ▶ if (defined(my $link_style = delete $opts{link_style})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $link_style = delete $opts{"link_style"})) 0 4 4
138 0 ▶ $link_style = DEFAULT_LINK_STYLE if $link_style eq 'default';
Branch: 1 branch
BranchTrueFalseTotal
if $link_style eq "default" 0 0 0
139 0 ▶ croak 'Not a valid link style: '.$link_style unless defined $_valid_link_styles{$link_style};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $File::FStore::_valid_link_styles{$link_style} 0 0 0
140 0 $self->{link_style} = $link_style;
141 }
142  
143 4 ▶ if (defined(my $store_style = delete $opts{store_style})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $store_style = delete $opts{"store_style"})) 0 4 4
144 0 ▶ $store_style = DEFAULT_STORE_STYLE if $store_style eq 'default';
Branch: 1 branch
BranchTrueFalseTotal
if $store_style eq "default" 0 0 0
145 0 ▶ croak 'Not a valid store style: '.$store_style unless defined $_valid_store_styles{$store_style};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $File::FStore::_valid_store_styles{$store_style} 0 0 0
146 0 $self->{store_style} = $store_style;
147 }
148  
149 4 ▶ croak 'Stray options passed' if scalar keys %opts;
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %opts 0 4 4
150  
151 {
152 4 ▶ opendir(my $dir, $self->_directory(v2 => 'by')) or croak $!;
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dir, $self->_directory("v2", "by") or croak($!) 4 0 4
153 4 ▶ while (defined(my $ent = readdir($dir))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $ent = readdir $dir)) 48 4 52
154 48 ▶ next if $ent =~ /^\./;
Branch: 1 branch
BranchTrueFalseTotal
if $ent =~ /^\./ 8 40 48
155 40 ▶ croak 'Invalid store, unsupported/invalid digest used: '.$ent unless $_valid_digests{$ent};
Branch: 1 branch
BranchTrueFalseTotal
unless $File::FStore::_valid_digests{$ent} 0 40 40
156 40 push(@used_digests, $ent);
157 }
158 4 closedir($dir);
159 }
160  
161 4 ▶ if (opendir(my $dir, $self->_directory(v2 => 'ni'))) {
Branch: 1 branch
BranchTrueFalseTotal
if (opendir my $dir, $self->_directory("v2", "ni")) 0 4 4
162 0 ▶ while (defined(my $ent = readdir($dir))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $ent = readdir $dir)) 0 0 0
163 0 ▶ next if $ent =~ /^\./;
Branch: 1 branch
BranchTrueFalseTotal
if $ent =~ /^\./ 0 0 0
164 0 ▶ push(@used_digests_ni, $_ni_hashes_reverse{$ent} // next);
Condition0%0/2
$_ni_hashes_reverse{$ent} // (next)
l!l
00
MC/DC0%0/1
$_ni_hashes_reverse{$ent} // (next)
$_ni_hashes_reverse{$ent}
Truth table0%0/2
A
A= $_ni_hashes_reverse{$ent}
Aresult
11
00
165 }
166 0 closedir($dir);
167 }
168  
169 4 $self->{dbh} = DBI->connect('dbi:SQLite:dbname='.$self->_file(v2 => store => 'db.sqlite'), undef, undef, { RaiseError => 1, PrintError => undef });
170  
171 4 return $self;
172 }
173  
174  
175 4 ▶sub close {
Subroutine close: called CC=1 SCAR=0.0
Pod documented
176 4 my ($self) = @_;
177 4 $self->DESTROY;
178 }
179  
180  
181 9 ▶sub setting {
Subroutine setting: called CC=3 SCAR=12.0
Pod documented
182 9 my ($self, $key) = @_;
183  
184 9 ▶ croak 'No key given' unless defined $key;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key 0 9 9
185  
186 9 ▶ if (defined(my $flatkey = $_flat_settings{$key})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $flatkey = $_flat_settings{$key})) 9 0 9
187 9 return $self->{$flatkey};
188 }
189  
190 0 croak 'Unknown key: '.$key;
191 }
192  
193  
194 11 ▶sub in_transaction {
Subroutine in_transaction: called CC=12 SCAR=27.2
Pod documented
195 11 my ($self, $type, $code) = @_;
196 11 my $error;
197  
198 11 ▶ croak 'Bad transaction type' unless $type eq 'ro' || $type eq 'rw';
Branch: 1 branch
BranchTrueFalseTotal
unless $type eq "ro" or $type eq "rw" 0 11 11
Condition66%2/3
$type eq "ro" or $type eq "rw"
l!l&&r!l&&!r
1100
MC/DC0%0/2
$type eq "ro" or $type eq "rw"
$type eq "ro" $type eq "rw"
Truth table66%2/3
A or B
A= $type eq "ro"B= $type eq "rw"
ABresult
1X1
011
000
199  
200 11 ▶ return undef if defined $self->{transaction_error};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"transaction_error"} 0 11 11
201  
202 11 ▶ if ($self->{transaction_count}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'transaction_count'}) { } 5 6 11
203 5 ▶ if ($type ne 'ro' && $type ne $self->{transaction_type}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type ne "ro" and $type ne $self->{"transaction_type"}) 0 5 5
Condition33%1/3
$type ne "ro" and $type ne $self->{"transaction_type"}
!ll&&!rl&&r
050
MC/DC0%0/2
$type ne "ro" and $type ne $self->{"transaction_type"}
$type ne "ro" $type ne $self->{"transaction_type"}
Truth table33%1/3
A and B
A= $type ne "ro"B= $type ne $self->{"transaction_type"}
ABresult
0X0
100
111
204 0 croak 'Invalid inner transaction type '.$type.' within outer '.$self->{transaction_type}.' transaction';
205 }
206 } else {
207 6 $self->{dbh}->begin_work;
208 6 $self->{transaction_type} = $type;
209 6 $self->{transaction_error} = undef;
210 }
211  
212 11 $self->{transaction_count}++;
213  
214 11 eval {
215 11 $code->();
216 };
217 11 ▶ $error = $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 11 11
218  
219 11 ▶ $self->{transaction_error} //= $error;
Condition33%1/3
$self->{"transaction_error"} //= $error
l!l&&r!l&&!r
0011
MC/DC0%0/2
$self->{"transaction_error"} //= $error
$self->{"transaction_error"} $error
Truth table33%1/3
A //= B
A= $self->{"transaction_error"}B= $error
ABresult
1X1
011
000
220  
221 11 $self->{transaction_count}--;
222  
223 11 ▶ unless ($self->{transaction_count}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"transaction_count"}) 6 5 11
224 6 ▶ if (defined $self->{transaction_error}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'transaction_error'}) { } 0 6 6
225 0 $self->{dbh}->rollback;
226 } else {
227 6 $self->{dbh}->commit;
228 }
229 }
230  
231 11 ▶ croak $error if defined $error;
Branch: 1 branch
BranchTrueFalseTotal
if defined $error 0 11 11
232 }
233  
234  
235 17 ▶sub query {
Subroutine query: called CC=46 SCAR=51.8
Pod documented
236 17 my ($self, @query) = @_;
237 17 my %fields = (properties => {}, digests => {});
238 17 my $limit;
239 my $offset;
240 17 my $order;
241 17 my @q;
242 17 my @p;
243  
244 17 ▶ while (defined(my $cmd = shift(@query))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $cmd = shift @query)) 17 17 34
245 17 ▶ $cmd = 'digests' if $cmd eq 'hashes';
Branch: 1 branch
BranchTrueFalseTotal
if $cmd eq "hashes" 0 17 17
246  
247 17 ▶ if ($cmd eq 'properties' || $cmd eq 'digests') {
Branch: 9 branches
BranchTrueFalseTotal
if ($cmd eq 'properties' or $cmd eq 'digests') { } 12 5 17
elsif ($cmd eq 'all') { } 0 5 5
elsif ($cmd eq 'limit') { } 0 5 5
elsif ($cmd eq 'offset') { } 0 5 5
elsif ($cmd eq 'order') { } 0 5 5
elsif ($cmd eq 'min_size') { } 0 5 5
elsif ($cmd eq 'max_size') { } 0 5 5
elsif ($cmd eq 'dbname') { } 4 1 5
elsif ($cmd eq 'ise') { } 1 0 1
Condition100%3/3
$cmd eq "properties" or $cmd eq "digests"
l!l&&r!l&&!r
2105
MC/DC100%2/2
$cmd eq "properties" or $cmd eq "digests"
$cmd eq "properties" $cmd eq "digests"
Truth table100%3/3
A or B
A= $cmd eq "properties"B= $cmd eq "digests"
ABresult
1X1
011
000
248 12 ▶ my $n = shift(@query) // croak 'Incomplete query';
Condition50%1/2
shift @query // croak("Incomplete query")
l!l
120
MC/DC0%0/1
shift @query // croak("Incomplete query")
shift @query
Truth table50%1/2
A
A= shift @query
Aresult
11
00
249 12 my $t = $fields{$cmd};
250  
251 12 ▶ if (ref($n)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $n) { } 0 12 12
252 0 %{$t} = (%{$t}, %{$n});
253 } else {
254 12 ▶ my $v = shift(@query) // croak 'Incomplete query';
Condition50%1/2
shift @query // croak("Incomplete query")
l!l
120
MC/DC0%0/1
shift @query // croak("Incomplete query")
shift @query
Truth table50%1/2
A
A= shift @query
Aresult
11
00
255 12 $t->{$n} = $v;
256 }
257 } elsif ($cmd eq 'all') {
258 0 push(@q, 'SELECT id FROM file');
259 } elsif ($cmd eq 'limit') {
260 0 ▶ $limit = shift(@query) // croak 'Incomplete query';
Condition0%0/2
shift @query // croak("Incomplete query")
l!l
00
MC/DC0%0/1
shift @query // croak("Incomplete query")
shift @query
Truth table0%0/2
A
A= shift @query
Aresult
11
00
261 } elsif ($cmd eq 'offset') {
262 0 ▶ $offset = shift(@query) // croak 'Incomplete query';
Condition0%0/2
shift @query // croak("Incomplete query")
l!l
00
MC/DC0%0/1
shift @query // croak("Incomplete query")
shift @query
Truth table0%0/2
A
A= shift @query
Aresult
11
00
263 } elsif ($cmd eq 'order') {
264 0 ▶ $order = shift(@query) // croak 'Incomplete query';
Condition0%0/2
shift @query // croak("Incomplete query")
l!l
00
MC/DC0%0/1
shift @query // croak("Incomplete query")
shift @query
Truth table0%0/2
A
A= shift @query
Aresult
11
00
265 0 $order = uc($order);
266 0 ▶ croak 'Bad order' if $order ne 'ASC' && $order ne 'DESC';
Branch: 1 branch
BranchTrueFalseTotal
if $order ne "ASC" and $order ne "DESC" 0 0 0
Condition0%0/3
$order ne "ASC" and $order ne "DESC"
!ll&&!rl&&r
000
MC/DC0%0/2
$order ne "ASC" and $order ne "DESC"
$order ne "ASC" $order ne "DESC"
Truth table0%0/3
A and B
A= $order ne "ASC"B= $order ne "DESC"
ABresult
0X0
100
111
267 } elsif ($cmd eq 'min_size') {
268 0 ▶ my $v = shift(@query) // croak 'Incomplete query';
Condition0%0/2
shift @query // croak("Incomplete query")
l!l
00
MC/DC0%0/1
shift @query // croak("Incomplete query")
shift @query
Truth table0%0/2
A
A= shift @query
Aresult
11
00
269 0 push(@q, 'SELECT file AS id FROM file_properties WHERE key = \'size\' AND CAST(value AS BIG INTEGER) >= ?');
270 0 push(@p, $v);
271 } elsif ($cmd eq 'max_size') {
272 0 ▶ my $v = shift(@query) // croak 'Incomplete query';
Condition0%0/2
shift @query // croak("Incomplete query")
l!l
00
MC/DC0%0/1
shift @query // croak("Incomplete query")
shift @query
Truth table0%0/2
A
A= shift @query
Aresult
11
00
273 0 push(@q, 'SELECT file AS id FROM file_properties WHERE key = \'size\' AND CAST(value AS BIG INTEGER) <= ?');
274 0 push(@p, $v);
275 } elsif ($cmd eq 'dbname') {
276 4 ▶ my $v = shift(@query) // croak 'Incomplete query';
Condition50%1/2
shift @query // croak("Incomplete query")
l!l
40
MC/DC0%0/1
shift @query // croak("Incomplete query")
shift @query
Truth table50%1/2
A
A= shift @query
Aresult
11
00
277  
278 4 ▶ $v = [$v] unless ref $v;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $v 4 0 4
279  
280 4 ▶ croak 'Empty list for dbname' unless scalar(@{$v});
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$v;} 0 4 4
281  
282 4 push(@q, 'SELECT id FROM file WHERE '.$self->_placeholders(filename => $v));
283 4 push(@p, @{$v});
284 } elsif ($cmd eq 'ise') {
285 1 ▶ my $v = shift(@query) // croak 'Incomplete query';
Condition50%1/2
shift @query // croak("Incomplete query")
l!l
10
MC/DC0%0/1
shift @query // croak("Incomplete query")
shift @query
Truth table50%1/2
A
A= shift @query
Aresult
11
00
286  
287 1 ▶ if (ref $v) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v) { } 0 1 1
288 0 ▶ if (eval {$v->isa('Data::Identifier::Cloudlet')}) {
Branch: 2 branches
BranchTrueFalseTotal
if (eval { do { $v->isa('Data::Identifier::Cloudlet') } }) { } 0 0 0
elsif (eval { do { $v->can('ise') } }) { } 0 0 0
289 0 $v = [$v->entries];
290 0 } elsif (eval {$v->can('ise')}) {
291 0 $v = [$v];
292 }
293 } else {
294 1 $v = [$v];
295 }
296  
297 1 ▶ croak 'Empty list for ise' unless scalar(@{$v});
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$v;} 0 1 1
298  
299 1 foreach my $s (@{$v}) {
300 1 ▶ $s = $s->ise if ref $s;
Branch: 1 branch
BranchTrueFalseTotal
if ref $s 0 1 1
301 }
302  
303 1 push(@q, 'SELECT file AS id FROM file_properties WHERE key IN (\'contentise\', \'inodeise\') AND '.$self->_placeholders(value => $v));
304 1 push(@p, @{$v});
305 } else {
306 0 croak 'Invalid query command: '.$cmd;
307 }
308 }
309  
310 17 foreach my $digest (keys %{$fields{digests}}) {
311 10 my $v = $fields{digests}{$digest};
312 10 ▶ $v = [$v] unless ref($v) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $v eq "ARRAY" 10 0 10
313 10 unshift(@q, 'SELECT file AS id FROM file_hash WHERE algo = ? AND '.$self->_placeholders(hash => $v));
314 10 unshift(@p, $digest, @{$v});
315 }
316  
317 17 foreach my $property (keys %{$fields{properties}}) {
318 2 my $v = $fields{properties}{$property};
319 2 ▶ $v = [$v] unless ref($v) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $v eq "ARRAY" 2 0 2
320 2 push(@q, 'SELECT file AS id FROM file_properties WHERE key = ? AND '.$self->_placeholders(value => $v));
321 2 push(@p, $property, @{$v});
322 }
323  
324 17 ▶ unless (scalar @q) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @q) 0 17 17
325 0 croak 'No filter given';
326 }
327  
328 {
329 17 my $q = join(' INTERSECT ', @q);
330 17 my $sth;
331 my @result;
332  
333 17 ▶ if (defined $order) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $order) 0 17 17
334 0 $q .= ' ORDER BY id '.$order;
335 }
336  
337 17 ▶ $limit = 2 unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 14 3 17
338  
339 17 ▶ if (defined $limit) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $limit) 14 3 17
340 14 $q .= ' LIMIT ?';
341 14 push(@p, $limit);
342 }
343  
344 17 ▶ if (defined $offset) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $offset) 0 17 17
345 0 $q .= ' OFFSET ?';
346 0 push(@p, $offset);
347 }
348 17 $sth = $self->{dbh}->prepare($q);
349 17 $sth->execute(@p);
350  
351 17 ▶ while (my $row = $sth->fetchrow_arrayref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_arrayref) 14 17 31
352 14 push(@result, File::FStore::File->_new(store => $self, dbid => $row->[0]));
353 }
354  
355 17 $sth->finish;
356  
357 17 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 3 14 17
358 3 return @result;
359 } else {
360 14 ▶ croak 'Multiple results for query but called in scalar context' if scalar(@result) > 1;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @result > 1 0 14 14
361 14 ▶ croak 'No results for query but called in scalar context' if scalar(@result) < 1;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @result < 1 0 14 14
362 14 return $result[0];
363 }
364 }
365  
366 0 die 'BUG';
367 }
368  
369  
370 1 ▶sub scrub {
Subroutine scrub: called CC=3 SCAR=16.3
Pod documented
371 1 my ($self, %opts) = @_;
372  
373 1 ▶ croak 'Stray options passed' if scalar keys %opts;
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %opts 0 1 1
374  
375 1 ▶ $self->in_transaction(ro => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
376 1 ▶ opendir(my $algodir, $self->_directory('v2' => 'by')) or croak $!;
Branch: 1 branch
BranchTrueFalseTotal
opendir my $algodir, $self->_directory("v2", "by") or croak($!) 1 0 1
377 1 ▶ while (defined(my $algoent = readdir($algodir))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $algoent = readdir $algodir)) 12 1 13
378 12 ▶ next if $algoent =~ /^\./;
Branch: 1 branch
BranchTrueFalseTotal
if $algoent =~ /^\./ 2 10 12
379 10 $self->_scrub_dir($algoent => $self->_directory(v2 => by => $algoent));
380 }
381 1 closedir($algodir);
382 1 });
383  
384 {
385 1 ▶ if (opendir(my $algodir, $self->_directory('v2' => 'ni'))) {
Branch: 1 branch
BranchTrueFalseTotal
if (opendir my $algodir, $self->_directory("v2", "ni")) 0 1 1
386 0 ▶ $self->in_transaction(ro => sub {
Subroutine __ANON__: not called CC=7 SCAR=40.3
387 0 ▶ while (defined(my $algoent = readdir($algodir))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $algoent = readdir $algodir)) 0 0 0
388 0 my $dirname;
389  
390 0 ▶ next if $algoent =~ /^\./;
Branch: 1 branch
BranchTrueFalseTotal
if $algoent =~ /^\./ 0 0 0
391  
392 0 $dirname = $self->_directory(v2 => ni => $algoent);
393  
394 0 ▶ opendir(my $dir, $dirname) or next;
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dir, $dirname or next 0 0 0
395 0 ▶ while (defined(my $fn = readdir($dir))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $fn = readdir $dir)) 0 0 0
396 0 my $fullname = File::Spec->catfile($dirname, $fn);
397 0 ▶ next if $fn =~ /^\./;
Branch: 1 branch
BranchTrueFalseTotal
if $fn =~ /^\./ 0 0 0
398 0 ▶ unlink($fullname) unless -e $fullname;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $fullname 0 0 0
399 }
400 0 closedir($dir);
401 }
402 0 });
403 0 closedir($algodir);
404 }
405 }
406 }
407  
408  
409 2 ▶sub scan {
Subroutine scan: called CC=4 SCAR=13.9
Pod documented
410 2 my ($self, %opts) = @_;
411 2 my %extra;
412  
413 2 foreach my $key (qw(update no_digests on_pre_set on_post_set)) {
414 8 $extra{$key} = delete $opts{$key};
415 }
416  
417 2 ▶ $extra{update} //= 'all';
Condition100%2/2
$extra{"update"} //= "all"
l!l
11
MC/DC100%1/1
$extra{"update"} //= "all"
$extra{"update"}
Truth table100%2/2
A
A= $extra{"update"}
Aresult
11
00
418  
419 2 ▶ croak 'Stray options passed' if scalar keys %opts;
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %opts 0 2 2
420  
421 2 ▶ $self->in_transaction(rw => sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
422 2 my $insert = $self->{dbh}->prepare('INSERT OR IGNORE INTO file (filename) VALUES (?)');
423  
424 2 ▶ opendir(my $dir, $self->_directory('v2', 'store')) or croak $!;
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dir, $self->_directory("v2", "store") or croak($!) 2 0 2
425 2 ▶ while (defined(my $ent = readdir($dir))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $ent = readdir $dir)) 8 2 10
426 8 my $dirname;
427  
428 8 ▶ next if $ent =~ /^\./;
Branch: 1 branch
BranchTrueFalseTotal
if $ent =~ /^\./ 4 4 8
429  
430 4 $dirname = $self->_directory('v2', 'store', $ent);
431  
432 4 ▶ if (-d $dirname) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $dirname) 2 2 4
433 2 $self->_scan_subdir($dirname, dbprefix => $ent, insert => $insert, %extra);
434 }
435 }
436 2 closedir($dir);
437 2 });
438 }
439  
440  
441 1 ▶sub fix {
Subroutine fix: called CC=8 SCAR=23.4
Pod documented
442 1 my ($self, @fixes) = @_;
443 1 my %fixes = map {$_ => 1} @fixes;
444  
445 1 foreach my $fix (qw(upgrade scrub remove-inode remove-mediasubtype remove-inodeise scan)) {
446 6 ▶ next unless delete $fixes{$fix};
Branch: 1 branch
BranchTrueFalseTotal
unless delete $fixes{$fix} 3 3 6
447  
448 3 ▶ if ($fix eq 'scrub') {
Branch: 4 branches
BranchTrueFalseTotal
if ($fix eq 'scrub') { } 1 2 3
elsif ($fix eq 'scan') { } 1 1 2
elsif ($fix eq 'upgrade') { } 1 0 1
elsif ($fix =~ /^remove-(inode|mediasubtype|inodeise)$/) { } 0 0 0
449 1 $self->scrub;
450 } elsif ($fix eq 'scan') {
451 1 $self->scan;
452 } elsif ($fix eq 'upgrade') {
453 1 $self->migration->upgrade;
454 } elsif ($fix =~ /^remove-(inode|mediasubtype|inodeise)$/) {
455 0 my $what = $1;
456 0 my $sth = $self->{dbh}->prepare('DELETE FROM file_properties WHERE key = ?');
457 0 $sth->execute($what);;
458 } else {
459 0 croak 'BUG';
460 }
461 }
462  
463 1 ▶ if (scalar keys %fixes) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %fixes) 0 1 1
464 0 croak 'Invalid/unknown fixes passed: '.join(', ', keys %fixes);
465 }
466 }
467  
468  
469 #@returns File::FStore::Adder
470 1 ▶sub new_adder {
Subroutine new_adder: called CC=1 SCAR=0.0
Pod documented
471 1 my ($self) = @_;
472 1 require File::FStore::Adder;
473 1 return File::FStore::Adder->_new(store => $self);
474 }
475  
476  
477 #@returns File::FStore::Migration
478 1 ▶sub migration {
Subroutine migration: called CC=1 SCAR=0.0
Pod documented
479 1 my ($self) = @_;
480 1 require File::FStore::Migration;
481 1 return File::FStore::Migration->_new(store => $self);
482 }
483  
484  
485 #@deprecated
486 0 ▶sub export {
Subroutine export: not called CC=1 SCAR=6.9
Pod documented
487 0 my ($self, @args) = @_;
488 0 return $self->migration->export_data(@args);
489 }
490  
491  
492 #@deprecated
493 0 ▶sub import_data {
Subroutine import_data: not called CC=1 SCAR=6.9
Pod documented
494 0 my ($self, @args) = @_;
495 0 return $self->migration->import_data(@args);
496 }
497  
498  
499 0 ▶sub add_digest {
Subroutine add_digest: not called CC=7 SCAR=40.3
Pod documented
500 0 my ($self, $digests, @opts) = @_;
501 0 my $path = $self->{path};
502 0 my %used_digests = map {$_ => undef} @{$self->{used_digests}};
503  
504 0 ▶ croak 'Stray options passed' if scalar @opts;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @opts 0 0 0
505  
506 0 ▶ $digests = [split(/\s*,\s*|\s+/, $digests)] unless ref $digests;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $digests 0 0 0
507  
508 0 foreach my $d (@{$digests}) {
509 0 ▶ next if exists $used_digests{$d};
Branch: 1 branch
BranchTrueFalseTotal
if exists $used_digests{$d} 0 0 0
510  
511 0 ▶ croak 'Invalid digest: '.$d unless defined $_valid_digests{$d};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $File::FStore::_valid_digests{$d} 0 0 0
512 0 ▶ mkdir(File::Spec->catdir($path, qw(v2 by), $d)) or croak $!;
Branch: 1 branch
BranchTrueFalseTotal
mkdir "File::Spec"->catdir($path, ("v2", "by"), $d) or croak($!) 0 0 0
513  
514 0 $used_digests{$d} = undef;
515 }
516  
517 0 @{$self->{used_digests}} = keys %used_digests;
518 }
519  
520  
521 #@deprecated
522 0 ▶sub attach {
Subroutine attach: not called CC=1 SCAR=6.9
Pod documented
523 0 my ($self, %opts) = @_;
524 0 $self->so_attach(%opts);
525 }
526  
527  
528 #@deprecated
529 0 ▶sub db {
Subroutine db: not called CC=1 SCAR=6.9
Pod documented
530 0 my ($self, %opts) = @_;
531 0 return $self->so_get('db', %opts);
532 }
533  
534  
535 #@deprecated
536 0 ▶sub extractor {
Subroutine extractor: not called CC=1 SCAR=6.9
Pod documented
537 0 my ($self, %opts) = @_;
538 0 return $self->so_get('extractor', %opts);
539 }
540  
541  
542 #@returns File::Information
543 4 ▶sub fii {
Subroutine fii: called CC=2 SCAR=6.9
Pod documented
544 4 my ($self) = @_;
545 4 my $fii = $self->so_get('fii', default => undef, no_defaults => 1);
546 4 ▶ return $fii if defined $fii;
Branch: 1 branch
BranchTrueFalseTotal
if defined $fii 2 2 4
547  
548 2 require File::Information;
549 2 File::Information->VERSION(v0.06);
550 2 $fii = File::Information->new(
551 db => $self->so_get('db', default => undef, no_defaults => 1),
552 extractor => $self->so_get('extractor', default => undef, no_defaults => 1),
553 );
554  
555 2 $self->so_attach(fii => $fii);
556 2 return $fii;
557 }
558  
559 # --- Overrides for Data::Identifier::Interface::Known ---
560 5 ▶sub _known_provider {
Subroutine _known_provider: called CC=1 SCAR=0.0
561 5 my ($pkg, @args) = @_;
562 5 return $pkg->File::FStore::File::_known_provider(@args);
563 }
564  
565  
566  
567 # ---- Private helpers ----
568  
569 17 ▶sub _placeholders {
Subroutine _placeholders: called CC=1 SCAR=0.0
570 17 my ($self, $field, $list) = @_;
571 17 my $placeholders = '?,' x scalar(@{$list});
572  
573 17 $placeholders =~ s/,$//;
574  
575 17 return sprintf('%s IN (%s)', $field, $placeholders);
576 }
577  
578 8 ▶sub DESTROY {
Subroutine DESTROY: called CC=2 SCAR=6.9
579 8 my ($self) = @_;
580 8 ▶ $self->{dbh}->disconnect if defined $self->{dbh};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"dbh"} 4 4 8
581 8 %{$self} = ();
582 }
583  
584 38 ▶sub _file {
Subroutine _file: called CC=1 SCAR=0.0
585 38 my ($self, @comp) = @_;
586 38 return File::Spec->catfile($self->{path}, @comp);
587 }
588  
589 28 ▶sub _directory {
Subroutine _directory: called CC=1 SCAR=0.0
590 28 my ($self, @comp) = @_;
591 28 return File::Spec->catdir($self->{path}, @comp);
592 }
593  
594 4 ▶sub _used_digests {
Subroutine _used_digests: called CC=1 SCAR=0.0
595 4 my ($self) = @_;
596 4 return $self->{used_digests};
597 }
598  
599 3 ▶sub _used_digests_ni {
Subroutine _used_digests_ni: called CC=1 SCAR=0.0
600 3 my ($self) = @_;
601 3 return $self->{used_digests_ni};
602 }
603  
604 3 ▶sub _init_link_style {
Subroutine _init_link_style: called CC=5 SCAR=20.2
605 3 my ($self) = @_;
606  
607 3 ▶ unless ($self->{_init_link_style}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_init_link_style"}) 2 1 3
608 2 my $link_style = $self->setting('link_style');
609  
610 2 $self->{_init_link_style} = 1;
611  
612 2 ▶ if ($link_style eq '2-level') {
Branch: 1 branch
BranchTrueFalseTotal
if ($link_style eq "2-level") 0 2 2
613 0 foreach my $digest (@{$self->_used_digests}) {
614 0 ▶ for (my $i = 0; $i < 0x100; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 256) 0 0 0
615 0 mkdir($self->_directory(v2 => by => $digest => sprintf('%02x', $i)));
616 }
617 }
618 }
619 }
620 }
621  
622 1 ▶sub _init_store_style {
Subroutine _init_store_style: called CC=6 SCAR=22.3
623 1 my ($self) = @_;
624  
625 1 ▶ unless ($self->{_init_store_style}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_init_store_style"}) 1 0 1
626 1 my $store_style = $self->setting('store_style');
627  
628 1 $self->{_init_store_style} = 1;
629  
630 1 ▶ if ($store_style eq '2-level-contentise' || $store_style eq '1-level-contentise') {
Branch: 1 branch
BranchTrueFalseTotal
if ($store_style eq "2-level-contentise" or $store_style eq "1-level-contentise") 1 0 1
Condition33%1/3
$store_style eq "2-level-contentise" or $store_style eq "1-level-contentise"
l!l&&r!l&&!r
010
MC/DC0%0/2
$store_style eq "2-level-contentise" or $store_style eq "1-level-contentise"
$store_style eq "2-level-contentise" $store_style eq "1-level-contentise"
Truth table33%1/3
A or B
A= $store_style eq "2-level-contentise"B= $store_style eq "1-level-contentise"
ABresult
1X1
011
000
631 1 mkdir($self->_directory(v2 => store => 'by-contentise'));
632 }
633  
634 1 ▶ if ($store_style eq '2-level-contentise') {
Branch: 1 branch
BranchTrueFalseTotal
if ($store_style eq "2-level-contentise") 0 1 1
635 0 ▶ for (my $i = 0; $i < 0x100; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 256) 0 0 0
636 0 mkdir($self->_directory(v2 => store => 'by-contentise' => sprintf('%02x', $i)));
637 }
638 }
639 }
640 }
641  
642 2 ▶sub _scan_subdir {
Subroutine _scan_subdir: called CC=6 SCAR=18.4
643 2 my ($self, $dirname, %opts) = @_;
644 2 my $dbprefix = $opts{dbprefix};
645  
646 2 ▶ opendir(my $dir, $dirname) // croak $!;
Condition50%1/2
opendir(my $dir, $dirname) // croak($!)
l!l
20
MC/DC0%0/1
opendir(my $dir, $dirname) // croak($!)
opendir(my $dir, $dirname)
Truth table50%1/2
A
A= opendir(my $dir, $dirname)
Aresult
11
00
647 2 ▶ while (defined(my $ent = readdir($dir))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $ent = readdir $dir)) 6 2 8
648 6 my $filename;
649 my $fh;
650  
651 6 ▶ next if $ent =~ /^\./;
Branch: 1 branch
BranchTrueFalseTotal
if $ent =~ /^\./ 4 2 6
652  
653 2 $filename = File::Spec->catfile($dirname, $ent);
654 2 open($fh, '<', $filename);
655 2 ▶ if ($fh && -f $fh) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fh and -f $fh) { } 2 0 2
Condition33%1/3
$fh and -f $fh
!ll&&!rl&&r
002
MC/DC0%0/2
$fh and -f $fh
$fh -f $fh
Truth table33%1/3
A and B
A= $fhB= -f $fh
ABresult
0X0
100
111
656 2 my $dbname = File::Spec->catfile($dbprefix, $ent);
657 2 $self->_scan_file($fh, $dbname, %opts);
658 #warn sprintf('ent=<%s>, filename=<%s>, dbprefix=<%s>, dbname=<%s>', $ent, $filename, $dbprefix, $dbname);
659 } else {
660 0 $self->_scan_subdir(File::Spec->catdir($dirname, $ent), %opts, dbprefix => File::Spec->catdir($dbprefix, $ent));
661 }
662 }
663 2 closedir($dir);
664 }
665  
666 2 ▶sub _scan_file {
Subroutine _scan_file: called CC=6 SCAR=18.3
667 2 my ($self, $fh, $dbname, %opts) = @_;
668 2 my File::FStore::File $file;
669 2 my $update = $opts{update};
670 2 my $new;
671  
672 2 $opts{insert}->execute($dbname);
673 2 $new = $opts{insert}->rows;
674  
675 2 $file = $self->query(dbname => $dbname);
676 2 $file->_open(fh => $fh);
677  
678 2 ▶ if ($update eq 'all' || ($new && $update eq 'new')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($update eq 'all' or $new and $update eq 'new') { } 1 1 2
Condition50%3/6
$update eq "all" or $new and $update eq "new"
l!l&&r!l&&!r
101
$new and $update eq "new"
!ll&&!rl&&r
010
MC/DC33%1/3
$update eq "all" or $new and $update eq "new"
$update eq "all" $new $update eq "new"
Truth table50%2/4
A or B and C
A= $update eq "all"B= $newC= $update eq "new"
ABCresult
1XX1
0111
00X0
0100
679 1 $file->update(%opts{qw(no_digests on_pre_set on_post_set)});
680 } else {
681 1 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
682 $atime,$mtime,$ctime,$blksize,$blocks) = $file->stat;
683  
684 1 ▶ $opts{on_pre_set}->($file) if defined $opts{on_pre_set};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"on_pre_set"} 0 1 1
685 1 $file->set({
686 properties => {
687 size => $size,
688 inode => $ino,
689 },
690 });
691 1 ▶ $opts{on_post_set}->($file) if defined $opts{on_post_set};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"on_post_set"} 0 1 1
692 }
693 }
694  
695 10 ▶sub _scrub_dir {
Subroutine _scrub_dir: called CC=12 SCAR=27.1
696 10 my ($self, $algoent, $dirname) = @_;
697  
698 10 ▶ opendir(my $dir, $dirname) or croak $!;
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dir, $dirname or croak($!) 10 0 10
699 10 ▶ while (defined(my $ent = readdir($dir))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $ent = readdir $dir)) 30 10 40
700 30 my $fullname;
701 my $hash;
702 30 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
703 $atime,$mtime,$ctime,$blksize,$blocks);
704 30 my $bad = 1;
705  
706 30 ▶ next if $ent =~ /^\./;
Branch: 1 branch
BranchTrueFalseTotal
if $ent =~ /^\./ 20 10 30
707  
708 10 $fullname = File::Spec->catdir($dirname, $ent);
709 10 ▶ if (-d $fullname) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $fullname) 0 10 10
710 0 $self->_scrub_dir($algoent => $fullname);
711 0 next;
712 }
713  
714 10 $fullname = File::Spec->catfile($dirname, $ent);
715 10 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
716 $atime,$mtime,$ctime,$blksize,$blocks) = stat($fullname);
717  
718 10 ▶ if (defined $size) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $size) 10 0 10
719 10 my ($hash) = $ent =~ /^([0-9a-fA-F]+)(?:\..+)?$/;
720 10 ▶ if (defined $hash) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hash) 10 0 10
721 10 my $file;
722  
723 10 $hash = lc($hash);
724 10 $file = eval {$self->query(digests => $algoent => $hash)};
725  
726 10 ▶ if (defined $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file) 10 0 10
727 10 ▶ my $want_size = eval { $file->get(properties => 'size') } // $size;
Condition33%1/3
eval { do { $file->get("properties", "size") } } // $size
l!l&&r!l&&!r
1000
MC/DC0%0/2
eval { do { $file->get("properties", "size") } } // $size
eval { do { $file->get("properties", "size") } } $size
Truth table33%1/3
A // B
A= eval { do { $file->get("properties", "size") } }B= $size
ABresult
1X1
011
000
728 10 ▶ if ($size == $want_size) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size == $want_size) 10 0 10
729 10 $bad = 0;
730 }
731 }
732 }
733 }
734  
735 #warn $algoent.' -> '.$ent.' -> '.$bad;
736 10 ▶ if ($bad) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bad) 0 10 10
737 0 ▶ unlink($fullname) or croak $!;
Branch: 1 branch
BranchTrueFalseTotal
unlink $fullname or croak($!) 0 0 0
738 }
739 }
740 10 closedir($dir);
741 }
742  
743 4 1;
744  
745 __END__
« FStore/File.pm ↑ Summary FStore/Adder.pm »