Brackup/GPGProcess.pm

filter: Statementstmt 38.1% 16 / 42 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 45.4% 5 / 11 Podpod 0.0% 0 / 6 totaltotal 26.9% 21 / 78 CC 10 SCAR 34.4
CC
10
Cov
27%
new
72.0
chunkref
12.0
pid
2.0
CRAP 31.2
« Brackup/GPGProcManager.pm ↑ Summary Brackup/BackupStats.pm »
1 package Brackup::GPGProcess;
2 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 13 ▶use Brackup::Util qw(tempfile_obj);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 13 ▶use POSIX qw(_exit);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 13 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 0 ▶sub new {
Subroutine new: not called CC=8 SCAR=42.8
Pod undocumented
9 0 my ($class, $pchunk) = @_;
10  
11 0 my $destfh = tempfile_obj();
12 0 my $destfn = $destfh->filename;
13  
14 0 ▶ my $no_fork = $ENV{BRACKUP_NOFORK} || 0; # if true (perhaps on Windows?), then don't fork... do all inline.
Condition0%0/2
$ENV{'BRACKUP_NOFORK'} || 0
l!l
00
MC/DC0%0/1
$ENV{'BRACKUP_NOFORK'} || 0
$ENV{'BRACKUP_NOFORK'}
Truth table0%0/2
A
A= $ENV{'BRACKUP_NOFORK'}
Aresult
11
00
15  
16 0 ▶ my $pid = $no_fork ? 0 : fork;
Branch: 1 branch
BranchTrueFalseTotal
$no_fork ? : 0 0 0
17 0 ▶ if (!defined $pid) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $pid) 0 0 0
18 0 die "Failed to fork: $!";
19 }
20  
21 # caller (parent)
22 0 ▶ if ($pid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pid) 0 0 0
23 0 return bless {
24 destfh => $destfh,
25 pid => $pid,
26 running => 1,
27 }, $class;
28 }
29  
30 # child: encrypt and exit(0)...
31 0 $pchunk->root->encrypt($pchunk->raw_chunkref, $destfn);
32  
33 0 ▶ unless (-e $destfn) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $destfn) 0 0 0
34 # if the file's gone, that likely means the parent process
35 # already terminated and unlinked our temp file, in
36 # which case we should just exit (with error code), rather
37 # than spewing error messages to stderr.
38 0 POSIX::_exit(1);
39 }
40 0 ▶ unless (-s $destfn) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-s $destfn) 0 0 0
41 0 die "No data in encrypted output file";
42 }
43  
44 0 ▶ if ($no_fork) {
Branch: 1 branch
BranchTrueFalseTotal
if ($no_fork) 0 0 0
45 0 return bless {
46 destfh => $destfh,
47 pid => 0,
48 }, $class;
49 }
50  
51 # Note: we have to do this, to avoid some END block, somewhere,
52 # from cleaning up something or doing something. probably tempfiles
53 # being destroyed in File::Temp.
54 0 POSIX::_exit(0);
55 }
56  
57 0 ▶sub pid { $_[0]{pid} }
Subroutine pid: not called CC=1 SCAR=6.9
Pod undocumented
58  
59 0 ▶sub running { $_[0]{running} }
Subroutine running: not called CC=1 SCAR=6.9
Pod undocumented
60 0 ▶sub note_stopped { $_[0]{running} = 0; }
Subroutine note_stopped: not called CC=1 SCAR=6.9
Pod undocumented
61  
62 0 ▶sub chunkref {
Subroutine chunkref: not called CC=3 SCAR=24.8
Pod undocumented
63 0 my ($self) = @_;
64 0 ▶ die "Still running!" if $self->{running};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"running"} 0 0 0
65 0 ▶ die "No data in file" unless $self->size_on_disk;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->size_on_disk 0 0 0
66  
67 0 return $self->{destfh};
68 }
69  
70 0 ▶sub size_on_disk {
Subroutine size_on_disk: not called CC=1 SCAR=6.9
Pod undocumented
71 0 my $self = shift;
72 0 return -s $self->{destfh}->filename;
73 }
74  
75 13 1;
76  
« Brackup/GPGProcManager.pm ↑ Summary Brackup/BackupStats.pm »