line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- Mode: cperl; coding: utf-8; cperl-indent-level: 4 -*- |
2
|
|
|
|
|
|
|
# vim: ts=4 sts=4 sw=4: |
3
|
|
|
|
|
|
|
package CPAN::FTP; |
4
|
13
|
|
|
13
|
|
91
|
use strict; |
|
13
|
|
|
|
|
26
|
|
|
13
|
|
|
|
|
399
|
|
5
|
|
|
|
|
|
|
|
6
|
13
|
|
|
13
|
|
2811
|
use Errno (); |
|
13
|
|
|
|
|
8549
|
|
|
13
|
|
|
|
|
301
|
|
7
|
13
|
|
|
13
|
|
75
|
use Fcntl qw(:flock); |
|
13
|
|
|
|
|
23
|
|
|
13
|
|
|
|
|
2057
|
|
8
|
13
|
|
|
13
|
|
100
|
use File::Basename qw(dirname); |
|
13
|
|
|
|
|
24
|
|
|
13
|
|
|
|
|
1320
|
|
9
|
13
|
|
|
13
|
|
89
|
use File::Path qw(mkpath); |
|
13
|
|
|
|
|
28
|
|
|
13
|
|
|
|
|
792
|
|
10
|
13
|
|
|
13
|
|
4821
|
use CPAN::FTP::netrc; |
|
13
|
|
|
|
|
34
|
|
|
13
|
|
|
|
|
424
|
|
11
|
13
|
|
|
13
|
|
78
|
use vars qw($connect_to_internet_ok $Ua $Thesite $ThesiteURL $Themethod); |
|
13
|
|
|
|
|
28
|
|
|
13
|
|
|
|
|
932
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
@CPAN::FTP::ISA = qw(CPAN::Debug); |
14
|
|
|
|
|
|
|
|
15
|
13
|
|
|
|
|
96222
|
use vars qw( |
16
|
|
|
|
|
|
|
$VERSION |
17
|
13
|
|
|
13
|
|
73
|
); |
|
13
|
|
|
|
|
24
|
|
18
|
|
|
|
|
|
|
$VERSION = "5.5012"; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub _plus_append_open { |
21
|
0
|
|
|
0
|
|
0
|
my($fh, $file) = @_; |
22
|
0
|
|
|
|
|
0
|
my $parent_dir = dirname $file; |
23
|
0
|
|
|
|
|
0
|
mkpath $parent_dir; |
24
|
0
|
|
|
|
|
0
|
my($cnt); |
25
|
0
|
|
|
|
|
0
|
until (open $fh, "+>>$file") { |
26
|
0
|
0
|
0
|
|
|
0
|
next if exists &Errno::EAGAIN && $! == &Errno::EAGAIN; # don't increment on EAGAIN |
27
|
0
|
0
|
|
|
|
0
|
$CPAN::Frontend->mydie("Could not open '$file' after 10000 tries: $!") if ++$cnt > 100000; |
28
|
0
|
|
|
|
|
0
|
sleep 0.0001; |
29
|
0
|
|
|
|
|
0
|
mkpath $parent_dir; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
#-> sub CPAN::FTP::ftp_statistics |
34
|
|
|
|
|
|
|
# if they want to rewrite, they need to pass in a filehandle |
35
|
|
|
|
|
|
|
sub _ftp_statistics { |
36
|
0
|
|
|
0
|
|
0
|
my($self,$fh) = @_; |
37
|
0
|
|
|
|
|
0
|
my $ftpstats_size = $CPAN::Config->{ftpstats_size}; |
38
|
0
|
0
|
0
|
|
|
0
|
return if defined $ftpstats_size && $ftpstats_size <= 0; |
39
|
0
|
0
|
|
|
|
0
|
my $locktype = $fh ? LOCK_EX : LOCK_SH; |
40
|
|
|
|
|
|
|
# XXX On Windows flock() implements mandatory locking, so we can |
41
|
|
|
|
|
|
|
# XXX only use shared locking to still allow _yaml_load_file() to |
42
|
|
|
|
|
|
|
# XXX read from the file using a different filehandle. |
43
|
0
|
0
|
|
|
|
0
|
$locktype = LOCK_SH if $^O eq "MSWin32"; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
0
|
|
|
0
|
$fh ||= FileHandle->new; |
46
|
0
|
|
|
|
|
0
|
my $file = File::Spec->catfile($CPAN::Config->{cpan_home},"FTPstats.yml"); |
47
|
0
|
|
|
|
|
0
|
_plus_append_open($fh,$file); |
48
|
0
|
|
|
|
|
0
|
my $sleep = 1; |
49
|
0
|
|
|
|
|
0
|
my $waitstart; |
50
|
0
|
|
|
|
|
0
|
while (!CPAN::_flock($fh, $locktype|LOCK_NB)) { |
51
|
0
|
|
0
|
|
|
0
|
$waitstart ||= localtime(); |
52
|
0
|
0
|
|
|
|
0
|
if ($sleep>3) { |
53
|
0
|
|
|
|
|
0
|
my $now = localtime(); |
54
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->mywarn("$now: waiting for read lock on '$file' (since $waitstart)\n"); |
55
|
|
|
|
|
|
|
} |
56
|
0
|
|
|
|
|
0
|
sleep($sleep); # this sleep must not be overridden; |
57
|
|
|
|
|
|
|
# Frontend->mysleep with AUTOMATED_TESTING has |
58
|
|
|
|
|
|
|
# provoked complete lock contention on my NFS |
59
|
0
|
0
|
|
|
|
0
|
if ($sleep <= 6) { |
60
|
0
|
|
|
|
|
0
|
$sleep+=0.5; |
61
|
|
|
|
|
|
|
} else { |
62
|
|
|
|
|
|
|
# retry to get a fresh handle. If it is NFS and the handle is stale, we will never get an flock |
63
|
0
|
|
|
|
|
0
|
_plus_append_open($fh, $file); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
0
|
|
|
|
|
0
|
my $stats = eval { CPAN->_yaml_loadfile($file); }; |
|
0
|
|
|
|
|
0
|
|
67
|
0
|
0
|
|
|
|
0
|
if ($@) { |
68
|
0
|
0
|
|
|
|
0
|
if (ref $@) { |
69
|
0
|
0
|
|
|
|
0
|
if (ref $@ eq "CPAN::Exception::yaml_not_installed") { |
|
|
0
|
|
|
|
|
|
70
|
0
|
|
|
|
|
0
|
chomp $@; |
71
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->myprintonce("Warning (usually harmless): $@\n"); |
72
|
0
|
|
|
|
|
0
|
return; |
73
|
|
|
|
|
|
|
} elsif (ref $@ eq "CPAN::Exception::yaml_process_error") { |
74
|
0
|
|
|
|
|
0
|
my $time = time; |
75
|
0
|
|
|
|
|
0
|
my $to = "$file.$time"; |
76
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->mywarn("Error reading '$file': $@ |
77
|
|
|
|
|
|
|
Trying to stash it away as '$to' to prevent further interruptions. |
78
|
|
|
|
|
|
|
You may want to remove that file later.\n"); |
79
|
|
|
|
|
|
|
# may fail because somebody else has moved it away in the meantime: |
80
|
0
|
0
|
|
|
|
0
|
rename $file, $to or $CPAN::Frontend->mywarn("Could not rename '$file' to '$to': $!\n"); |
81
|
0
|
|
|
|
|
0
|
return; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} else { |
84
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->mydie($@); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
0
|
|
|
|
|
0
|
CPAN::_flock($fh, LOCK_UN); |
88
|
0
|
|
|
|
|
0
|
return $stats->[0]; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
#-> sub CPAN::FTP::_mytime |
92
|
|
|
|
|
|
|
sub _mytime () { |
93
|
6
|
50
|
|
6
|
|
21
|
if (CPAN->has_inst("Time::HiRes")) { |
94
|
6
|
|
|
|
|
48
|
return Time::HiRes::time(); |
95
|
|
|
|
|
|
|
} else { |
96
|
0
|
|
|
|
|
0
|
return time; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
#-> sub CPAN::FTP::_new_stats |
101
|
|
|
|
|
|
|
sub _new_stats { |
102
|
3
|
|
|
3
|
|
7
|
my($self,$file) = @_; |
103
|
3
|
|
|
|
|
10
|
my $ret = { |
104
|
|
|
|
|
|
|
file => $file, |
105
|
|
|
|
|
|
|
attempts => [], |
106
|
|
|
|
|
|
|
start => _mytime, |
107
|
|
|
|
|
|
|
}; |
108
|
3
|
|
|
|
|
8
|
$ret; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
#-> sub CPAN::FTP::_add_to_statistics |
112
|
|
|
|
|
|
|
sub _add_to_statistics { |
113
|
3
|
|
|
3
|
|
8
|
my($self,$stats) = @_; |
114
|
3
|
|
|
|
|
13
|
my $yaml_module = CPAN::_yaml_module(); |
115
|
3
|
50
|
|
|
|
8
|
$self->debug("yaml_module[$yaml_module]") if $CPAN::DEBUG; |
116
|
3
|
50
|
|
|
|
8
|
if ($CPAN::META->has_inst($yaml_module)) { |
117
|
0
|
|
|
|
|
0
|
$stats->{thesiteurl} = $ThesiteURL; |
118
|
0
|
|
|
|
|
0
|
$stats->{end} = CPAN::FTP::_mytime(); |
119
|
0
|
|
|
|
|
0
|
my $fh = FileHandle->new; |
120
|
0
|
|
|
|
|
0
|
my $time = time; |
121
|
0
|
|
|
|
|
0
|
my $sdebug = 0; |
122
|
0
|
|
|
|
|
0
|
my @debug; |
123
|
0
|
0
|
|
|
|
0
|
@debug = $time if $sdebug; |
124
|
0
|
|
|
|
|
0
|
my $fullstats = $self->_ftp_statistics($fh); |
125
|
0
|
0
|
0
|
|
|
0
|
close $fh if $fh && defined(fileno($fh)); |
126
|
0
|
|
0
|
|
|
0
|
$fullstats->{history} ||= []; |
127
|
0
|
0
|
|
|
|
0
|
push @debug, scalar @{$fullstats->{history}} if $sdebug; |
|
0
|
|
|
|
|
0
|
|
128
|
0
|
0
|
|
|
|
0
|
push @debug, time if $sdebug; |
129
|
0
|
|
|
|
|
0
|
push @{$fullstats->{history}}, $stats; |
|
0
|
|
|
|
|
0
|
|
130
|
|
|
|
|
|
|
# YAML.pm 0.62 is unacceptably slow with 999; |
131
|
|
|
|
|
|
|
# YAML::Syck 0.82 has no noticable performance problem with 999; |
132
|
0
|
|
|
|
|
0
|
my $ftpstats_size = $CPAN::Config->{ftpstats_size}; |
133
|
0
|
0
|
|
|
|
0
|
$ftpstats_size = 99 unless defined $ftpstats_size; |
134
|
0
|
|
0
|
|
|
0
|
my $ftpstats_period = $CPAN::Config->{ftpstats_period} || 14; |
135
|
0
|
|
0
|
|
|
0
|
while ( |
|
|
|
0
|
|
|
|
|
136
|
0
|
0
|
|
|
|
0
|
@{$fullstats->{history} || []} |
137
|
|
|
|
|
|
|
&& |
138
|
|
|
|
|
|
|
( |
139
|
|
|
|
|
|
|
@{$fullstats->{history}} > $ftpstats_size |
140
|
|
|
|
|
|
|
|| $time - $fullstats->{history}[0]{start} > 86400*$ftpstats_period |
141
|
|
|
|
|
|
|
) |
142
|
|
|
|
|
|
|
) { |
143
|
0
|
|
|
|
|
0
|
shift @{$fullstats->{history}} |
|
0
|
|
|
|
|
0
|
|
144
|
|
|
|
|
|
|
} |
145
|
0
|
0
|
|
|
|
0
|
push @debug, scalar @{$fullstats->{history}} if $sdebug; |
|
0
|
|
|
|
|
0
|
|
146
|
0
|
0
|
|
|
|
0
|
push @debug, time if $sdebug; |
147
|
0
|
0
|
|
|
|
0
|
push @debug, scalar localtime($fullstats->{history}[0]{start}) if $sdebug; |
148
|
|
|
|
|
|
|
# need no eval because if this fails, it is serious |
149
|
0
|
|
|
|
|
0
|
my $sfile = File::Spec->catfile($CPAN::Config->{cpan_home},"FTPstats.yml"); |
150
|
0
|
|
|
|
|
0
|
CPAN->_yaml_dumpfile("$sfile.$$",$fullstats); |
151
|
0
|
0
|
|
|
|
0
|
if ( $sdebug ) { |
152
|
0
|
|
|
|
|
0
|
local $CPAN::DEBUG = 512; # FTP |
153
|
0
|
|
|
|
|
0
|
push @debug, time; |
154
|
0
|
|
|
|
|
0
|
CPAN->debug(sprintf("DEBUG history: before_read[%d]before[%d]at[%d]". |
155
|
|
|
|
|
|
|
"after[%d]at[%d]oldest[%s]dumped backat[%d]", |
156
|
|
|
|
|
|
|
@debug, |
157
|
|
|
|
|
|
|
)); |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
# Win32 cannot rename a file to an existing filename |
160
|
0
|
0
|
0
|
|
|
0
|
unlink($sfile) if ($^O eq 'MSWin32' or $^O eq 'os2'); |
161
|
0
|
0
|
|
|
|
0
|
_copy_stat($sfile, "$sfile.$$") if -e $sfile; |
162
|
0
|
0
|
|
|
|
0
|
rename "$sfile.$$", $sfile |
163
|
|
|
|
|
|
|
or $CPAN::Frontend->mywarn("Could not rename '$sfile.$$' to '$sfile': $!\nGiving up\n"); |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
# Copy some stat information (owner, group, mode and) from one file to |
168
|
|
|
|
|
|
|
# another. |
169
|
|
|
|
|
|
|
# This is a utility function which might be moved to a utility repository. |
170
|
|
|
|
|
|
|
#-> sub CPAN::FTP::_copy_stat |
171
|
|
|
|
|
|
|
sub _copy_stat { |
172
|
0
|
|
|
0
|
|
0
|
my($src, $dest) = @_; |
173
|
0
|
|
|
|
|
0
|
my @stat = stat($src); |
174
|
0
|
0
|
|
|
|
0
|
if (!@stat) { |
175
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->mywarn("Can't stat '$src': $!\n"); |
176
|
0
|
|
|
|
|
0
|
return; |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
0
|
|
|
|
|
0
|
eval { |
180
|
0
|
0
|
|
|
|
0
|
chmod $stat[2], $dest |
181
|
|
|
|
|
|
|
or $CPAN::Frontend->mywarn("Can't chmod '$dest' to " . sprintf("0%o", $stat[2]) . ": $!\n"); |
182
|
|
|
|
|
|
|
}; |
183
|
0
|
0
|
|
|
|
0
|
warn $@ if $@; |
184
|
0
|
|
|
|
|
0
|
eval { |
185
|
|
|
|
|
|
|
chown $stat[4], $stat[5], $dest |
186
|
0
|
0
|
|
|
|
0
|
or do { |
187
|
0
|
|
|
|
|
0
|
my $save_err = $!; # otherwise it's lost in the get... calls |
188
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->mywarn("Can't chown '$dest' to " . |
189
|
|
|
|
|
|
|
(getpwuid($stat[4]))[0] . "/" . |
190
|
|
|
|
|
|
|
(getgrgid($stat[5]))[0] . ": $save_err\n" |
191
|
|
|
|
|
|
|
); |
192
|
|
|
|
|
|
|
}; |
193
|
|
|
|
|
|
|
}; |
194
|
0
|
0
|
|
|
|
0
|
warn $@ if $@; |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
# if file is CHECKSUMS, suggest the place where we got the file to be |
198
|
|
|
|
|
|
|
# checked from, maybe only for young files? |
199
|
|
|
|
|
|
|
#-> sub CPAN::FTP::_recommend_url_for |
200
|
|
|
|
|
|
|
sub _recommend_url_for { |
201
|
3
|
|
|
3
|
|
9
|
my($self, $file, $urllist) = @_; |
202
|
3
|
50
|
|
|
|
17
|
if ($file =~ s|/CHECKSUMS(.gz)?$||) { |
203
|
0
|
|
|
|
|
0
|
my $fullstats = $self->_ftp_statistics(); |
204
|
0
|
|
0
|
|
|
0
|
my $history = $fullstats->{history} || []; |
205
|
0
|
|
|
|
|
0
|
while (my $last = pop @$history) { |
206
|
0
|
0
|
|
|
|
0
|
last if $last->{end} - time > 3600; # only young results are interesting |
207
|
0
|
0
|
|
|
|
0
|
next unless $last->{file}; # dirname of nothing dies! |
208
|
0
|
0
|
|
|
|
0
|
next unless $file eq dirname($last->{file}); |
209
|
0
|
|
|
|
|
0
|
return $last->{thesiteurl}; |
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
} |
212
|
3
|
50
|
33
|
|
|
11
|
if ($CPAN::Config->{randomize_urllist} |
213
|
|
|
|
|
|
|
&& |
214
|
|
|
|
|
|
|
rand(1) < $CPAN::Config->{randomize_urllist} |
215
|
|
|
|
|
|
|
) { |
216
|
0
|
|
|
|
|
0
|
$urllist->[int rand scalar @$urllist]; |
217
|
|
|
|
|
|
|
} else { |
218
|
3
|
|
|
|
|
11
|
return (); |
219
|
|
|
|
|
|
|
} |
220
|
|
|
|
|
|
|
} |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
#-> sub CPAN::FTP::_get_urllist |
223
|
|
|
|
|
|
|
sub _get_urllist { |
224
|
3
|
|
|
3
|
|
8
|
my($self, $with_defaults) = @_; |
225
|
3
|
|
50
|
|
|
19
|
$with_defaults ||= 0; |
226
|
3
|
50
|
|
|
|
7
|
CPAN->debug("with_defaults[$with_defaults]") if $CPAN::DEBUG; |
227
|
|
|
|
|
|
|
|
228
|
3
|
|
50
|
|
|
8
|
$CPAN::Config->{urllist} ||= []; |
229
|
3
|
50
|
|
|
|
10
|
unless (ref $CPAN::Config->{urllist} eq 'ARRAY') { |
230
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->mywarn("Malformed urllist; ignoring. Configuration file corrupt?\n"); |
231
|
0
|
|
|
|
|
0
|
$CPAN::Config->{urllist} = []; |
232
|
|
|
|
|
|
|
} |
233
|
3
|
50
|
|
|
|
4
|
my @urllist = grep { defined $_ and length $_ } @{$CPAN::Config->{urllist}}; |
|
3
|
|
|
|
|
19
|
|
|
3
|
|
|
|
|
7
|
|
234
|
3
|
50
|
|
|
|
10
|
push @urllist, @CPAN::Defaultsites if $with_defaults; |
235
|
3
|
|
|
|
|
6
|
for my $u (@urllist) { |
236
|
3
|
50
|
|
|
|
10
|
CPAN->debug("u[$u]") if $CPAN::DEBUG; |
237
|
3
|
50
|
|
|
|
27
|
if (UNIVERSAL::can($u,"text")) { |
238
|
0
|
0
|
|
|
|
0
|
$u->{TEXT} .= "/" unless substr($u->{TEXT},-1) eq "/"; |
239
|
|
|
|
|
|
|
} else { |
240
|
3
|
50
|
|
|
|
17
|
$u .= "/" unless substr($u,-1) eq "/"; |
241
|
3
|
|
|
|
|
24
|
$u = CPAN::URL->new(TEXT => $u, FROM => "USER"); |
242
|
|
|
|
|
|
|
} |
243
|
|
|
|
|
|
|
} |
244
|
3
|
|
|
|
|
7
|
\@urllist; |
245
|
|
|
|
|
|
|
} |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
#-> sub CPAN::FTP::ftp_get ; |
248
|
|
|
|
|
|
|
sub ftp_get { |
249
|
0
|
|
|
0
|
0
|
0
|
my($class,$host,$dir,$file,$target) = @_; |
250
|
0
|
0
|
|
|
|
0
|
$class->debug( |
251
|
|
|
|
|
|
|
qq[Going to fetch file [$file] from dir [$dir] |
252
|
|
|
|
|
|
|
on host [$host] as local [$target]\n] |
253
|
|
|
|
|
|
|
) if $CPAN::DEBUG; |
254
|
0
|
|
|
|
|
0
|
my $ftp = Net::FTP->new($host); |
255
|
0
|
0
|
|
|
|
0
|
unless ($ftp) { |
256
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->mywarn(" Could not connect to host '$host' with Net::FTP\n"); |
257
|
0
|
|
|
|
|
0
|
return; |
258
|
|
|
|
|
|
|
} |
259
|
0
|
0
|
|
|
|
0
|
return 0 unless defined $ftp; |
260
|
0
|
0
|
|
|
|
0
|
$ftp->debug(1) if $CPAN::DEBUG{'FTP'} & $CPAN::DEBUG; |
261
|
0
|
|
|
|
|
0
|
$class->debug(qq[Going to login("anonymous","$Config::Config{cf_email}")]); |
262
|
0
|
0
|
|
|
|
0
|
unless ( $ftp->login("anonymous",$Config::Config{'cf_email'}) ) { |
263
|
0
|
|
|
|
|
0
|
my $msg = $ftp->message; |
264
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->mywarn(" Couldn't login on $host: $msg\n"); |
265
|
0
|
|
|
|
|
0
|
return; |
266
|
|
|
|
|
|
|
} |
267
|
0
|
0
|
|
|
|
0
|
unless ( $ftp->cwd($dir) ) { |
268
|
0
|
|
|
|
|
0
|
my $msg = $ftp->message; |
269
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->mywarn(" Couldn't cwd $dir: $msg\n"); |
270
|
0
|
|
|
|
|
0
|
return; |
271
|
|
|
|
|
|
|
} |
272
|
0
|
|
|
|
|
0
|
$ftp->binary; |
273
|
0
|
0
|
|
|
|
0
|
$class->debug(qq[Going to ->get("$file","$target")\n]) if $CPAN::DEBUG; |
274
|
0
|
0
|
|
|
|
0
|
unless ( $ftp->get($file,$target) ) { |
275
|
0
|
|
|
|
|
0
|
my $msg = $ftp->message; |
276
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->mywarn(" Couldn't fetch $file from $host: $msg\n"); |
277
|
0
|
|
|
|
|
0
|
return; |
278
|
|
|
|
|
|
|
} |
279
|
0
|
|
|
|
|
0
|
$ftp->quit; # it's ok if this fails |
280
|
0
|
|
|
|
|
0
|
return 1; |
281
|
|
|
|
|
|
|
} |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
# If more accuracy is wanted/needed, Chris Leach sent me this patch... |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
# > *** /install/perl/live/lib/CPAN.pm- Wed Sep 24 13:08:48 1997 |
286
|
|
|
|
|
|
|
# > --- /tmp/cp Wed Sep 24 13:26:40 1997 |
287
|
|
|
|
|
|
|
# > *************** |
288
|
|
|
|
|
|
|
# > *** 1562,1567 **** |
289
|
|
|
|
|
|
|
# > --- 1562,1580 ---- |
290
|
|
|
|
|
|
|
# > return 1 if substr($url,0,4) eq "file"; |
291
|
|
|
|
|
|
|
# > return 1 unless $url =~ m|://([^/]+)|; |
292
|
|
|
|
|
|
|
# > my $host = $1; |
293
|
|
|
|
|
|
|
# > + my $proxy = $CPAN::Config->{'http_proxy'} || $ENV{'http_proxy'}; |
294
|
|
|
|
|
|
|
# > + if ($proxy) { |
295
|
|
|
|
|
|
|
# > + $proxy =~ m|://([^/:]+)|; |
296
|
|
|
|
|
|
|
# > + $proxy = $1; |
297
|
|
|
|
|
|
|
# > + my $noproxy = $CPAN::Config->{'no_proxy'} || $ENV{'no_proxy'}; |
298
|
|
|
|
|
|
|
# > + if ($noproxy) { |
299
|
|
|
|
|
|
|
# > + if ($host !~ /$noproxy$/) { |
300
|
|
|
|
|
|
|
# > + $host = $proxy; |
301
|
|
|
|
|
|
|
# > + } |
302
|
|
|
|
|
|
|
# > + } else { |
303
|
|
|
|
|
|
|
# > + $host = $proxy; |
304
|
|
|
|
|
|
|
# > + } |
305
|
|
|
|
|
|
|
# > + } |
306
|
|
|
|
|
|
|
# > require Net::Ping; |
307
|
|
|
|
|
|
|
# > return 1 unless $Net::Ping::VERSION >= 2; |
308
|
|
|
|
|
|
|
# > my $p; |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
#-> sub CPAN::FTP::localize ; |
312
|
|
|
|
|
|
|
sub localize { |
313
|
3
|
|
|
3
|
0
|
10
|
my($self,$file,$aslocal,$force,$with_defaults) = @_; |
314
|
3
|
|
50
|
|
|
11
|
$force ||= 0; |
315
|
3
|
50
|
|
|
|
10
|
Carp::croak( "Usage: ->localize(cpan_file,as_local_file[,\$force])" ) |
316
|
|
|
|
|
|
|
unless defined $aslocal; |
317
|
3
|
50
|
|
|
|
9
|
if ($CPAN::DEBUG){ |
318
|
0
|
|
|
|
|
0
|
require Carp; |
319
|
0
|
|
|
|
|
0
|
my $longmess = Carp::longmess(); |
320
|
0
|
|
|
|
|
0
|
$self->debug("file[$file] aslocal[$aslocal] force[$force] carplongmess[$longmess]"); |
321
|
|
|
|
|
|
|
} |
322
|
3
|
50
|
|
|
|
12
|
if ($^O eq 'MacOS') { |
323
|
|
|
|
|
|
|
# Comment by AK on 2000-09-03: Uniq short filenames would be |
324
|
|
|
|
|
|
|
# available in CHECKSUMS file |
325
|
0
|
|
|
|
|
0
|
my($name, $path) = File::Basename::fileparse($aslocal, ''); |
326
|
0
|
0
|
|
|
|
0
|
if (length($name) > 31) { |
327
|
0
|
|
|
|
|
0
|
$name =~ s/( |
328
|
|
|
|
|
|
|
\.( |
329
|
|
|
|
|
|
|
readme(\.(gz|Z))? | |
330
|
|
|
|
|
|
|
(tar\.)?(gz|Z) | |
331
|
|
|
|
|
|
|
tgz | |
332
|
|
|
|
|
|
|
zip | |
333
|
|
|
|
|
|
|
pm\.(gz|Z) |
334
|
|
|
|
|
|
|
) |
335
|
|
|
|
|
|
|
)$//x; |
336
|
0
|
|
|
|
|
0
|
my $suf = $1; |
337
|
0
|
|
|
|
|
0
|
my $size = 31 - length($suf); |
338
|
0
|
|
|
|
|
0
|
while (length($name) > $size) { |
339
|
0
|
|
|
|
|
0
|
chop $name; |
340
|
|
|
|
|
|
|
} |
341
|
0
|
|
|
|
|
0
|
$name .= $suf; |
342
|
0
|
|
|
|
|
0
|
$aslocal = File::Spec->catfile($path, $name); |
343
|
|
|
|
|
|
|
} |
344
|
|
|
|
|
|
|
} |
345
|
|
|
|
|
|
|
|
346
|
3
|
0
|
33
|
|
|
26
|
if (-f $aslocal && -r _ && !($force & 1)) { |
|
|
|
33
|
|
|
|
|
347
|
0
|
|
|
|
|
0
|
my $size; |
348
|
0
|
0
|
|
|
|
0
|
if ($size = -s $aslocal) { |
349
|
0
|
0
|
|
|
|
0
|
$self->debug("aslocal[$aslocal]size[$size]") if $CPAN::DEBUG; |
350
|
0
|
|
|
|
|
0
|
return $aslocal; |
351
|
|
|
|
|
|
|
} else { |
352
|
|
|
|
|
|
|
# empty file from a previous unsuccessful attempt to download it |
353
|
0
|
0
|
|
|
|
0
|
unlink $aslocal or |
354
|
|
|
|
|
|
|
$CPAN::Frontend->mydie("Found a zero-length '$aslocal' that I ". |
355
|
|
|
|
|
|
|
"could not remove."); |
356
|
|
|
|
|
|
|
} |
357
|
|
|
|
|
|
|
} |
358
|
3
|
|
|
|
|
11
|
my($maybe_restore) = 0; |
359
|
3
|
50
|
|
|
|
25
|
if (-f $aslocal) { |
360
|
0
|
|
|
|
|
0
|
rename $aslocal, "$aslocal.bak$$"; |
361
|
0
|
|
|
|
|
0
|
$maybe_restore++; |
362
|
|
|
|
|
|
|
} |
363
|
|
|
|
|
|
|
|
364
|
3
|
|
|
|
|
190
|
my($aslocal_dir) = dirname($aslocal); |
365
|
|
|
|
|
|
|
# Inheritance is not easier to manage than a few if/else branches |
366
|
3
|
50
|
|
|
|
19
|
if ($CPAN::META->has_usable('LWP::UserAgent')) { |
367
|
0
|
0
|
|
|
|
0
|
unless ($Ua) { |
368
|
0
|
|
|
|
|
0
|
CPAN::LWP::UserAgent->config; |
369
|
0
|
|
|
|
|
0
|
eval {$Ua = CPAN::LWP::UserAgent->new;}; # Why is has_usable still not fit enough? |
|
0
|
|
|
|
|
0
|
|
370
|
0
|
0
|
|
|
|
0
|
if ($@) { |
371
|
0
|
0
|
|
|
|
0
|
$CPAN::Frontend->mywarn("CPAN::LWP::UserAgent->new dies with $@\n") |
372
|
|
|
|
|
|
|
if $CPAN::DEBUG; |
373
|
|
|
|
|
|
|
} else { |
374
|
0
|
|
|
|
|
0
|
my($var); |
375
|
|
|
|
|
|
|
$Ua->proxy('ftp', $var) |
376
|
0
|
0
|
0
|
|
|
0
|
if $var = $CPAN::Config->{ftp_proxy} || $ENV{ftp_proxy}; |
377
|
|
|
|
|
|
|
$Ua->proxy('http', $var) |
378
|
0
|
0
|
0
|
|
|
0
|
if $var = $CPAN::Config->{http_proxy} || $ENV{http_proxy}; |
379
|
|
|
|
|
|
|
$Ua->no_proxy($var) |
380
|
0
|
0
|
0
|
|
|
0
|
if $var = $CPAN::Config->{no_proxy} || $ENV{no_proxy}; |
381
|
|
|
|
|
|
|
} |
382
|
|
|
|
|
|
|
} |
383
|
|
|
|
|
|
|
} |
384
|
3
|
|
|
|
|
10
|
for my $prx (qw(ftp_proxy http_proxy no_proxy)) { |
385
|
9
|
50
|
|
|
|
21
|
$ENV{$prx} = $CPAN::Config->{$prx} if $CPAN::Config->{$prx}; |
386
|
|
|
|
|
|
|
} |
387
|
|
|
|
|
|
|
|
388
|
|
|
|
|
|
|
# Try the list of urls for each single object. We keep a record |
389
|
|
|
|
|
|
|
# where we did get a file from |
390
|
3
|
|
|
|
|
6
|
my(@reordered,$last); |
391
|
3
|
|
|
|
|
18
|
my $ccurllist = $self->_get_urllist($with_defaults); |
392
|
3
|
|
|
|
|
6
|
$last = $#$ccurllist; |
393
|
3
|
50
|
|
|
|
12
|
if ($force & 2) { # local cpans probably out of date, don't reorder |
394
|
3
|
|
|
|
|
13
|
@reordered = (0..$last); |
395
|
|
|
|
|
|
|
} else { |
396
|
|
|
|
|
|
|
@reordered = |
397
|
|
|
|
|
|
|
sort { |
398
|
0
|
0
|
0
|
|
|
0
|
(substr($ccurllist->[$b],0,4) eq "file") |
|
0
|
|
|
|
|
0
|
|
399
|
|
|
|
|
|
|
<=> |
400
|
|
|
|
|
|
|
(substr($ccurllist->[$a],0,4) eq "file") |
401
|
|
|
|
|
|
|
or |
402
|
|
|
|
|
|
|
defined($ThesiteURL) |
403
|
|
|
|
|
|
|
and |
404
|
|
|
|
|
|
|
($ccurllist->[$b] eq $ThesiteURL) |
405
|
|
|
|
|
|
|
<=> |
406
|
|
|
|
|
|
|
($ccurllist->[$a] eq $ThesiteURL) |
407
|
|
|
|
|
|
|
} 0..$last; |
408
|
|
|
|
|
|
|
} |
409
|
3
|
|
|
|
|
5
|
my(@levels); |
410
|
3
|
|
100
|
|
|
15
|
$Themethod ||= ""; |
411
|
3
|
50
|
|
|
|
11
|
$self->debug("Themethod[$Themethod]reordered[@reordered]") if $CPAN::DEBUG; |
412
|
3
|
|
|
|
|
35
|
my @all_levels = ( |
413
|
|
|
|
|
|
|
["dleasy", "file"], |
414
|
|
|
|
|
|
|
["dleasy"], |
415
|
|
|
|
|
|
|
["dlhard"], |
416
|
|
|
|
|
|
|
["dlhardest"], |
417
|
|
|
|
|
|
|
["dleasy", "http","defaultsites"], |
418
|
|
|
|
|
|
|
["dlhard", "http","defaultsites"], |
419
|
|
|
|
|
|
|
["dleasy", "ftp", "defaultsites"], |
420
|
|
|
|
|
|
|
["dlhard", "ftp", "defaultsites"], |
421
|
|
|
|
|
|
|
["dlhardest","", "defaultsites"], |
422
|
|
|
|
|
|
|
); |
423
|
3
|
100
|
|
|
|
8
|
if ($Themethod) { |
424
|
2
|
|
|
|
|
3
|
@levels = grep {$_->[0] eq $Themethod} @all_levels; |
|
18
|
|
|
|
|
27
|
|
425
|
2
|
|
|
|
|
4
|
push @levels, grep {$_->[0] ne $Themethod} @all_levels; |
|
18
|
|
|
|
|
51
|
|
426
|
|
|
|
|
|
|
} else { |
427
|
1
|
|
|
|
|
2
|
@levels = @all_levels; |
428
|
|
|
|
|
|
|
} |
429
|
3
|
50
|
|
|
|
11
|
@levels = qw/dleasy/ if $^O eq 'MacOS'; |
430
|
3
|
|
|
|
|
19
|
my($levelno); |
431
|
|
|
|
|
|
|
local $ENV{FTP_PASSIVE} = |
432
|
|
|
|
|
|
|
exists $CPAN::Config->{ftp_passive} ? |
433
|
3
|
50
|
|
|
|
55
|
$CPAN::Config->{ftp_passive} : 1; |
434
|
3
|
|
|
|
|
7
|
my $ret; |
435
|
3
|
|
|
|
|
17
|
my $stats = $self->_new_stats($file); |
436
|
3
|
|
|
|
|
13
|
for ($CPAN::Config->{connect_to_internet_ok}) { |
437
|
3
|
50
|
33
|
|
|
20
|
$connect_to_internet_ok = $_ if not defined $connect_to_internet_ok and defined $_; |
438
|
|
|
|
|
|
|
} |
439
|
3
|
|
|
|
|
10
|
LEVEL: for $levelno (0..$#levels) { |
440
|
3
|
|
|
|
|
8
|
my $level_tuple = $levels[$levelno]; |
441
|
3
|
|
|
|
|
8
|
my($level,$scheme,$sitetag) = @$level_tuple; |
442
|
3
|
50
|
33
|
|
|
15
|
$self->mymkpath($aslocal_dir) unless $scheme && "file" eq $scheme; |
443
|
3
|
|
33
|
|
|
9
|
my $defaultsites = $sitetag && $sitetag eq "defaultsites" && !@$ccurllist; |
444
|
3
|
|
|
|
|
5
|
my @urllist; |
445
|
3
|
50
|
|
|
|
6
|
if ($defaultsites) { |
446
|
0
|
0
|
|
|
|
0
|
unless (defined $connect_to_internet_ok) { |
447
|
|
|
|
|
|
|
$CPAN::Frontend->myprint(sprintf qq{ |
448
|
|
|
|
|
|
|
I would like to connect to one of the following sites to get '%s': |
449
|
|
|
|
|
|
|
|
450
|
|
|
|
|
|
|
%s |
451
|
|
|
|
|
|
|
}, |
452
|
|
|
|
|
|
|
$file, |
453
|
0
|
|
|
|
|
0
|
join("",map { " ".$_->text."\n" } @CPAN::Defaultsites), |
|
0
|
|
|
|
|
0
|
|
454
|
|
|
|
|
|
|
); |
455
|
0
|
|
|
|
|
0
|
my $answer = CPAN::Shell::colorable_makemaker_prompt("Is it OK to try to connect to the Internet?", "yes"); |
456
|
0
|
0
|
|
|
|
0
|
if ($answer =~ /^y/i) { |
457
|
0
|
|
|
|
|
0
|
$connect_to_internet_ok = 1; |
458
|
|
|
|
|
|
|
} else { |
459
|
0
|
|
|
|
|
0
|
$connect_to_internet_ok = 0; |
460
|
|
|
|
|
|
|
} |
461
|
|
|
|
|
|
|
} |
462
|
0
|
0
|
|
|
|
0
|
if ($connect_to_internet_ok) { |
463
|
0
|
|
|
|
|
0
|
@urllist = @CPAN::Defaultsites; |
464
|
|
|
|
|
|
|
} else { |
465
|
0
|
|
|
|
|
0
|
my $sleep = 2; |
466
|
|
|
|
|
|
|
# the tricky thing about dying here is that everybody |
467
|
|
|
|
|
|
|
# believes that calls to exists() or all_objects() are |
468
|
|
|
|
|
|
|
# safe. |
469
|
0
|
|
|
|
|
0
|
require CPAN::Exception::blocked_urllist; |
470
|
0
|
|
|
|
|
0
|
die CPAN::Exception::blocked_urllist->new; |
471
|
|
|
|
|
|
|
} |
472
|
|
|
|
|
|
|
} else { # ! $defaultsites |
473
|
3
|
50
|
|
|
|
21
|
my @host_seq = $level =~ /dleasy/ ? |
474
|
|
|
|
|
|
|
@reordered : 0..$last; # reordered has file and $Thesiteurl first |
475
|
3
|
|
|
|
|
7
|
@urllist = map { $ccurllist->[$_] } @host_seq; |
|
3
|
|
|
|
|
10
|
|
476
|
|
|
|
|
|
|
} |
477
|
3
|
50
|
|
|
|
12
|
$self->debug("synth. urllist[@urllist]") if $CPAN::DEBUG; |
478
|
3
|
|
|
|
|
12
|
my $aslocal_tempfile = $aslocal . ".tmp" . $$; |
479
|
3
|
50
|
|
|
|
15
|
if (my $recommend = $self->_recommend_url_for($file,\@urllist)) { |
480
|
0
|
|
|
|
|
0
|
@urllist = grep { $_ ne $recommend } @urllist; |
|
0
|
|
|
|
|
0
|
|
481
|
0
|
|
|
|
|
0
|
unshift @urllist, $recommend; |
482
|
|
|
|
|
|
|
} |
483
|
3
|
50
|
|
|
|
7
|
$self->debug("synth. urllist[@urllist]") if $CPAN::DEBUG; |
484
|
3
|
|
|
|
|
15
|
$ret = $self->hostdlxxx($level,$scheme,\@urllist,$file,$aslocal_tempfile,$stats); |
485
|
3
|
50
|
|
|
|
9
|
if ($ret) { |
486
|
3
|
50
|
|
|
|
6
|
CPAN->debug("ret[$ret]aslocal[$aslocal]") if $CPAN::DEBUG; |
487
|
3
|
50
|
33
|
|
|
51
|
if ($ret eq $aslocal_tempfile) { |
|
|
50
|
|
|
|
|
|
488
|
|
|
|
|
|
|
# if we got it exactly as we asked for, only then we |
489
|
|
|
|
|
|
|
# want to rename |
490
|
0
|
0
|
|
|
|
0
|
rename $aslocal_tempfile, $aslocal |
491
|
|
|
|
|
|
|
or $CPAN::Frontend->mydie("Error while trying to rename ". |
492
|
|
|
|
|
|
|
"'$ret' to '$aslocal': $!"); |
493
|
0
|
|
|
|
|
0
|
$ret = $aslocal; |
494
|
|
|
|
|
|
|
} |
495
|
|
|
|
|
|
|
elsif (-f $ret && $scheme eq 'file' ) { |
496
|
|
|
|
|
|
|
# it's a local file, so there's nothing left to do, we |
497
|
|
|
|
|
|
|
# let them read from where it is |
498
|
|
|
|
|
|
|
} |
499
|
3
|
|
|
|
|
7
|
$Themethod = $level; |
500
|
3
|
|
|
|
|
6
|
my $now = time; |
501
|
|
|
|
|
|
|
# utime $now, $now, $aslocal; # too bad, if we do that, we |
502
|
|
|
|
|
|
|
# might alter a local mirror |
503
|
3
|
50
|
|
|
|
5
|
$self->debug("level[$level]") if $CPAN::DEBUG; |
504
|
3
|
|
|
|
|
11
|
last LEVEL; |
505
|
|
|
|
|
|
|
} else { |
506
|
0
|
|
|
|
|
0
|
unlink $aslocal_tempfile; |
507
|
0
|
0
|
|
|
|
0
|
last if $CPAN::Signal; # need to cleanup |
508
|
|
|
|
|
|
|
} |
509
|
|
|
|
|
|
|
} |
510
|
3
|
50
|
|
|
|
6
|
if ($ret) { |
511
|
3
|
|
|
|
|
36
|
$stats->{filesize} = -s $ret; |
512
|
|
|
|
|
|
|
} |
513
|
3
|
50
|
|
|
|
10
|
$self->debug("before _add_to_statistics") if $CPAN::DEBUG; |
514
|
3
|
|
|
|
|
17
|
$self->_add_to_statistics($stats); |
515
|
3
|
50
|
|
|
|
7
|
$self->debug("after _add_to_statistics") if $CPAN::DEBUG; |
516
|
3
|
50
|
|
|
|
8
|
if ($ret) { |
517
|
3
|
|
|
|
|
30
|
unlink "$aslocal.bak$$"; |
518
|
3
|
|
|
|
|
46
|
return $ret; |
519
|
|
|
|
|
|
|
} |
520
|
0
|
0
|
|
|
|
0
|
unless ($CPAN::Signal) { |
521
|
0
|
|
|
|
|
0
|
my(@mess); |
522
|
0
|
|
|
|
|
0
|
local $" = " "; |
523
|
0
|
0
|
|
|
|
0
|
if (@{$CPAN::Config->{urllist}}) { |
|
0
|
|
|
|
|
0
|
|
524
|
|
|
|
|
|
|
push @mess, |
525
|
|
|
|
|
|
|
qq{Please check, if the URLs I found in your configuration file \(}. |
526
|
0
|
|
|
|
|
0
|
join(", ", @{$CPAN::Config->{urllist}}). |
|
0
|
|
|
|
|
0
|
|
527
|
|
|
|
|
|
|
qq{\) are valid.}; |
528
|
|
|
|
|
|
|
} else { |
529
|
0
|
|
|
|
|
0
|
push @mess, qq{Your urllist is empty!}; |
530
|
|
|
|
|
|
|
} |
531
|
0
|
|
|
|
|
0
|
push @mess, qq{The urllist can be edited.}, |
532
|
|
|
|
|
|
|
qq{E.g. with 'o conf urllist push ftp://myurl/'}; |
533
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->mywarn(Text::Wrap::wrap("","","@mess"). "\n\n"); |
534
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->mydie("Could not fetch $file\n"); |
535
|
|
|
|
|
|
|
} |
536
|
0
|
0
|
|
|
|
0
|
if ($maybe_restore) { |
537
|
0
|
|
|
|
|
0
|
rename "$aslocal.bak$$", $aslocal; |
538
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->myprint("Trying to get away with old file:\n" . |
539
|
|
|
|
|
|
|
$self->ls($aslocal) . "\n"); |
540
|
0
|
|
|
|
|
0
|
return $aslocal; |
541
|
|
|
|
|
|
|
} |
542
|
0
|
|
|
|
|
0
|
return; |
543
|
|
|
|
|
|
|
} |
544
|
|
|
|
|
|
|
|
545
|
|
|
|
|
|
|
sub mymkpath { |
546
|
0
|
|
|
0
|
0
|
0
|
my($self, $aslocal_dir) = @_; |
547
|
0
|
|
|
|
|
0
|
mkpath($aslocal_dir); |
548
|
0
|
0
|
|
|
|
0
|
$CPAN::Frontend->mywarn(qq{Warning: You are not allowed to write into }. |
549
|
|
|
|
|
|
|
qq{directory "$aslocal_dir". |
550
|
|
|
|
|
|
|
I\'ll continue, but if you encounter problems, they may be due |
551
|
|
|
|
|
|
|
to insufficient permissions.\n}) unless -w $aslocal_dir; |
552
|
|
|
|
|
|
|
} |
553
|
|
|
|
|
|
|
|
554
|
|
|
|
|
|
|
sub hostdlxxx { |
555
|
3
|
|
|
3
|
0
|
5
|
my $self = shift; |
556
|
3
|
|
|
|
|
5
|
my $level = shift; |
557
|
3
|
|
|
|
|
4
|
my $scheme = shift; |
558
|
3
|
|
|
|
|
4
|
my $h = shift; |
559
|
3
|
50
|
|
|
|
57
|
$h = [ grep /^\Q$scheme\E:/, @$h ] if $scheme; |
560
|
3
|
|
|
|
|
7
|
my $method = "host$level"; |
561
|
3
|
|
|
|
|
17
|
$self->$method($h, @_); |
562
|
|
|
|
|
|
|
} |
563
|
|
|
|
|
|
|
|
564
|
|
|
|
|
|
|
sub _set_attempt { |
565
|
3
|
|
|
3
|
|
9
|
my($self,$stats,$method,$url) = @_; |
566
|
3
|
|
|
|
|
4
|
push @{$stats->{attempts}}, { |
|
3
|
|
|
|
|
10
|
|
567
|
|
|
|
|
|
|
method => $method, |
568
|
|
|
|
|
|
|
start => _mytime, |
569
|
|
|
|
|
|
|
url => $url, |
570
|
|
|
|
|
|
|
}; |
571
|
|
|
|
|
|
|
} |
572
|
|
|
|
|
|
|
|
573
|
|
|
|
|
|
|
# package CPAN::FTP; |
574
|
|
|
|
|
|
|
sub hostdleasy { #called from hostdlxxx |
575
|
3
|
|
|
3
|
0
|
12
|
my($self,$host_seq,$file,$aslocal,$stats) = @_; |
576
|
3
|
|
|
|
|
8
|
my($ro_url); |
577
|
3
|
|
|
|
|
13
|
HOSTEASY: for $ro_url (@$host_seq) { |
578
|
3
|
|
|
|
|
10
|
$self->_set_attempt($stats,"dleasy",$ro_url); |
579
|
3
|
|
|
|
|
10
|
my $url = "$ro_url$file"; |
580
|
3
|
50
|
|
|
|
10
|
$self->debug("localizing perlish[$url]") if $CPAN::DEBUG; |
581
|
3
|
50
|
|
|
|
15
|
if ($url =~ /^file:/) { |
582
|
3
|
|
|
|
|
4
|
my $l; |
583
|
3
|
50
|
|
|
|
8
|
if ($CPAN::META->has_inst('URI::URL')) { |
584
|
3
|
|
|
|
|
15
|
my $u = URI::URL->new($url); |
585
|
3
|
|
|
|
|
5284
|
$l = $u->file; |
586
|
|
|
|
|
|
|
} else { # works only on Unix, is poorly constructed, but |
587
|
|
|
|
|
|
|
# hopefully better than nothing. |
588
|
|
|
|
|
|
|
# RFC 1738 says fileurl BNF is |
589
|
|
|
|
|
|
|
# fileurl = "file://" [ host | "localhost" ] "/" fpath |
590
|
|
|
|
|
|
|
# Thanks to "Mark D. Baushke" for |
591
|
|
|
|
|
|
|
# the code |
592
|
0
|
|
|
|
|
0
|
($l = $url) =~ s|^file://[^/]*/|/|; # discard the host part |
593
|
0
|
|
|
|
|
0
|
$l =~ s|^file:||; # assume they |
594
|
|
|
|
|
|
|
# meant |
595
|
|
|
|
|
|
|
# file://localhost |
596
|
0
|
0
|
0
|
|
|
0
|
$l =~ s|^/||s |
597
|
|
|
|
|
|
|
if ! -f $l && $l =~ m|^/\w:|; # e.g. /P: |
598
|
|
|
|
|
|
|
} |
599
|
3
|
50
|
|
|
|
2286
|
$self->debug("local file[$l]") if $CPAN::DEBUG; |
600
|
3
|
50
|
33
|
|
|
84
|
if ( -f $l && -r _) { |
601
|
0
|
|
|
|
|
0
|
$ThesiteURL = $ro_url; |
602
|
0
|
|
|
|
|
0
|
return $l; |
603
|
|
|
|
|
|
|
} |
604
|
|
|
|
|
|
|
# If request is for a compressed file and we can find the |
605
|
|
|
|
|
|
|
# uncompressed file also, return the path of the uncompressed file |
606
|
|
|
|
|
|
|
# otherwise, decompress it and return the resulting path |
607
|
3
|
50
|
0
|
|
|
27
|
if ($l =~ /(.+)\.gz$/) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
608
|
3
|
|
|
|
|
10
|
my $ungz = $1; |
609
|
3
|
50
|
33
|
|
|
62
|
if ( -f $ungz && -r _) { |
|
|
0
|
0
|
|
|
|
|
610
|
3
|
|
|
|
|
9
|
$ThesiteURL = $ro_url; |
611
|
3
|
|
|
|
|
29
|
return $ungz; |
612
|
|
|
|
|
|
|
} |
613
|
|
|
|
|
|
|
elsif (-f $l && -r _) { |
614
|
0
|
|
|
|
|
0
|
eval { CPAN::Tarzip->new($l)->gunzip($aslocal) }; |
|
0
|
|
|
|
|
0
|
|
615
|
0
|
0
|
0
|
|
|
0
|
if ( -f $aslocal && -s _) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
616
|
0
|
|
|
|
|
0
|
$ThesiteURL = $ro_url; |
617
|
0
|
|
|
|
|
0
|
return $aslocal; |
618
|
|
|
|
|
|
|
} |
619
|
|
|
|
|
|
|
elsif (! -s $aslocal) { |
620
|
0
|
|
|
|
|
0
|
unlink $aslocal; |
621
|
|
|
|
|
|
|
} |
622
|
|
|
|
|
|
|
elsif (-f $l) { |
623
|
0
|
0
|
|
|
|
0
|
$CPAN::Frontend->mywarn("Error decompressing '$l': $@\n") |
624
|
|
|
|
|
|
|
if $@; |
625
|
0
|
|
|
|
|
0
|
return; |
626
|
|
|
|
|
|
|
} |
627
|
|
|
|
|
|
|
} |
628
|
|
|
|
|
|
|
} |
629
|
|
|
|
|
|
|
# Otherwise, return the local file path if it exists |
630
|
|
|
|
|
|
|
elsif ( -f $l && -r _) { |
631
|
0
|
|
|
|
|
0
|
$ThesiteURL = $ro_url; |
632
|
0
|
|
|
|
|
0
|
return $l; |
633
|
|
|
|
|
|
|
} |
634
|
|
|
|
|
|
|
# If we can't find it, but there is a compressed version |
635
|
|
|
|
|
|
|
# of it, then decompress it |
636
|
|
|
|
|
|
|
elsif (-f "$l.gz") { |
637
|
0
|
0
|
|
|
|
0
|
$self->debug("found compressed $l.gz") if $CPAN::DEBUG; |
638
|
0
|
|
|
|
|
0
|
eval { CPAN::Tarzip->new("$l.gz")->gunzip($aslocal) }; |
|
0
|
|
|
|
|
0
|
|
639
|
0
|
0
|
|
|
|
0
|
if ( -f $aslocal) { |
640
|
0
|
|
|
|
|
0
|
$ThesiteURL = $ro_url; |
641
|
0
|
|
|
|
|
0
|
return $aslocal; |
642
|
|
|
|
|
|
|
} |
643
|
|
|
|
|
|
|
else { |
644
|
0
|
0
|
|
|
|
0
|
$CPAN::Frontend->mywarn("Error decompressing '$l': $@\n") |
645
|
|
|
|
|
|
|
if $@; |
646
|
0
|
|
|
|
|
0
|
return; |
647
|
|
|
|
|
|
|
} |
648
|
|
|
|
|
|
|
} |
649
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->mywarn("Could not find '$l'\n"); |
650
|
|
|
|
|
|
|
} |
651
|
0
|
0
|
|
|
|
0
|
$self->debug("it was not a file URL") if $CPAN::DEBUG; |
652
|
0
|
0
|
0
|
|
|
0
|
if ($CPAN::META->has_usable('LWP')) { |
|
|
0
|
|
|
|
|
|
653
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->myprint("Fetching with LWP:\n$url\n"); |
654
|
0
|
0
|
|
|
|
0
|
unless ($Ua) { |
655
|
0
|
|
|
|
|
0
|
CPAN::LWP::UserAgent->config; |
656
|
0
|
|
|
|
|
0
|
eval { $Ua = CPAN::LWP::UserAgent->new; }; |
|
0
|
|
|
|
|
0
|
|
657
|
0
|
0
|
|
|
|
0
|
if ($@) { |
658
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->mywarn("CPAN::LWP::UserAgent->new dies with $@\n"); |
659
|
|
|
|
|
|
|
} |
660
|
|
|
|
|
|
|
} |
661
|
0
|
|
|
|
|
0
|
my $res = $Ua->mirror($url, $aslocal); |
662
|
0
|
0
|
|
|
|
0
|
if ($res->is_success) { |
|
|
0
|
|
|
|
|
|
663
|
0
|
|
|
|
|
0
|
$ThesiteURL = $ro_url; |
664
|
0
|
|
|
|
|
0
|
my $now = time; |
665
|
0
|
|
|
|
|
0
|
utime $now, $now, $aslocal; # download time is more |
666
|
|
|
|
|
|
|
# important than upload |
667
|
|
|
|
|
|
|
# time |
668
|
0
|
|
|
|
|
0
|
return $aslocal; |
669
|
|
|
|
|
|
|
} elsif ($url !~ /\.gz(?!\n)\Z/) { |
670
|
0
|
|
|
|
|
0
|
my $gzurl = "$url.gz"; |
671
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->myprint("Fetching with LWP:\n$gzurl\n"); |
672
|
0
|
|
|
|
|
0
|
$res = $Ua->mirror($gzurl, "$aslocal.gz"); |
673
|
0
|
0
|
|
|
|
0
|
if ($res->is_success) { |
674
|
0
|
0
|
|
|
|
0
|
if (eval {CPAN::Tarzip->new("$aslocal.gz")->gunzip($aslocal)}) { |
|
0
|
|
|
|
|
0
|
|
675
|
0
|
|
|
|
|
0
|
$ThesiteURL = $ro_url; |
676
|
0
|
|
|
|
|
0
|
return $aslocal; |
677
|
|
|
|
|
|
|
} |
678
|
|
|
|
|
|
|
} |
679
|
|
|
|
|
|
|
} else { |
680
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->myprint(sprintf( |
681
|
|
|
|
|
|
|
"LWP failed with code[%s] message[%s]\n", |
682
|
|
|
|
|
|
|
$res->code, |
683
|
|
|
|
|
|
|
$res->message, |
684
|
|
|
|
|
|
|
)); |
685
|
|
|
|
|
|
|
# Alan Burlison informed me that in firewall environments |
686
|
|
|
|
|
|
|
# Net::FTP can still succeed where LWP fails. So we do not |
687
|
|
|
|
|
|
|
# skip Net::FTP anymore when LWP is available. |
688
|
|
|
|
|
|
|
} |
689
|
|
|
|
|
|
|
} elsif ($url =~ /^http:/i && $CPAN::META->has_usable('HTTP::Tiny')) { |
690
|
0
|
|
|
|
|
0
|
require CPAN::HTTP::Client; |
691
|
|
|
|
|
|
|
my $chc = CPAN::HTTP::Client->new( |
692
|
|
|
|
|
|
|
proxy => $CPAN::Config->{http_proxy} || $ENV{http_proxy}, |
693
|
|
|
|
|
|
|
no_proxy => $CPAN::Config->{no_proxy} || $ENV{no_proxy}, |
694
|
0
|
|
0
|
|
|
0
|
); |
|
|
|
0
|
|
|
|
|
695
|
0
|
0
|
|
|
|
0
|
for my $try ( $url, ( $url !~ /\.gz(?!\n)\Z/ ? "$url.gz" : () ) ) { |
696
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->myprint("Fetching with HTTP::Tiny:\n$try\n"); |
697
|
0
|
|
|
|
|
0
|
my $res = eval { $chc->mirror($try, $aslocal) }; |
|
0
|
|
|
|
|
0
|
|
698
|
0
|
0
|
0
|
|
|
0
|
if ( $res && $res->{success} ) { |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
699
|
0
|
|
|
|
|
0
|
$ThesiteURL = $ro_url; |
700
|
0
|
|
|
|
|
0
|
my $now = time; |
701
|
0
|
|
|
|
|
0
|
utime $now, $now, $aslocal; # download time is more |
702
|
|
|
|
|
|
|
# important than upload |
703
|
|
|
|
|
|
|
# time |
704
|
0
|
|
|
|
|
0
|
return $aslocal; |
705
|
|
|
|
|
|
|
} |
706
|
|
|
|
|
|
|
elsif ( $res && $res->{status} ne '599') { |
707
|
|
|
|
|
|
|
$CPAN::Frontend->myprint(sprintf( |
708
|
|
|
|
|
|
|
"HTTP::Tiny failed with code[%s] message[%s]\n", |
709
|
|
|
|
|
|
|
$res->{status}, |
710
|
|
|
|
|
|
|
$res->{reason}, |
711
|
|
|
|
|
|
|
) |
712
|
0
|
|
|
|
|
0
|
); |
713
|
|
|
|
|
|
|
} |
714
|
|
|
|
|
|
|
elsif ( $res && $res->{status} eq '599') { |
715
|
|
|
|
|
|
|
$CPAN::Frontend->myprint(sprintf( |
716
|
|
|
|
|
|
|
"HTTP::Tiny failed with an internal error: %s\n", |
717
|
|
|
|
|
|
|
$res->{content}, |
718
|
|
|
|
|
|
|
) |
719
|
0
|
|
|
|
|
0
|
); |
720
|
|
|
|
|
|
|
} |
721
|
|
|
|
|
|
|
else { |
722
|
0
|
|
0
|
|
|
0
|
my $err = $@ || 'Unknown error'; |
723
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->myprint(sprintf( |
724
|
|
|
|
|
|
|
"Error downloading with HTTP::Tiny: %s\n", $err |
725
|
|
|
|
|
|
|
) |
726
|
|
|
|
|
|
|
); |
727
|
|
|
|
|
|
|
} |
728
|
|
|
|
|
|
|
} |
729
|
|
|
|
|
|
|
} |
730
|
0
|
0
|
|
|
|
0
|
return if $CPAN::Signal; |
731
|
0
|
0
|
|
|
|
0
|
if ($url =~ m|^ftp://(.*?)/(.*)/(.*)|) { |
732
|
|
|
|
|
|
|
# that's the nice and easy way thanks to Graham |
733
|
0
|
0
|
|
|
|
0
|
$self->debug("recognized ftp") if $CPAN::DEBUG; |
734
|
0
|
|
|
|
|
0
|
my($host,$dir,$getfile) = ($1,$2,$3); |
735
|
0
|
0
|
|
|
|
0
|
if ($CPAN::META->has_usable('Net::FTP')) { |
736
|
0
|
|
|
|
|
0
|
$dir =~ s|/+|/|g; |
737
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->myprint("Fetching with Net::FTP:\n$url\n"); |
738
|
0
|
0
|
|
|
|
0
|
$self->debug("getfile[$getfile]dir[$dir]host[$host]" . |
739
|
|
|
|
|
|
|
"aslocal[$aslocal]") if $CPAN::DEBUG; |
740
|
0
|
0
|
|
|
|
0
|
if (CPAN::FTP->ftp_get($host,$dir,$getfile,$aslocal)) { |
741
|
0
|
|
|
|
|
0
|
$ThesiteURL = $ro_url; |
742
|
0
|
|
|
|
|
0
|
return $aslocal; |
743
|
|
|
|
|
|
|
} |
744
|
0
|
0
|
|
|
|
0
|
if ($aslocal !~ /\.gz(?!\n)\Z/) { |
745
|
0
|
|
|
|
|
0
|
my $gz = "$aslocal.gz"; |
746
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->myprint("Fetching with Net::FTP\n$url.gz\n"); |
747
|
0
|
0
|
0
|
|
|
0
|
if (CPAN::FTP->ftp_get($host, |
748
|
|
|
|
|
|
|
$dir, |
749
|
|
|
|
|
|
|
"$getfile.gz", |
750
|
|
|
|
|
|
|
$gz) && |
751
|
0
|
|
|
|
|
0
|
eval{CPAN::Tarzip->new($gz)->gunzip($aslocal)} |
752
|
|
|
|
|
|
|
) { |
753
|
0
|
|
|
|
|
0
|
$ThesiteURL = $ro_url; |
754
|
0
|
|
|
|
|
0
|
return $aslocal; |
755
|
|
|
|
|
|
|
} |
756
|
|
|
|
|
|
|
} |
757
|
|
|
|
|
|
|
# next HOSTEASY; |
758
|
|
|
|
|
|
|
} else { |
759
|
0
|
0
|
|
|
|
0
|
CPAN->debug("Net::FTP does not count as usable atm") if $CPAN::DEBUG; |
760
|
|
|
|
|
|
|
} |
761
|
|
|
|
|
|
|
} |
762
|
0
|
0
|
0
|
|
|
0
|
if ( |
763
|
|
|
|
|
|
|
UNIVERSAL::can($ro_url,"text") |
764
|
|
|
|
|
|
|
and |
765
|
|
|
|
|
|
|
$ro_url->{FROM} eq "USER" |
766
|
|
|
|
|
|
|
) { |
767
|
|
|
|
|
|
|
##address #17973: default URLs should not try to override |
768
|
|
|
|
|
|
|
##user-defined URLs just because LWP is not available |
769
|
0
|
|
|
|
|
0
|
my $ret = $self->hostdlhard([$ro_url],$file,$aslocal,$stats); |
770
|
0
|
0
|
|
|
|
0
|
return $ret if $ret; |
771
|
|
|
|
|
|
|
} |
772
|
0
|
0
|
|
|
|
0
|
return if $CPAN::Signal; |
773
|
|
|
|
|
|
|
} |
774
|
|
|
|
|
|
|
} |
775
|
|
|
|
|
|
|
|
776
|
|
|
|
|
|
|
# package CPAN::FTP; |
777
|
|
|
|
|
|
|
sub hostdlhard { |
778
|
0
|
|
|
0
|
0
|
0
|
my($self,$host_seq,$file,$aslocal,$stats) = @_; |
779
|
|
|
|
|
|
|
|
780
|
|
|
|
|
|
|
# Came back if Net::FTP couldn't establish connection (or |
781
|
|
|
|
|
|
|
# failed otherwise) Maybe they are behind a firewall, but they |
782
|
|
|
|
|
|
|
# gave us a socksified (or other) ftp program... |
783
|
|
|
|
|
|
|
|
784
|
0
|
|
|
|
|
0
|
my($ro_url); |
785
|
0
|
|
0
|
|
|
0
|
my($devnull) = $CPAN::Config->{devnull} || ""; |
786
|
|
|
|
|
|
|
# < /dev/null "; |
787
|
0
|
|
|
|
|
0
|
my($aslocal_dir) = dirname($aslocal); |
788
|
0
|
|
|
|
|
0
|
mkpath($aslocal_dir); |
789
|
0
|
|
|
|
|
0
|
my $some_dl_success = 0; |
790
|
0
|
|
|
|
|
0
|
my $any_attempt = 0; |
791
|
0
|
|
|
|
|
0
|
HOSTHARD: for $ro_url (@$host_seq) { |
792
|
0
|
|
|
|
|
0
|
$self->_set_attempt($stats,"dlhard",$ro_url); |
793
|
0
|
|
|
|
|
0
|
my $url = "$ro_url$file"; |
794
|
0
|
|
|
|
|
0
|
my($proto,$host,$dir,$getfile); |
795
|
|
|
|
|
|
|
|
796
|
|
|
|
|
|
|
# Courtesy Mark Conty mark_conty@cargill.com change from |
797
|
|
|
|
|
|
|
# if ($url =~ m|^ftp://(.*?)/(.*)/(.*)|) { |
798
|
|
|
|
|
|
|
# to |
799
|
0
|
0
|
|
|
|
0
|
if ($url =~ m|^([^:]+)://(.*?)/(.*)/(.*)|) { |
800
|
|
|
|
|
|
|
# proto not yet used |
801
|
0
|
|
|
|
|
0
|
($proto,$host,$dir,$getfile) = ($1,$2,$3,$4); |
802
|
|
|
|
|
|
|
} else { |
803
|
0
|
|
|
|
|
0
|
next HOSTHARD; # who said, we could ftp anything except ftp? |
804
|
|
|
|
|
|
|
} |
805
|
0
|
0
|
|
|
|
0
|
next HOSTHARD if $proto eq "file"; # file URLs would have had |
806
|
|
|
|
|
|
|
# success above. Likely a bogus URL |
807
|
|
|
|
|
|
|
|
808
|
|
|
|
|
|
|
# making at least one attempt against a host |
809
|
0
|
|
|
|
|
0
|
$any_attempt++; |
810
|
|
|
|
|
|
|
|
811
|
0
|
0
|
|
|
|
0
|
$self->debug("localizing funkyftpwise[$url]") if $CPAN::DEBUG; |
812
|
|
|
|
|
|
|
|
813
|
|
|
|
|
|
|
# Try the most capable first and leave ncftp* for last as it only |
814
|
|
|
|
|
|
|
# does FTP. |
815
|
0
|
|
|
|
|
0
|
my $proxy_vars = $self->_proxy_vars($ro_url); |
816
|
0
|
|
|
|
|
0
|
DLPRG: for my $f (qw(curl wget lynx ncftpget ncftp)) { |
817
|
0
|
|
|
|
|
0
|
my $funkyftp = CPAN::HandleConfig->safe_quote($CPAN::Config->{$f}); |
818
|
0
|
0
|
|
|
|
0
|
next DLPRG unless defined $funkyftp; |
819
|
0
|
0
|
|
|
|
0
|
next DLPRG if $funkyftp =~ /^\s*$/; |
820
|
|
|
|
|
|
|
|
821
|
0
|
|
|
|
|
0
|
my($src_switch) = ""; |
822
|
0
|
|
|
|
|
0
|
my($chdir) = ""; |
823
|
0
|
|
|
|
|
0
|
my($stdout_redir) = " > \"$aslocal\""; |
824
|
0
|
0
|
|
|
|
0
|
if ($f eq "lynx") { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
825
|
0
|
|
|
|
|
0
|
$src_switch = " -source"; |
826
|
|
|
|
|
|
|
} elsif ($f eq "ncftp") { |
827
|
0
|
0
|
|
|
|
0
|
next DLPRG unless $url =~ m{\Aftp://}; |
828
|
0
|
|
|
|
|
0
|
$src_switch = " -c"; |
829
|
|
|
|
|
|
|
} elsif ($f eq "wget") { |
830
|
0
|
|
|
|
|
0
|
$src_switch = " -O \"$aslocal\""; |
831
|
0
|
|
|
|
|
0
|
$stdout_redir = ""; |
832
|
|
|
|
|
|
|
} elsif ($f eq 'curl') { |
833
|
0
|
|
|
|
|
0
|
$src_switch = ' -L -f -s -S --netrc-optional'; |
834
|
0
|
0
|
|
|
|
0
|
if ($proxy_vars->{http_proxy}) { |
835
|
0
|
|
|
|
|
0
|
$src_switch .= qq{ -U "$proxy_vars->{proxy_user}:$proxy_vars->{proxy_pass}" -x "$proxy_vars->{http_proxy}"}; |
836
|
|
|
|
|
|
|
} |
837
|
|
|
|
|
|
|
} elsif ($f eq "ncftpget") { |
838
|
0
|
0
|
|
|
|
0
|
next DLPRG unless $url =~ m{\Aftp://}; |
839
|
0
|
|
|
|
|
0
|
$chdir = "cd $aslocal_dir && "; |
840
|
0
|
|
|
|
|
0
|
$stdout_redir = ""; |
841
|
|
|
|
|
|
|
} |
842
|
|
|
|
|
|
|
$CPAN::Frontend->myprint( |
843
|
0
|
|
|
|
|
0
|
qq[ |
844
|
|
|
|
|
|
|
Trying with |
845
|
|
|
|
|
|
|
$funkyftp$src_switch |
846
|
|
|
|
|
|
|
to get |
847
|
|
|
|
|
|
|
$url |
848
|
|
|
|
|
|
|
]); |
849
|
0
|
|
|
|
|
0
|
my($system) = |
850
|
|
|
|
|
|
|
"$chdir$funkyftp$src_switch \"$url\" $devnull$stdout_redir"; |
851
|
0
|
0
|
|
|
|
0
|
$self->debug("system[$system]") if $CPAN::DEBUG; |
852
|
0
|
|
|
|
|
0
|
my($wstatus) = system($system); |
853
|
0
|
0
|
|
|
|
0
|
if ($f eq "lynx") { |
854
|
|
|
|
|
|
|
# lynx returns 0 when it fails somewhere |
855
|
0
|
0
|
|
|
|
0
|
if (-s $aslocal) { |
856
|
0
|
|
|
|
|
0
|
my $content = do { local *FH; |
|
0
|
|
|
|
|
0
|
|
857
|
0
|
0
|
|
|
|
0
|
open FH, $aslocal or die; |
858
|
0
|
|
|
|
|
0
|
local $/; |
859
|
0
|
|
|
|
|
0
|
}; |
860
|
0
|
0
|
|
|
|
0
|
if ($content =~ /^<.*([45]|Error [45])/si) { |
861
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->mywarn(qq{ |
862
|
|
|
|
|
|
|
No success, the file that lynx has downloaded looks like an error message: |
863
|
|
|
|
|
|
|
$content |
864
|
|
|
|
|
|
|
}); |
865
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->mysleep(1); |
866
|
0
|
|
|
|
|
0
|
next DLPRG; |
867
|
|
|
|
|
|
|
} |
868
|
0
|
|
|
|
|
0
|
$some_dl_success++; |
869
|
|
|
|
|
|
|
} else { |
870
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->myprint(qq{ |
871
|
|
|
|
|
|
|
No success, the file that lynx has downloaded is an empty file. |
872
|
|
|
|
|
|
|
}); |
873
|
0
|
|
|
|
|
0
|
next DLPRG; |
874
|
|
|
|
|
|
|
} |
875
|
|
|
|
|
|
|
} |
876
|
0
|
0
|
|
|
|
0
|
if ($wstatus == 0) { |
877
|
0
|
0
|
|
|
|
0
|
if (-s $aslocal) { |
878
|
|
|
|
|
|
|
# Looks good |
879
|
0
|
|
|
|
|
0
|
$some_dl_success++; |
880
|
|
|
|
|
|
|
} |
881
|
0
|
|
|
|
|
0
|
$ThesiteURL = $ro_url; |
882
|
0
|
|
|
|
|
0
|
return $aslocal; |
883
|
|
|
|
|
|
|
} else { |
884
|
0
|
|
|
|
|
0
|
my $estatus = $wstatus >> 8; |
885
|
0
|
0
|
|
|
|
0
|
my $size = -f $aslocal ? |
886
|
|
|
|
|
|
|
", left\n$aslocal with size ".-s _ : |
887
|
|
|
|
|
|
|
"\nWarning: expected file [$aslocal] doesn't exist"; |
888
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->myprint(qq{ |
889
|
|
|
|
|
|
|
Function system("$system") |
890
|
|
|
|
|
|
|
returned status $estatus (wstat $wstatus)$size |
891
|
|
|
|
|
|
|
}); |
892
|
|
|
|
|
|
|
} |
893
|
0
|
0
|
|
|
|
0
|
return if $CPAN::Signal; |
894
|
|
|
|
|
|
|
} # download/transfer programs (DLPRG) |
895
|
|
|
|
|
|
|
} # host |
896
|
0
|
0
|
|
|
|
0
|
return unless $any_attempt; |
897
|
0
|
0
|
|
|
|
0
|
if ($some_dl_success) { |
898
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->mywarn("Warning: doesn't seem we had substantial success downloading '$aslocal'. Don't know how to proceed.\n"); |
899
|
|
|
|
|
|
|
} else { |
900
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->mywarn("Warning: no success downloading '$aslocal'. Giving up on it.\n"); |
901
|
|
|
|
|
|
|
} |
902
|
0
|
|
|
|
|
0
|
return; |
903
|
|
|
|
|
|
|
} |
904
|
|
|
|
|
|
|
|
905
|
|
|
|
|
|
|
#-> CPAN::FTP::_proxy_vars |
906
|
|
|
|
|
|
|
sub _proxy_vars { |
907
|
2
|
|
|
2
|
|
4001
|
my($self,$url) = @_; |
908
|
2
|
|
|
|
|
5
|
my $ret = +{}; |
909
|
2
|
|
33
|
|
|
8
|
my $http_proxy = $CPAN::Config->{'http_proxy'} || $ENV{'http_proxy'}; |
910
|
2
|
50
|
|
|
|
5
|
if ($http_proxy) { |
911
|
2
|
|
|
|
|
12
|
my($host) = $url =~ m|://([^/:]+)|; |
912
|
2
|
|
|
|
|
4
|
my $want_proxy = 1; |
913
|
2
|
|
0
|
|
|
6
|
my $noproxy = $CPAN::Config->{'no_proxy'} || $ENV{'no_proxy'} || ""; |
914
|
2
|
|
|
|
|
6
|
my @noproxy = split /\s*,\s*/, $noproxy; |
915
|
2
|
50
|
|
|
|
6
|
if ($host) { |
916
|
2
|
|
|
|
|
4
|
DOMAIN: for my $domain (@noproxy) { |
917
|
2
|
100
|
|
|
|
35
|
if ($host =~ /\Q$domain\E$/) { # cf. LWP::UserAgent |
918
|
1
|
|
|
|
|
4
|
$want_proxy = 0; |
919
|
1
|
|
|
|
|
2
|
last DOMAIN; |
920
|
|
|
|
|
|
|
} |
921
|
|
|
|
|
|
|
} |
922
|
|
|
|
|
|
|
} else { |
923
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->mywarn(" Could not determine host from http_proxy '$http_proxy'\n"); |
924
|
|
|
|
|
|
|
} |
925
|
2
|
100
|
|
|
|
6
|
if ($want_proxy) { |
926
|
1
|
|
|
|
|
19
|
my($user, $pass) = |
927
|
|
|
|
|
|
|
CPAN::HTTP::Credentials->get_proxy_credentials(); |
928
|
1
|
|
|
|
|
5
|
$ret = { |
929
|
|
|
|
|
|
|
proxy_user => $user, |
930
|
|
|
|
|
|
|
proxy_pass => $pass, |
931
|
|
|
|
|
|
|
http_proxy => $http_proxy |
932
|
|
|
|
|
|
|
}; |
933
|
|
|
|
|
|
|
} |
934
|
|
|
|
|
|
|
} |
935
|
2
|
|
|
|
|
5
|
return $ret; |
936
|
|
|
|
|
|
|
} |
937
|
|
|
|
|
|
|
|
938
|
|
|
|
|
|
|
# package CPAN::FTP; |
939
|
|
|
|
|
|
|
sub hostdlhardest { |
940
|
0
|
|
|
0
|
0
|
|
my($self,$host_seq,$file,$aslocal,$stats) = @_; |
941
|
|
|
|
|
|
|
|
942
|
0
|
0
|
|
|
|
|
return unless @$host_seq; |
943
|
0
|
|
|
|
|
|
my($ro_url); |
944
|
0
|
|
|
|
|
|
my($aslocal_dir) = dirname($aslocal); |
945
|
0
|
|
|
|
|
|
mkpath($aslocal_dir); |
946
|
0
|
|
|
|
|
|
my $ftpbin = $CPAN::Config->{ftp}; |
947
|
0
|
0
|
0
|
|
|
|
unless ($ftpbin && length $ftpbin && MM->maybe_command($ftpbin)) { |
|
|
|
0
|
|
|
|
|
948
|
0
|
|
|
|
|
|
$CPAN::Frontend->myprint("No external ftp command available\n\n"); |
949
|
0
|
|
|
|
|
|
return; |
950
|
|
|
|
|
|
|
} |
951
|
0
|
|
|
|
|
|
$CPAN::Frontend->mywarn(qq{ |
952
|
|
|
|
|
|
|
As a last resort we now switch to the external ftp command '$ftpbin' |
953
|
|
|
|
|
|
|
to get '$aslocal'. |
954
|
|
|
|
|
|
|
|
955
|
|
|
|
|
|
|
Doing so often leads to problems that are hard to diagnose. |
956
|
|
|
|
|
|
|
|
957
|
|
|
|
|
|
|
If you're the victim of such problems, please consider unsetting the |
958
|
|
|
|
|
|
|
ftp config variable with |
959
|
|
|
|
|
|
|
|
960
|
|
|
|
|
|
|
o conf ftp "" |
961
|
|
|
|
|
|
|
o conf commit |
962
|
|
|
|
|
|
|
|
963
|
|
|
|
|
|
|
}); |
964
|
0
|
|
|
|
|
|
$CPAN::Frontend->mysleep(2); |
965
|
0
|
|
|
|
|
|
HOSTHARDEST: for $ro_url (@$host_seq) { |
966
|
0
|
|
|
|
|
|
$self->_set_attempt($stats,"dlhardest",$ro_url); |
967
|
0
|
|
|
|
|
|
my $url = "$ro_url$file"; |
968
|
0
|
0
|
|
|
|
|
$self->debug("localizing ftpwise[$url]") if $CPAN::DEBUG; |
969
|
0
|
0
|
|
|
|
|
unless ($url =~ m|^ftp://(.*?)/(.*)/(.*)|) { |
970
|
0
|
|
|
|
|
|
next; |
971
|
|
|
|
|
|
|
} |
972
|
0
|
|
|
|
|
|
my($host,$dir,$getfile) = ($1,$2,$3); |
973
|
0
|
|
|
|
|
|
my $timestamp = 0; |
974
|
0
|
|
|
|
|
|
my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime, |
975
|
|
|
|
|
|
|
$ctime,$blksize,$blocks) = stat($aslocal); |
976
|
0
|
|
0
|
|
|
|
$timestamp = $mtime ||= 0; |
977
|
0
|
|
|
|
|
|
my($netrc) = CPAN::FTP::netrc->new; |
978
|
0
|
|
|
|
|
|
my($netrcfile) = $netrc->netrc; |
979
|
0
|
0
|
|
|
|
|
my($verbose) = $CPAN::DEBUG{'FTP'} & $CPAN::DEBUG ? " -v" : ""; |
980
|
0
|
|
|
|
|
|
my $targetfile = File::Basename::basename($aslocal); |
981
|
0
|
|
|
|
|
|
my(@dialog); |
982
|
0
|
|
|
|
|
|
push( |
983
|
|
|
|
|
|
|
@dialog, |
984
|
|
|
|
|
|
|
"lcd $aslocal_dir", |
985
|
|
|
|
|
|
|
"cd /", |
986
|
|
|
|
|
|
|
map("cd $_", split /\//, $dir), # RFC 1738 |
987
|
|
|
|
|
|
|
"bin", |
988
|
|
|
|
|
|
|
"passive", |
989
|
|
|
|
|
|
|
"get $getfile $targetfile", |
990
|
|
|
|
|
|
|
"quit" |
991
|
|
|
|
|
|
|
); |
992
|
0
|
0
|
0
|
|
|
|
if (! $netrcfile) { |
|
|
0
|
|
|
|
|
|
993
|
0
|
0
|
|
|
|
|
CPAN->debug("No ~/.netrc file found") if $CPAN::DEBUG; |
994
|
|
|
|
|
|
|
} elsif ($netrc->hasdefault || $netrc->contains($host)) { |
995
|
0
|
0
|
|
|
|
|
CPAN->debug(sprintf("hasdef[%d]cont($host)[%d]", |
996
|
|
|
|
|
|
|
$netrc->hasdefault, |
997
|
|
|
|
|
|
|
$netrc->contains($host))) if $CPAN::DEBUG; |
998
|
0
|
0
|
|
|
|
|
if ($netrc->protected) { |
999
|
0
|
|
|
|
|
|
my $dialog = join "", map { " $_\n" } @dialog; |
|
0
|
|
|
|
|
|
|
1000
|
0
|
|
|
|
|
|
my $netrc_explain; |
1001
|
0
|
0
|
|
|
|
|
if ($netrc->contains($host)) { |
1002
|
0
|
|
|
|
|
|
$netrc_explain = "Relying that your .netrc entry for '$host' ". |
1003
|
|
|
|
|
|
|
"manages the login"; |
1004
|
|
|
|
|
|
|
} else { |
1005
|
0
|
|
|
|
|
|
$netrc_explain = "Relying that your default .netrc entry ". |
1006
|
|
|
|
|
|
|
"manages the login"; |
1007
|
|
|
|
|
|
|
} |
1008
|
0
|
|
|
|
|
|
$CPAN::Frontend->myprint(qq{ |
1009
|
|
|
|
|
|
|
Trying with external ftp to get |
1010
|
|
|
|
|
|
|
'$url' |
1011
|
|
|
|
|
|
|
$netrc_explain |
1012
|
|
|
|
|
|
|
Sending the dialog |
1013
|
|
|
|
|
|
|
$dialog |
1014
|
|
|
|
|
|
|
} |
1015
|
|
|
|
|
|
|
); |
1016
|
0
|
|
|
|
|
|
$self->talk_ftp("$ftpbin$verbose $host", |
1017
|
|
|
|
|
|
|
@dialog); |
1018
|
0
|
|
|
|
|
|
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, |
1019
|
|
|
|
|
|
|
$atime,$mtime,$ctime,$blksize,$blocks) = stat($aslocal); |
1020
|
0
|
|
0
|
|
|
|
$mtime ||= 0; |
1021
|
0
|
0
|
|
|
|
|
if ($mtime > $timestamp) { |
1022
|
0
|
|
|
|
|
|
$CPAN::Frontend->myprint("GOT $aslocal\n"); |
1023
|
0
|
|
|
|
|
|
$ThesiteURL = $ro_url; |
1024
|
0
|
|
|
|
|
|
return $aslocal; |
1025
|
|
|
|
|
|
|
} else { |
1026
|
0
|
|
|
|
|
|
$CPAN::Frontend->myprint("Hmm... Still failed!\n"); |
1027
|
|
|
|
|
|
|
} |
1028
|
0
|
0
|
|
|
|
|
return if $CPAN::Signal; |
1029
|
|
|
|
|
|
|
} else { |
1030
|
0
|
|
|
|
|
|
$CPAN::Frontend->mywarn(qq{Your $netrcfile is not }. |
1031
|
|
|
|
|
|
|
qq{correctly protected.\n}); |
1032
|
|
|
|
|
|
|
} |
1033
|
|
|
|
|
|
|
} else { |
1034
|
0
|
|
|
|
|
|
$CPAN::Frontend->mywarn("Your ~/.netrc neither contains $host |
1035
|
|
|
|
|
|
|
nor does it have a default entry\n"); |
1036
|
|
|
|
|
|
|
} |
1037
|
|
|
|
|
|
|
|
1038
|
|
|
|
|
|
|
# OK, they don't have a valid ~/.netrc. Use 'ftp -n' |
1039
|
|
|
|
|
|
|
# then and login manually to host, using e-mail as |
1040
|
|
|
|
|
|
|
# password. |
1041
|
0
|
|
|
|
|
|
$CPAN::Frontend->myprint(qq{Issuing "$ftpbin$verbose -n"\n}); |
1042
|
0
|
|
|
|
|
|
unshift( |
1043
|
|
|
|
|
|
|
@dialog, |
1044
|
|
|
|
|
|
|
"open $host", |
1045
|
|
|
|
|
|
|
"user anonymous $Config::Config{'cf_email'}" |
1046
|
|
|
|
|
|
|
); |
1047
|
0
|
|
|
|
|
|
my $dialog = join "", map { " $_\n" } @dialog; |
|
0
|
|
|
|
|
|
|
1048
|
0
|
|
|
|
|
|
$CPAN::Frontend->myprint(qq{ |
1049
|
|
|
|
|
|
|
Trying with external ftp to get |
1050
|
|
|
|
|
|
|
$url |
1051
|
|
|
|
|
|
|
Sending the dialog |
1052
|
|
|
|
|
|
|
$dialog |
1053
|
|
|
|
|
|
|
} |
1054
|
|
|
|
|
|
|
); |
1055
|
0
|
|
|
|
|
|
$self->talk_ftp("$ftpbin$verbose -n", @dialog); |
1056
|
0
|
|
|
|
|
|
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, |
1057
|
|
|
|
|
|
|
$atime,$mtime,$ctime,$blksize,$blocks) = stat($aslocal); |
1058
|
0
|
|
0
|
|
|
|
$mtime ||= 0; |
1059
|
0
|
0
|
|
|
|
|
if ($mtime > $timestamp) { |
1060
|
0
|
|
|
|
|
|
$CPAN::Frontend->myprint("GOT $aslocal\n"); |
1061
|
0
|
|
|
|
|
|
$ThesiteURL = $ro_url; |
1062
|
0
|
|
|
|
|
|
return $aslocal; |
1063
|
|
|
|
|
|
|
} else { |
1064
|
0
|
|
|
|
|
|
$CPAN::Frontend->myprint("Bad luck... Still failed!\n"); |
1065
|
|
|
|
|
|
|
} |
1066
|
0
|
0
|
|
|
|
|
return if $CPAN::Signal; |
1067
|
0
|
|
|
|
|
|
$CPAN::Frontend->mywarn("Can't access URL $url.\n\n"); |
1068
|
0
|
|
|
|
|
|
$CPAN::Frontend->mysleep(2); |
1069
|
|
|
|
|
|
|
} # host |
1070
|
|
|
|
|
|
|
} |
1071
|
|
|
|
|
|
|
|
1072
|
|
|
|
|
|
|
# package CPAN::FTP; |
1073
|
|
|
|
|
|
|
sub talk_ftp { |
1074
|
0
|
|
|
0
|
0
|
|
my($self,$command,@dialog) = @_; |
1075
|
0
|
|
|
|
|
|
my $fh = FileHandle->new; |
1076
|
0
|
0
|
|
|
|
|
$fh->open("|$command") or die "Couldn't open ftp: $!"; |
1077
|
0
|
|
|
|
|
|
foreach (@dialog) { $fh->print("$_\n") } |
|
0
|
|
|
|
|
|
|
1078
|
0
|
|
|
|
|
|
$fh->close; # Wait for process to complete |
1079
|
0
|
|
|
|
|
|
my $wstatus = $?; |
1080
|
0
|
|
|
|
|
|
my $estatus = $wstatus >> 8; |
1081
|
0
|
0
|
|
|
|
|
$CPAN::Frontend->myprint(qq{ |
1082
|
|
|
|
|
|
|
Subprocess "|$command" |
1083
|
|
|
|
|
|
|
returned status $estatus (wstat $wstatus) |
1084
|
|
|
|
|
|
|
}) if $wstatus; |
1085
|
|
|
|
|
|
|
} |
1086
|
|
|
|
|
|
|
|
1087
|
|
|
|
|
|
|
# find2perl needs modularization, too, all the following is stolen |
1088
|
|
|
|
|
|
|
# from there |
1089
|
|
|
|
|
|
|
# CPAN::FTP::ls |
1090
|
|
|
|
|
|
|
sub ls { |
1091
|
0
|
|
|
0
|
0
|
|
my($self,$name) = @_; |
1092
|
0
|
|
|
|
|
|
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$sizemm, |
1093
|
|
|
|
|
|
|
$atime,$mtime,$ctime,$blksize,$blocks) = lstat($name); |
1094
|
|
|
|
|
|
|
|
1095
|
0
|
|
|
|
|
|
my($perms,%user,%group); |
1096
|
0
|
|
|
|
|
|
my $pname = $name; |
1097
|
|
|
|
|
|
|
|
1098
|
0
|
0
|
|
|
|
|
if ($blocks) { |
1099
|
0
|
|
|
|
|
|
$blocks = int(($blocks + 1) / 2); |
1100
|
|
|
|
|
|
|
} |
1101
|
|
|
|
|
|
|
else { |
1102
|
0
|
|
|
|
|
|
$blocks = int(($sizemm + 1023) / 1024); |
1103
|
|
|
|
|
|
|
} |
1104
|
|
|
|
|
|
|
|
1105
|
0
|
0
|
|
|
|
|
if (-f _) { $perms = '-'; } |
|
0
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
1106
|
0
|
|
|
|
|
|
elsif (-d _) { $perms = 'd'; } |
1107
|
0
|
|
|
|
|
|
elsif (-c _) { $perms = 'c'; $sizemm = &sizemm; } |
|
0
|
|
|
|
|
|
|
1108
|
0
|
|
|
|
|
|
elsif (-b _) { $perms = 'b'; $sizemm = &sizemm; } |
|
0
|
|
|
|
|
|
|
1109
|
0
|
|
|
|
|
|
elsif (-p _) { $perms = 'p'; } |
1110
|
0
|
|
|
|
|
|
elsif (-S _) { $perms = 's'; } |
1111
|
0
|
|
|
|
|
|
else { $perms = 'l'; $pname .= ' -> ' . readlink($_); } |
|
0
|
|
|
|
|
|
|
1112
|
|
|
|
|
|
|
|
1113
|
0
|
|
|
|
|
|
my(@rwx) = ('---','--x','-w-','-wx','r--','r-x','rw-','rwx'); |
1114
|
0
|
|
|
|
|
|
my(@moname) = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); |
1115
|
0
|
|
|
|
|
|
my $tmpmode = $mode; |
1116
|
0
|
|
|
|
|
|
my $tmp = $rwx[$tmpmode & 7]; |
1117
|
0
|
|
|
|
|
|
$tmpmode >>= 3; |
1118
|
0
|
|
|
|
|
|
$tmp = $rwx[$tmpmode & 7] . $tmp; |
1119
|
0
|
|
|
|
|
|
$tmpmode >>= 3; |
1120
|
0
|
|
|
|
|
|
$tmp = $rwx[$tmpmode & 7] . $tmp; |
1121
|
0
|
0
|
|
|
|
|
substr($tmp,2,1) =~ tr/-x/Ss/ if -u _; |
1122
|
0
|
0
|
|
|
|
|
substr($tmp,5,1) =~ tr/-x/Ss/ if -g _; |
1123
|
0
|
0
|
|
|
|
|
substr($tmp,8,1) =~ tr/-x/Tt/ if -k _; |
1124
|
0
|
|
|
|
|
|
$perms .= $tmp; |
1125
|
|
|
|
|
|
|
|
1126
|
0
|
|
0
|
|
|
|
my $user = $user{$uid} || $uid; # too lazy to implement lookup |
1127
|
0
|
|
0
|
|
|
|
my $group = $group{$gid} || $gid; |
1128
|
|
|
|
|
|
|
|
1129
|
0
|
|
|
|
|
|
my($sec,$min,$hour,$mday,$mon,$year) = localtime($mtime); |
1130
|
0
|
|
|
|
|
|
my($timeyear); |
1131
|
0
|
|
|
|
|
|
my($moname) = $moname[$mon]; |
1132
|
0
|
0
|
|
|
|
|
if (-M _ > 365.25 / 2) { |
1133
|
0
|
|
|
|
|
|
$timeyear = $year + 1900; |
1134
|
|
|
|
|
|
|
} |
1135
|
|
|
|
|
|
|
else { |
1136
|
0
|
|
|
|
|
|
$timeyear = sprintf("%02d:%02d", $hour, $min); |
1137
|
|
|
|
|
|
|
} |
1138
|
|
|
|
|
|
|
|
1139
|
0
|
|
|
|
|
|
sprintf "%5lu %4ld %-10s %2d %-8s %-8s %8s %s %2d %5s %s\n", |
1140
|
|
|
|
|
|
|
$ino, |
1141
|
|
|
|
|
|
|
$blocks, |
1142
|
|
|
|
|
|
|
$perms, |
1143
|
|
|
|
|
|
|
$nlink, |
1144
|
|
|
|
|
|
|
$user, |
1145
|
|
|
|
|
|
|
$group, |
1146
|
|
|
|
|
|
|
$sizemm, |
1147
|
|
|
|
|
|
|
$moname, |
1148
|
|
|
|
|
|
|
$mday, |
1149
|
|
|
|
|
|
|
$timeyear, |
1150
|
|
|
|
|
|
|
$pname; |
1151
|
|
|
|
|
|
|
} |
1152
|
|
|
|
|
|
|
|
1153
|
|
|
|
|
|
|
1; |