line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package BackupPC::XS; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
69750
|
use 5.008; |
|
1
|
|
|
|
|
4
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
5
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
54
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Exporter; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
6
|
use vars qw( @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
88
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# |
14
|
|
|
|
|
|
|
# These must match the file types used by tar |
15
|
|
|
|
|
|
|
# |
16
|
1
|
|
|
1
|
|
7
|
use constant BPC_FTYPE_FILE => 0; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
108
|
|
17
|
1
|
|
|
1
|
|
7
|
use constant BPC_FTYPE_HARDLINK => 1; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
45
|
|
18
|
1
|
|
|
1
|
|
6
|
use constant BPC_FTYPE_SYMLINK => 2; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
58
|
|
19
|
1
|
|
|
1
|
|
6
|
use constant BPC_FTYPE_CHARDEV => 3; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
53
|
|
20
|
1
|
|
|
1
|
|
6
|
use constant BPC_FTYPE_BLOCKDEV => 4; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
65
|
|
21
|
1
|
|
|
1
|
|
13
|
use constant BPC_FTYPE_DIR => 5; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
59
|
|
22
|
1
|
|
|
1
|
|
7
|
use constant BPC_FTYPE_FIFO => 6; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
23
|
1
|
|
|
1
|
|
6
|
use constant BPC_FTYPE_SOCKET => 8; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
50
|
|
24
|
1
|
|
|
1
|
|
6
|
use constant BPC_FTYPE_UNKNOWN => 9; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
50
|
|
25
|
1
|
|
|
1
|
|
7
|
use constant BPC_FTYPE_DELETED => 10; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
366
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
@EXPORT = qw( ); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
@EXPORT_OK = ( |
51
|
|
|
|
|
|
|
@FILE_TYPES, |
52
|
|
|
|
|
|
|
); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
%EXPORT_TAGS = ( |
55
|
|
|
|
|
|
|
'all' => [ @EXPORT_OK ], |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
our $VERSION = '0.60'; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
require XSLoader; |
61
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
{ |
73
|
0
|
|
|
0
|
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
|
0
|
|
|
|
|
if ( $compress > 0 ) { |
80
|
0
|
|
|
|
|
|
my $fh = BackupPC::XS::FileZIO::open($destFileZ, 1, $compress); |
81
|
0
|
|
|
|
|
|
my $data; |
82
|
0
|
0
|
0
|
|
|
|
if ( defined($fh) && open($srcFh, "<", $srcFile) ) { |
83
|
0
|
|
|
|
|
|
binmode($srcFh); |
84
|
0
|
|
|
|
|
|
while ( sysread($srcFh, $data, 65536 *4) > 0 ) { |
85
|
0
|
|
|
|
|
|
$fh->write(\$data); |
86
|
|
|
|
|
|
|
} |
87
|
0
|
|
|
|
|
|
close($srcFh); |
88
|
0
|
|
|
|
|
|
$fh->close(); |
89
|
0
|
0
|
|
|
|
|
unlink($srcFile) if ( $rmSrc ); |
90
|
0
|
|
|
|
|
|
utime($atime, $mtime, $destFileZ); |
91
|
0
|
|
|
|
|
|
return 1; |
92
|
|
|
|
|
|
|
} else { |
93
|
0
|
0
|
|
|
|
|
$fh->close() if ( defined($fh) ); |
94
|
0
|
|
|
|
|
|
return 0; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
0
|
0
|
|
|
|
|
return 0 if ( !defined($destFileNoZ) ); |
98
|
0
|
0
|
|
|
|
|
if ( $rmSrc ) { |
99
|
0
|
|
|
|
|
|
return rename($srcFile, $destFileNoZ); |
100
|
|
|
|
|
|
|
} else { |
101
|
0
|
0
|
|
|
|
|
return 0 if ( !copy($srcFile, $destFileNoZ) ); |
102
|
0
|
|
|
|
|
|
utime($atime, $mtime, $destFileNoZ); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
1; |
107
|
|
|
|
|
|
|
__END__ |