line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::Copy::Reliable; |
2
|
1
|
|
|
1
|
|
647
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
54
|
|
4
|
1
|
|
|
1
|
|
6
|
use Carp qw(croak); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
52
|
|
5
|
1
|
|
|
1
|
|
5
|
use File::Copy; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
52
|
|
6
|
1
|
|
|
1
|
|
5
|
use Path::Class; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
53
|
|
7
|
1
|
|
|
1
|
|
5
|
use Exporter 'import'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
312
|
|
8
|
|
|
|
|
|
|
our @EXPORT = qw(copy_reliable move_reliable); |
9
|
|
|
|
|
|
|
our $VERSION = '0.32'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub copy_reliable { |
12
|
5
|
|
|
5
|
1
|
8172
|
my ( $source, $destination ) = @_; |
13
|
5
|
|
100
|
|
|
171
|
my $source_size = (-s $source) || 0; |
14
|
|
|
|
|
|
|
|
15
|
5
|
100
|
|
|
|
98
|
copy( $source, $destination ) |
16
|
|
|
|
|
|
|
|| croak("copy_reliable($source, $destination) failed: $!"); |
17
|
3
|
|
|
|
|
664
|
my $destination_file = $destination; |
18
|
3
|
100
|
|
|
|
31
|
if (-d $destination) { |
19
|
1
|
|
|
|
|
5
|
$destination_file = file( $destination, file( $source )->basename ); |
20
|
|
|
|
|
|
|
} |
21
|
3
|
|
100
|
|
|
193
|
my $destination_size = (-s $destination_file) || 0; |
22
|
3
|
100
|
|
|
|
74
|
croak( |
23
|
|
|
|
|
|
|
"copy_reliable($source, $destination) failed copied $destination_size bytes out of $source_size" |
24
|
|
|
|
|
|
|
) |
25
|
|
|
|
|
|
|
if ( $source_size != $destination_size ); |
26
|
2
|
|
|
|
|
6
|
1; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub move_reliable { |
31
|
4
|
|
|
4
|
1
|
5067
|
my ( $source, $destination ) = @_; |
32
|
4
|
|
100
|
|
|
144
|
my $source_size = (-s $source) || 0; |
33
|
|
|
|
|
|
|
|
34
|
4
|
100
|
|
|
|
100
|
move( $source, $destination ) |
35
|
|
|
|
|
|
|
|| croak("move_reliable($source, $destination) failed: $!"); |
36
|
2
|
|
|
|
|
171
|
my $destination_file = $destination; |
37
|
2
|
50
|
|
|
|
7
|
if (-d $destination) { |
38
|
0
|
|
|
|
|
0
|
$destination_file = file( $destination, file( $source )->basename ); |
39
|
|
|
|
|
|
|
} |
40
|
2
|
|
100
|
|
|
67
|
my $destination_size = (-s $destination_file) || 0; |
41
|
2
|
100
|
|
|
|
80
|
croak( |
42
|
|
|
|
|
|
|
"move_reliable($source, $destination) failed copied $destination_size bytes out of $source_size" |
43
|
|
|
|
|
|
|
) |
44
|
|
|
|
|
|
|
if ( $source_size != $destination_size ); |
45
|
1
|
|
|
|
|
3
|
1; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
1; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
__END__ |