File-AptFetch
view release on metacpan or search on metacpan
lib/AptFetch.pm view on Meta::CPAN
If naming or handling of unfinished transfers would ever change there will be
breakage.
=item *
Then.
When transfer is finished *physically* it's not reported just yet
(temporal has been renamed).
A method calculates hashes.
For obvious reasons methods do not coummunicate progress either.
Naive approach would be to check size and then just wait forever.
That's possible size isn't known beforehand.
So B<_read_callback()> increases number of ticks before signaling timeout.
That increase is function of tick length (I<$ConfigData{tick}>), current file
size, and supposed IO speed.
The IO speed is hardcoded to be 15MB/sec.
So if media is realy slow (like a diskette or something) there's a possibility
of breakage.
However, those nitty-gritty manipulations won't result ever in timeout
decrease.
=back
For now it's not clear if B<_read_callback()> ought to provide some
diagnostics.
Right now it doesn't.
=cut
sub _read_callback {
my $st = shift;
defined $st->{filename} or return undef;
$st->{tick} =
File::AptFetch::ConfigData->config( q|tick| ) unless $st->{tick};
$st->{flag} = 5 unless defined $st->{flag};
$st->{tmp} = ( glob qq|$st->{filename}*| )[0] unless defined $st->{tmp};
unless( defined $st->{tmp} ) {
# TODO:201403040310:whynot: Here comes diagnostics.
# warn sprintf qq|(%s) (%i): missing, ticks left\n|, ( split m{/}, $st->{filename} )[-1], $st->{flag} - 1
}
elsif( !-f $st->{tmp} ) {
# TODO:201403040310:whynot: Here could be diagnostics too.
# warn sprintf qq|(%s): disappeared, forcing sync\n|, ( split m{/}, $st->{filename} )[-1];
undef $st->{tmp} }
else {
@$st{qw| size back |} = ( -s $st->{tmp}, $st->{size} || 0 );
$st->{factor} = $st->{size} / ( $st->{tick} * 15 * 1024 * 1024 );
$st->{factor} = 1 if 1 > $st->{factor};
$st->{flag} = 5 * $st->{factor} if $st->{size} - $st->{back} }
0 < $st->{flag}-- }
set_callback read => \&_read_callback;
=back
=cut
=head1 DIAGNOSTICS
Most error communication is done through give-up codes.
However, some conditions aren't worth of keeping process alive -- those are
marked as B<(fatal)>.
Others are (mostly) in just B<fork>ed process that just couldn't boot
properly -- those are communicated back (somehow).
=over
=item (%s): candiate to pass is neither CODE nor (undef)
B<(fatal)>
In L</set_callback()>.
Tag C<%s> (may be unknown) tries to set something for callback.
That must be either CODE or C<undef>.
It's not.
=item (%s): unknown callback
B<(fatal)>
In L</set_callback()>.
Tag C<%s> is unknown.
Nothing to do with it but B<croak>.
=item [close] (reader): $!
In L</DESTROY()> (that's why it's not fatal).
Closing I<STDIN> of child has failed.
Nothing to do with it except blast ahead
(probably, would stuck in B<waitpid> then).
=item [close] (writer): $!
In L</DESTROY()> (that's why it's not fatal).
Closing I<STDOUT> of child has failed.
Nothing to do with it except blast ahead
(probably, would stuck in B<waitpid> then).
=item [dup] (STDIN): $!
In L</init()>.
Turning reader pipe into I<STDIN> has failed.
Parent will express it with S<($method): ($?): died without handshake> give-up
code.
=item [dup] (STDOUT): $!
In L</init()> or L</_cache_configuration()>.
Turning writer pipe into I<STDOUT> has failed.
Parent will express it with S<($method): ($?): died without handshake> or
S<($method): (apt-config) died: ($?)> give-up code.
=item [exec] ($method): $!
In L</init()>.
Executing requested I<$method> has failed.
Parent will express it with S<($method): ($?): died without handshake> give-up
code.
=item [fork] ($method): $!
=item [fork] (apt-config): $!
( run in 0.369 second using v1.01-cache-2.11-cpan-71847e10f99 )