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