SimpleBackuper/_BlockDelete.pm

filter: Statementstmt 15.8% 10 / 63 Branchbran 0.0% 0 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 3 / 4 Podpod n/a totaltotal 14.9% 13 / 87 CC 15 SCAR 53.0
CC
15
Cov
12%
_BlockDelete
240.0
BEGIN
1.0
BEGIN
1.0
CRAP 200.2
« SimpleBackuper/_BlocksInfo.pm ↑ Summary SimpleBackuper/DB.pm »
1 package App::SimpleBackuper;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use App::SimpleBackuper::_format;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 0 ▶sub _BlockDelete {
Subroutine _BlockDelete: not called CC=15 SCAR=54.8
8 0 my($options, $state, $block, $block_files) = @_;
9
10 0 ▶ if($options->{verbose}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{"verbose"}) 0 0 0
11 0 my $block_info = $state->{blocks_info}->{ $block->{id} };
12 0 print "\tDeleting block # $block->{id} (score $block_info->[0] = backup_id_score $block_info->[3] * prio $block_info->[4], size => ".fmt_weight($block_info->[1])."):\n";
13 }
14
15 0 my($backups, $files, $blocks, $parts) = @{ $state->{db} }{qw(backups files blocks parts)};
16
17 0 my %parts2delete;
18
19 # Delete all from block
20 0 $state->{profile}->{db_delete_all_from_block} -= time;
21
22 0 ▶ while(@$block_files) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$block_files) 0 0 0
23 0 my $parent_id = shift @$block_files;
24 0 my $id = shift @$block_files;
25 0 my $full_path = shift @$block_files;
26 0 my $file = $files->find_all({parent_id => $parent_id, id => $id})->[0];
27
28 0 my $found;
29 0 foreach my $version ( @{ $file->{versions} } ) {
30 0 ▶ next if $version->{block_id} != $block->{id};
Branch: 1 branch
BranchTrueFalseTotal
if $version->{"block_id"} != $block->{"id"} 0 0 0
31
32 0 $found = 1;
33
34 0 ▶ if($options->{verbose}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{"verbose"}) 0 0 0
35 print "\t\tDeleting $full_path from ".
36 (
37 $version->{backup_id_min} == $version->{backup_id_max}
38 ? "backup ".$backups->find_row({ id => $version->{backup_id_max} })->{name}
39 : "backups ".$backups->find_row({ id => $version->{backup_id_min} })->{name}
40 ."..".$backups->find_row({ id => $version->{backup_id_max} })->{name}
41 0 ▶ )."\n";
Branch: 1 branch
BranchTrueFalseTotal
$version->{'backup_id_min'} == $version->{'backup_id_max'} ? : 0 0 0
42 }
43
44 0 foreach my $part ( @{ $version->{parts} } ) {
45 0 $parts2delete{ $part->{hash} } = $part;
46 0 $state->{deletions_stats}->{bytes} += $part->{size};
47 }
48 0 $state->{deletions_stats}->{versions}++;
49
50
51 0 foreach my $backup_id ( $version->{backup_id_min} .. $version->{backup_id_max} ) {
52 0 my $backup = $backups->find_row({ id => $backup_id });
53 0 ▶ next if ! $backup;
Branch: 1 branch
BranchTrueFalseTotal
unless $backup 0 0 0
54 0 $backup->{files_cnt}--;
55 0 ▶ if( $backup->{files_cnt} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($backup->{'files_cnt'}) { } 0 0 0
56 0 $backups->upsert({ id => $backup_id }, $backup);
57 } else {
58 0 $backups->delete({ id => $backup_id });
59 }
60 }
61 }
62
63 0 ▶ if($found) {
Branch: 1 branch
BranchTrueFalseTotal
if ($found) 0 0 0
64 0 $state->{deletions_stats}->{files}++;
65
66 # Delete version
67 0 @{ $file->{versions} } = grep {$_->{block_id} != $block->{id}} @{ $file->{versions} };
68
69 0 ▶ if( @{ $file->{versions} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$file->{'versions'};}) { } 0 0 0
70 0 $files->upsert({parent_id => $parent_id, id => $id}, $file);
71 } else {
72 0 $files->delete({parent_id => $parent_id, id => $id});
73 }
74 }
75 }
76 0 $state->{profile}->{db_delete_all_from_block} += time;
77
78 0 $blocks->delete({ id => $block->{id} });
79
80 0 my $deleted = 0;
81 0 foreach my $part (values %parts2delete) {
82 0 $state->{storage}->remove(fmt_hex2base64($part->{hash}));
83 0 $parts->delete({hash => $part->{hash}});
84 0 $state->{total_weight} -= $part->{size};
85 0 $deleted++;
86 0 ▶ if($options->{verbose}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{"verbose"}) 0 0 0
87 0 print "\t\t\tpart ".fmt_hex2base64($part->{hash})." deleted (".fmt_weight($part->{size})." of space freed)\n";
88 }
89 }
90
91 0 return $deleted;
92 }
93  
94 1 1;
« SimpleBackuper/_BlocksInfo.pm ↑ Summary SimpleBackuper/DB.pm »