| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package IO::BlockSync::App; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Basic |
|
4
|
1
|
|
|
1
|
|
1255
|
use 5.010; |
|
|
1
|
|
|
|
|
4
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
24
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use warnings FATAL => 'all'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
64
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# Build in |
|
9
|
1
|
|
|
1
|
|
648
|
use English qw( -no_match_vars ); |
|
|
1
|
|
|
|
|
3495
|
|
|
|
1
|
|
|
|
|
6
|
|
|
10
|
1
|
|
|
1
|
|
359
|
use Scalar::Util qw(blessed); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
116
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# CPAN |
|
13
|
1
|
|
|
1
|
|
7
|
use Moo; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
7
|
|
|
14
|
1
|
|
|
1
|
|
925
|
use MooX::Options; |
|
|
1
|
|
|
|
|
3819
|
|
|
|
1
|
|
|
|
|
6
|
|
|
15
|
1
|
|
|
1
|
|
88653
|
use Log::Log4perl; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
10
|
|
|
16
|
1
|
|
|
1
|
|
54
|
use Log::Log4perl::Level; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
9
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# This bundle |
|
19
|
1
|
|
|
1
|
|
146
|
use IO::BlockSync; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
542
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
################################################################ |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 NAME |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
IO::BlockSync::App - Perl module |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 VERSION |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Version 0.002 |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=cut |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
our $VERSION = '0.002'; |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
################################################################ |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
BlockSync can some of the same stuff that bigsync (by Egor Egorov) can |
|
40
|
|
|
|
|
|
|
- it's just written in perl. |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
BlockSync copies data from source file to destination file (can be a block |
|
43
|
|
|
|
|
|
|
device) and calculates checksum on each block it copies. |
|
44
|
|
|
|
|
|
|
On all runs after the first only the changed blocks will be copied. |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
blocksync -S -s /source/path -d /destination/path |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=cut |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
################################################################ |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 INSTALLATION |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Look in C<README.pod> |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Can also be found on |
|
57
|
|
|
|
|
|
|
L<GitHub|https://github.com/thordreier/perl-IO-BlockSync/blob/master/README.pod> |
|
58
|
|
|
|
|
|
|
or L<meta::cpan|https://metacpan.org/pod/distribution/IO-BlockSync/README.pod> |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=cut |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
################################################################ |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 COMMAND LINE OPTIONS |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=cut |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
################################################################ |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head2 -V --version |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Print version and exit |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=cut |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
option 'version' => ( |
|
77
|
|
|
|
|
|
|
is => 'ro', |
|
78
|
|
|
|
|
|
|
short => 'V', |
|
79
|
|
|
|
|
|
|
doc => 'print version and exit', |
|
80
|
|
|
|
|
|
|
); |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
################################################################ |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 -v --verbose |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Print version and exit |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=cut |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
option 'verbose' => ( |
|
91
|
|
|
|
|
|
|
is => 'ro', |
|
92
|
|
|
|
|
|
|
short => 'v', |
|
93
|
|
|
|
|
|
|
repeatable => 1, |
|
94
|
|
|
|
|
|
|
doc => 'be verbose', |
|
95
|
|
|
|
|
|
|
); |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
################################################################ |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head2 -s --src |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Path to source file. |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
mandatory - string (containing path) |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=cut |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
option 'src' => ( |
|
108
|
|
|
|
|
|
|
is => 'ro', |
|
109
|
|
|
|
|
|
|
format => 's', |
|
110
|
|
|
|
|
|
|
short => 's', |
|
111
|
|
|
|
|
|
|
doc => 'source file path', |
|
112
|
|
|
|
|
|
|
); |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
################################################################ |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head2 -d --dst |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Destination file. If not set, then only checksum file will be updated. |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
optional - string (containing path) |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=cut |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
option 'dst' => ( |
|
125
|
|
|
|
|
|
|
is => 'ro', |
|
126
|
|
|
|
|
|
|
format => 's', |
|
127
|
|
|
|
|
|
|
short => 'd', |
|
128
|
|
|
|
|
|
|
doc => 'destination file path', |
|
129
|
|
|
|
|
|
|
); |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
################################################################ |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head2 -c --chk |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Path to checksum file. |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
mandatory - string (containing path) |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=cut |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
option 'chk' => ( |
|
142
|
|
|
|
|
|
|
is => 'rwp', |
|
143
|
|
|
|
|
|
|
format => 's', |
|
144
|
|
|
|
|
|
|
short => 'c', |
|
145
|
|
|
|
|
|
|
doc => 'checksum file path', |
|
146
|
|
|
|
|
|
|
); |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
################################################################ |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 -b --bs |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Block size to use in bytes. |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
optional - integer - defaults to 1_048_576 B (1 MB) |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=cut |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
option 'bs' => ( |
|
159
|
|
|
|
|
|
|
is => 'ro', |
|
160
|
|
|
|
|
|
|
format => 'i', |
|
161
|
|
|
|
|
|
|
short => 'b', |
|
162
|
|
|
|
|
|
|
default => 1_048_576, |
|
163
|
|
|
|
|
|
|
doc => 'block size', |
|
164
|
|
|
|
|
|
|
); |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
################################################################ |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head2 -S --sparse |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Seek in dst file, instead of writing blocks only containing \0 |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
optional - boolean - defaults to 0 (false) |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=cut |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
option 'sparse' => ( |
|
177
|
|
|
|
|
|
|
is => 'ro', |
|
178
|
|
|
|
|
|
|
short => 'S', |
|
179
|
|
|
|
|
|
|
default => 0, |
|
180
|
|
|
|
|
|
|
## no critic (ValuesAndExpressions::RequireInterpolationOfMetachars) |
|
181
|
|
|
|
|
|
|
doc => 'seek in dst file, instead of writing blocks only containing \0', |
|
182
|
|
|
|
|
|
|
## use critic |
|
183
|
|
|
|
|
|
|
); |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
################################################################ |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head2 -t --truncate |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
Truncate the destination file to same size as source file. Does not work on block devices. Will only be tried if C<data> has default value (whole file is copied). |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
optional - boolean - defaults to 0 (false) |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=cut |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
option 'truncate' => ( |
|
196
|
|
|
|
|
|
|
is => 'ro', |
|
197
|
|
|
|
|
|
|
short => 't', |
|
198
|
|
|
|
|
|
|
default => 0, |
|
199
|
|
|
|
|
|
|
doc => 'truncate destination file', |
|
200
|
|
|
|
|
|
|
); |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
################################################################ |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=head1 METHODS |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=cut |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
################################################################ |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=head2 run |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
C<bin/blocksync> calls C<IO::BlockSync::App::run> to start the program. |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
If you just run C<blocksync> command then ignore this method. |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=cut |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
sub run { |
|
219
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
# Create object with data from command line and run this function again |
|
222
|
0
|
0
|
|
|
|
|
if ( !blessed $self) { |
|
223
|
0
|
|
|
|
|
|
return $self->new_with_options->run; |
|
224
|
|
|
|
|
|
|
} |
|
225
|
|
|
|
|
|
|
|
|
226
|
0
|
0
|
|
|
|
|
if ( $self->version ) { |
|
227
|
0
|
|
|
|
|
|
say "blocksync version $VERSION"; |
|
228
|
0
|
|
|
|
|
|
exit; |
|
229
|
|
|
|
|
|
|
} |
|
230
|
|
|
|
|
|
|
|
|
231
|
0
|
0
|
|
|
|
|
if ( !$self->src ) { |
|
232
|
0
|
|
|
|
|
|
$self->options_usage( 1, '<src> must be set' ); |
|
233
|
|
|
|
|
|
|
} |
|
234
|
|
|
|
|
|
|
|
|
235
|
0
|
0
|
0
|
|
|
|
if ( $self->dst && !$self->chk ) { |
|
|
|
0
|
0
|
|
|
|
|
|
236
|
0
|
|
|
|
|
|
$self->_set_chk( $self->dst . '.chk' ); |
|
237
|
|
|
|
|
|
|
} |
|
238
|
|
|
|
|
|
|
elsif ( !$self->dst && !$self->chk ) { |
|
239
|
0
|
|
|
|
|
|
$self->options_usage( 1, 'at least one of <chk> or <dst> must be set' ); |
|
240
|
|
|
|
|
|
|
} |
|
241
|
|
|
|
|
|
|
|
|
242
|
0
|
|
|
|
|
|
my $status; |
|
243
|
0
|
0
|
|
|
|
|
if ( $self->verbose ) { |
|
244
|
|
|
|
|
|
|
$status = sub { |
|
245
|
0
|
|
|
0
|
|
|
printf |
|
246
|
|
|
|
|
|
|
"Copying block=<%s> type=<%s> start=<%s> end=<%s> size=<%s>\n", |
|
247
|
|
|
|
|
|
|
@_, $_[3] - $_[2]; |
|
248
|
0
|
|
|
|
|
|
}; |
|
249
|
0
|
0
|
|
|
|
|
if ( $self->verbose > 1 ) { |
|
250
|
0
|
|
|
|
|
|
Log::Log4perl->init( \<<"EOF"); |
|
251
|
|
|
|
|
|
|
log4perl.logger = DEBUG, Screen |
|
252
|
|
|
|
|
|
|
log4perl.appender.Screen = Log::Log4perl::Appender::Screen |
|
253
|
|
|
|
|
|
|
log4perl.appender.Screen.layout = Log::Log4perl::Layout::PatternLayout |
|
254
|
|
|
|
|
|
|
log4perl.appender.Screen.layout.ConversionPattern = %d %p %M %m%n |
|
255
|
|
|
|
|
|
|
EOF |
|
256
|
|
|
|
|
|
|
} |
|
257
|
|
|
|
|
|
|
} |
|
258
|
|
|
|
|
|
|
else { |
|
259
|
|
|
|
|
|
|
$status = sub { |
|
260
|
0
|
|
|
0
|
|
|
$OUTPUT_AUTOFLUSH++; |
|
261
|
0
|
|
|
|
|
|
print( "\rCopying block " . shift ); |
|
262
|
|
|
|
|
|
|
} |
|
263
|
0
|
|
|
|
|
|
} |
|
264
|
|
|
|
|
|
|
|
|
265
|
0
|
|
|
|
|
|
BlockSync( %{$self}, 'status' => $status, ); |
|
|
0
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
|
|
267
|
0
|
|
|
|
|
|
say ''; |
|
268
|
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
# Make Perl::Critic happy |
|
270
|
0
|
|
|
|
|
|
return; |
|
271
|
|
|
|
|
|
|
} |
|
272
|
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
################################################################ |
|
274
|
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
276
|
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
This software is copyright (c) 2019 by Thor Dreier-Hansen. |
|
278
|
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
280
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
281
|
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
Terms of the Perl programming language system itself: |
|
283
|
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
=over |
|
285
|
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
=item * the |
|
287
|
|
|
|
|
|
|
L<GNU General Public License|http://dev.perl.org/licenses/gpl1.html> |
|
288
|
|
|
|
|
|
|
as published by the Free Software Foundation; either |
|
289
|
|
|
|
|
|
|
L<version 1|http://dev.perl.org/licenses/gpl1.html>, |
|
290
|
|
|
|
|
|
|
or (at your option) any later version, or |
|
291
|
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
=item * the L<"Artistic License"|http://dev.perl.org/licenses/artistic.html> |
|
293
|
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
=back |
|
295
|
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
See L<http://dev.perl.org/licenses/> for more information. |
|
297
|
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
=cut |
|
299
|
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
1; # End of IO::BlockSync::App |