blib/lib/BackupPC/XS.pm

filter: Statementstmt 68.0% 51 / 75 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 93.3% 14 / 15 Podpod 0.0% 0 / 1 totaltotal 58.0% 65 / 112 CC 10 SCAR 38.4
CC
10
Cov
54%
compressCopy
110.0
BEGIN
1.0
BEGIN
1.0
CRAP 46.4
↑ Summary BackupPC_XS.xs »
1 package BackupPC::XS;
2  
3 1 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 require Exporter;
8  
9 1 ▶use vars qw( @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 @ISA = qw(Exporter);
12  
13 #
14 # These must match the file types used by tar
15 #
16 1 ▶use constant BPC_FTYPE_FILE => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use constant BPC_FTYPE_HARDLINK => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use constant BPC_FTYPE_SYMLINK => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use constant BPC_FTYPE_CHARDEV => 3;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use constant BPC_FTYPE_BLOCKDEV => 4;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use constant BPC_FTYPE_DIR => 5;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use constant BPC_FTYPE_FIFO => 6;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use constant BPC_FTYPE_SOCKET => 8;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use constant BPC_FTYPE_UNKNOWN => 9;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use constant BPC_FTYPE_DELETED => 10;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 1 my @FILE_TYPES = qw(
28 BPC_FTYPE_FILE
29 BPC_FTYPE_HARDLINK
30 BPC_FTYPE_SYMLINK
31 BPC_FTYPE_CHARDEV
32 BPC_FTYPE_BLOCKDEV
33 BPC_FTYPE_DIR
34 BPC_FTYPE_FIFO
35 BPC_FTYPE_SOCKET
36 BPC_FTYPE_UNKNOWN
37 BPC_FTYPE_DELETED
38 );
39  
40 # Items to export into callers namespace by default. Note: do not export
41 # names by default without a very good reason. Use EXPORT_OK instead.
42 # Do not simply export all your public functions/methods/constants.
43  
44 # This allows declaration use BackupPC::XS ':all';
45 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
46 # will save memory.
47  
48 1 @EXPORT = qw( );
49  
50 1 @EXPORT_OK = (
51 @FILE_TYPES,
52 );
53  
54 1 %EXPORT_TAGS = (
55 'all' => [ @EXPORT_OK ],
56 );
57  
58 1 our $VERSION = '0.62';
59  
60 1 require XSLoader;
61 1 XSLoader::load('BackupPC::XS', $VERSION);
62  
63 # Preloaded methods go here.
64  
65 #
66 # If $compress is >0, copy and compress $srcFile putting the output
67 # in $destFileZ. Otherwise, copy the file to $destFileNoZ, or do
68 # nothing if $destFileNoZ is undef. Finally, if rename is set, then
69 # the source file is removed.
70 #
71 sub compressCopy
72 0 ▶{
Subroutine compressCopy: not called CC=10 SCAR=47.0
Pod undocumented
73 0 my($srcFile, $destFileZ, $destFileNoZ, $compress, $rmSrc) = @_;
74 0 my($srcFh);
75 0 my(@s) = stat($srcFile);
76 0 my $atime = $s[8];
77 0 my $mtime = $s[9];
78  
79 0 ▶ if ( $compress > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($compress > 0) 0 0 0
80 0 my $fh = BackupPC::XS::FileZIO::open($destFileZ, 1, $compress);
81 0 my $data;
82 0 ▶ if ( defined($fh) && open($srcFh, "<", $srcFile) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fh and open $srcFh, '<', $srcFile) { } 0 0 0
Condition0%0/3
defined $fh and open $srcFh, "<", $srcFile
!ll&&!rl&&r
000
MC/DC0%0/2
defined $fh and open $srcFh, "<", $srcFile
defined $fh open $srcFh, "<", $srcFile
Truth table0%0/3
A and B
A= defined $fhB= open $srcFh, "<", $srcFile
ABresult
0X0
100
111
83 0 binmode($srcFh);
84 0 ▶ while ( sysread($srcFh, $data, 65536 *4) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (sysread($srcFh, $data, 262144) > 0) 0 0 0
85 0 $fh->write(\$data);
86 }
87 0 close($srcFh);
88 0 $fh->close();
89 0 ▶ unlink($srcFile) if ( $rmSrc );
Branch: 1 branch
BranchTrueFalseTotal
if $rmSrc 0 0 0
90 0 utime($atime, $mtime, $destFileZ);
91 0 return 1;
92 } else {
93 0 ▶ $fh->close() if ( defined($fh) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $fh 0 0 0
94 0 return 0;
95 }
96 }
97 0 ▶ return 0 if ( !defined($destFileNoZ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $destFileNoZ 0 0 0
98 0 ▶ if ( $rmSrc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rmSrc) { } 0 0 0
99 0 return rename($srcFile, $destFileNoZ);
100 } else {
101 0 ▶ return 0 if ( !copy($srcFile, $destFileNoZ) );
Branch: 1 branch
BranchTrueFalseTotal
unless copy($srcFile, $destFileNoZ) 0 0 0
102 0 utime($atime, $mtime, $destFileNoZ);
103 }
104 }
105  
106 1 1;
107 __END__
↑ Summary BackupPC_XS.xs »