CPAN
view release on metacpan or search on metacpan
lib/CPAN/FTP.pm view on Meta::CPAN
push @{$fullstats->{history}}, $stats;
# YAML.pm 0.62 is unacceptably slow with 999;
# YAML::Syck 0.82 has no noticable performance problem with 999;
my $ftpstats_size = $CPAN::Config->{ftpstats_size};
$ftpstats_size = 99 unless defined $ftpstats_size;
my $ftpstats_period = $CPAN::Config->{ftpstats_period} || 14;
while (
@{$fullstats->{history} || []}
&&
(
@{$fullstats->{history}} > $ftpstats_size
|| $time - $fullstats->{history}[0]{start} > 86400*$ftpstats_period
)
) {
shift @{$fullstats->{history}}
}
push @debug, scalar @{$fullstats->{history}} if $sdebug;
push @debug, time if $sdebug;
push @debug, scalar localtime($fullstats->{history}[0]{start}) if $sdebug;
# need no eval because if this fails, it is serious
my $sfile = File::Spec->catfile($CPAN::Config->{cpan_home},"FTPstats.yml");
CPAN->_yaml_dumpfile("$sfile.$$",$fullstats);
if ( $sdebug ) {
local $CPAN::DEBUG = 512; # FTP
push @debug, time;
CPAN->debug(sprintf("DEBUG history: before_read[%d]before[%d]at[%d]".
"after[%d]at[%d]oldest[%s]dumped backat[%d]",
@debug,
));
}
# Win32 cannot rename a file to an existing filename
unlink($sfile) if ($^O eq 'MSWin32' or $^O eq 'os2');
_copy_stat($sfile, "$sfile.$$") if -e $sfile;
rename "$sfile.$$", $sfile
or $CPAN::Frontend->mywarn("Could not rename '$sfile.$$' to '$sfile': $!\nGiving up\n");
}
}
# Copy some stat information (owner, group, mode and) from one file to
# another.
# This is a utility function which might be moved to a utility repository.
#-> sub CPAN::FTP::_copy_stat
sub _copy_stat {
my($src, $dest) = @_;
my @stat = stat($src);
if (!@stat) {
$CPAN::Frontend->mywarn("Can't stat '$src': $!\n");
return;
}
eval {
chmod $stat[2], $dest
or $CPAN::Frontend->mywarn("Can't chmod '$dest' to " . sprintf("0%o", $stat[2]) . ": $!\n");
};
warn $@ if $@;
eval {
chown $stat[4], $stat[5], $dest
or do {
my $save_err = $!; # otherwise it's lost in the get... calls
$CPAN::Frontend->mywarn("Can't chown '$dest' to " .
(getpwuid($stat[4]))[0] . "/" .
(getgrgid($stat[5]))[0] . ": $save_err\n"
);
};
};
warn $@ if $@;
}
# if file is CHECKSUMS, suggest the place where we got the file to be
# checked from, maybe only for young files?
#-> sub CPAN::FTP::_recommend_url_for
sub _recommend_url_for {
my($self, $file, $urllist) = @_;
if ($file =~ s|/CHECKSUMS(.gz)?$||) {
my $fullstats = $self->_ftp_statistics();
my $history = $fullstats->{history} || [];
while (my $last = pop @$history) {
last if $last->{end} - time > 3600; # only young results are interesting
next unless $last->{file}; # dirname of nothing dies!
next unless $file eq dirname($last->{file});
return $last->{thesiteurl};
}
}
if ($CPAN::Config->{randomize_urllist}
&&
rand(1) < $CPAN::Config->{randomize_urllist}
) {
$urllist->[int rand scalar @$urllist];
} else {
return ();
}
}
#-> sub CPAN::FTP::_get_urllist
sub _get_urllist {
my($self, $with_defaults) = @_;
$with_defaults ||= 0;
CPAN->debug("with_defaults[$with_defaults]") if $CPAN::DEBUG;
$CPAN::Config->{urllist} ||= [];
unless (ref $CPAN::Config->{urllist} eq 'ARRAY') {
$CPAN::Frontend->mywarn("Malformed urllist; ignoring. Configuration file corrupt?\n");
$CPAN::Config->{urllist} = [];
}
my @urllist = grep { defined $_ and length $_ } @{$CPAN::Config->{urllist}};
push @urllist, @CPAN::Defaultsites if $with_defaults;
for my $u (@urllist) {
CPAN->debug("u[$u]") if $CPAN::DEBUG;
if (UNIVERSAL::can($u,"text")) {
$u->{TEXT} .= "/" unless substr($u->{TEXT},-1) eq "/";
} else {
$u .= "/" unless substr($u,-1) eq "/";
$u = CPAN::URL->new(TEXT => $u, FROM => "USER");
}
}
\@urllist;
}
#-> sub CPAN::FTP::ftp_get ;
sub ftp_get {
my($class,$host,$dir,$file,$target) = @_;
( run in 2.875 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )