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
|
|
100
|
use strict; |
|
13
|
|
|
|
|
29
|
|
|
13
|
|
|
|
|
455
|
|
5
|
|
|
|
|
|
|
|
6
|
13
|
|
|
13
|
|
2905
|
use Errno (); |
|
13
|
|
|
|
|
8932
|
|
|
13
|
|
|
|
|
330
|
|
7
|
13
|
|
|
13
|
|
82
|
use Fcntl qw(:flock); |
|
13
|
|
|
|
|
39
|
|
|
13
|
|
|
|
|
2067
|
|
8
|
13
|
|
|
13
|
|
106
|
use File::Basename qw(dirname); |
|
13
|
|
|
|
|
42
|
|
|
13
|
|
|
|
|
1177
|
|
9
|
13
|
|
|
13
|
|
91
|
use File::Path qw(mkpath); |
|
13
|
|
|
|
|
28
|
|
|
13
|
|
|
|
|
799
|
|
10
|
13
|
|
|
13
|
|
5937
|
use CPAN::FTP::netrc; |
|
13
|
|
|
|
|
39
|
|
|
13
|
|
|
|
|
479
|
|
11
|
13
|
|
|
13
|
|
84
|
use vars qw($connect_to_internet_ok $Ua $Thesite $ThesiteURL $Themethod); |
|
13
|
|
|
|
|
32
|
|
|
13
|
|
|
|
|
1338
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
@CPAN::FTP::ISA = qw(CPAN::Debug); |
14
|
|
|
|
|
|
|
|
15
|
13
|
|
|
|
|
122824
|
use vars qw( |
16
|
|
|
|
|
|
|
$VERSION |
17
|
13
|
|
|
13
|
|
75
|
); |
|
13
|
|
|
|
|
26
|
|
18
|
|
|
|
|
|
|
$VERSION = "5.5015"; |
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_loadfile() 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, {loadblessed => 1}); }; |
|
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
|
|
27
|
if (CPAN->has_inst("Time::HiRes")) { |
94
|
6
|
|
|
|
|
63
|
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
|
|
13
|
my($self,$file) = @_; |
103
|
3
|
|
|
|
|
15
|
my $ret = { |
104
|
|
|
|
|
|
|
file => $file, |
105
|
|
|
|
|
|
|
attempts => [], |
106
|
|
|
|
|
|
|
start => _mytime, |
107
|
|
|
|
|
|
|
}; |
108
|
3
|
|
|
|
|
9
|
$ret; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
#-> sub CPAN::FTP::_add_to_statistics |
112
|
|
|
|
|
|
|
sub _add_to_statistics { |
113
|
3
|
|
|
3
|
|
11
|
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
|
|
|
|
11
|
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
|
|
12
|
my($self, $file, $urllist) = @_; |
202
|
3
|
50
|
|
|
|
12
|
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
|
|
|
14
|
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
|
|
9
|
my($self, $with_defaults) = @_; |
225
|
3
|
|
50
|
|
|
22
|
$with_defaults ||= 0; |
226
|
3
|
50
|
|
|
|
12
|
CPAN->debug("with_defaults[$with_defaults]") if $CPAN::DEBUG; |
227
|
|
|
|
|
|
|
|
228
|
3
|
|
50
|
|
|
14
|
$CPAN::Config->{urllist} ||= []; |
229
|
3
|
50
|
|
|
|
15
|
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
|
|
|
|
6
|
my @urllist = grep { defined $_ and length $_ } @{$CPAN::Config->{urllist}}; |
|
3
|
|
|
|
|
25
|
|
|
3
|
|
|
|
|
11
|
|
234
|
3
|
50
|
|
|
|
14
|
push @urllist, @CPAN::Defaultsites if $with_defaults; |
235
|
3
|
|
|
|
|
7
|
for my $u (@urllist) { |
236
|
3
|
50
|
|
|
|
9
|
CPAN->debug("u[$u]") if $CPAN::DEBUG; |
237
|
3
|
50
|
|
|
|
33
|
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
|
|
|
|
|
31
|
$u = CPAN::URL->new(TEXT => $u, FROM => "USER"); |
242
|
|
|
|
|
|
|
} |
243
|
|
|
|
|
|
|
} |
244
|
3
|
|
|
|
|
10
|
\@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
|
13
|
my($self,$file,$aslocal,$force,$with_defaults) = @_; |
314
|
3
|
|
50
|
|
|
19
|
$force ||= 0; |
315
|
3
|
50
|
|
|
|
14
|
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
|
|
|
|
|
13
|
for ($CPAN::Config->{connect_to_internet_ok}) { |
323
|
3
|
50
|
33
|
|
|
22
|
$connect_to_internet_ok = $_ if not defined $connect_to_internet_ok and defined $_; |
324
|
|
|
|
|
|
|
} |
325
|
3
|
|
|
|
|
8
|
my $ph = $CPAN::Config->{pushy_https}; |
326
|
3
|
50
|
33
|
|
|
19
|
if (!defined $ph || $ph) { |
327
|
0
|
|
|
|
|
0
|
return $self->localize_2021($file,$aslocal,$force,$with_defaults); |
328
|
|
|
|
|
|
|
} else { |
329
|
3
|
|
|
|
|
21
|
return $self->localize_1995ff($file,$aslocal,$force,$with_defaults); |
330
|
|
|
|
|
|
|
} |
331
|
|
|
|
|
|
|
} |
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
sub have_promising_aslocal { |
334
|
3
|
|
|
3
|
0
|
13
|
my($self, $aslocal, $force) = @_; |
335
|
3
|
0
|
33
|
|
|
41
|
if (-f $aslocal && -r _ && !($force & 1)) { |
|
|
|
33
|
|
|
|
|
336
|
0
|
|
|
|
|
0
|
my $size; |
337
|
0
|
0
|
|
|
|
0
|
if ($size = -s $aslocal) { |
338
|
0
|
0
|
|
|
|
0
|
$self->debug("aslocal[$aslocal]size[$size]") if $CPAN::DEBUG; |
339
|
0
|
|
|
|
|
0
|
return 1; |
340
|
|
|
|
|
|
|
} else { |
341
|
|
|
|
|
|
|
# empty file from a previous unsuccessful attempt to download it |
342
|
0
|
0
|
|
|
|
0
|
unlink $aslocal or |
343
|
|
|
|
|
|
|
$CPAN::Frontend->mydie("Found a zero-length '$aslocal' that I ". |
344
|
|
|
|
|
|
|
"could not remove."); |
345
|
|
|
|
|
|
|
} |
346
|
|
|
|
|
|
|
} |
347
|
3
|
|
|
|
|
17
|
return; |
348
|
|
|
|
|
|
|
} |
349
|
|
|
|
|
|
|
|
350
|
|
|
|
|
|
|
#-> sub CPAN::FTP::localize ; |
351
|
|
|
|
|
|
|
sub localize_2021 { |
352
|
0
|
|
|
0
|
0
|
0
|
my($self,$file,$aslocal,$force,$with_defaults) = @_; |
353
|
0
|
0
|
|
|
|
0
|
return $aslocal if $self->have_promising_aslocal($aslocal, $force); |
354
|
0
|
|
|
|
|
0
|
my($aslocal_dir) = dirname($aslocal); |
355
|
0
|
|
|
|
|
0
|
my $ret; |
356
|
0
|
|
|
|
|
0
|
$self->mymkpath($aslocal_dir); |
357
|
0
|
|
|
|
|
0
|
my $aslocal_tempfile = $aslocal . ".tmp" . $$; |
358
|
0
|
|
|
|
|
0
|
my $base; |
359
|
0
|
0
|
0
|
|
|
0
|
if ( |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
360
|
|
|
|
|
|
|
($CPAN::META->has_usable('HTTP::Tiny') |
361
|
|
|
|
|
|
|
&& $CPAN::META->has_usable('Net::SSLeay') |
362
|
|
|
|
|
|
|
&& $CPAN::META->has_usable('IO::Socket::SSL') |
363
|
|
|
|
|
|
|
) |
364
|
|
|
|
|
|
|
|| $CPAN::Config->{curl} |
365
|
|
|
|
|
|
|
|| $CPAN::Config->{wget} |
366
|
|
|
|
|
|
|
) { |
367
|
0
|
|
|
|
|
0
|
for my $prx (qw(https_proxy no_proxy)) { |
368
|
0
|
0
|
|
|
|
0
|
$ENV{$prx} = $CPAN::Config->{$prx} if $CPAN::Config->{$prx}; |
369
|
|
|
|
|
|
|
} |
370
|
0
|
|
|
|
|
0
|
$base = "https://cpan.org/"; |
371
|
|
|
|
|
|
|
} else { |
372
|
0
|
|
|
|
|
0
|
my @missing_modules = grep { ! $CPAN::META->has_usable($_) } qw(HTTP::Tiny Net::SSLeay IO::Socket::SSL); |
|
0
|
|
|
|
|
0
|
|
373
|
0
|
|
|
|
|
0
|
my $miss = join ", ", map { "'$_'" } @missing_modules; |
|
0
|
|
|
|
|
0
|
|
374
|
0
|
0
|
|
|
|
0
|
my $modules = @missing_modules == 1 ? "module" : "modules"; |
375
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->mywarn("Missing or unusable $modules $miss, and found neither curl nor wget installed. Need to fall back to http.\n"); |
376
|
0
|
|
|
|
|
0
|
for my $prx (qw(http_proxy no_proxy)) { |
377
|
0
|
0
|
|
|
|
0
|
$ENV{$prx} = $CPAN::Config->{$prx} if $CPAN::Config->{$prx}; |
378
|
|
|
|
|
|
|
} |
379
|
0
|
|
|
|
|
0
|
$base = "http://www.cpan.org/"; |
380
|
|
|
|
|
|
|
} |
381
|
0
|
|
|
|
|
0
|
$ret = $self->hostdl_2021($base,$file,$aslocal_tempfile); |
382
|
0
|
0
|
|
|
|
0
|
if ($ret) { # c&p from below |
383
|
0
|
0
|
|
|
|
0
|
CPAN->debug("ret[$ret]aslocal[$aslocal]") if $CPAN::DEBUG; |
384
|
0
|
0
|
|
|
|
0
|
if ($ret eq $aslocal_tempfile) { |
385
|
|
|
|
|
|
|
# if we got it exactly as we asked for, only then we |
386
|
|
|
|
|
|
|
# want to rename |
387
|
0
|
0
|
|
|
|
0
|
rename $aslocal_tempfile, $aslocal |
388
|
|
|
|
|
|
|
or $CPAN::Frontend->mydie("Error while trying to rename ". |
389
|
|
|
|
|
|
|
"'$ret' to '$aslocal': $!"); |
390
|
0
|
|
|
|
|
0
|
$ret = $aslocal; |
391
|
|
|
|
|
|
|
} |
392
|
|
|
|
|
|
|
} else { |
393
|
0
|
|
|
|
|
0
|
unlink $aslocal_tempfile; |
394
|
0
|
|
|
|
|
0
|
return; |
395
|
|
|
|
|
|
|
} |
396
|
0
|
|
|
|
|
0
|
return $ret; |
397
|
|
|
|
|
|
|
} |
398
|
|
|
|
|
|
|
|
399
|
|
|
|
|
|
|
sub hostdl_2021 { |
400
|
0
|
|
|
0
|
0
|
0
|
my($self, $base, $file, $aslocal) = @_; # the $aslocal is $aslocal_tempfile in the caller (old convention) |
401
|
0
|
|
|
|
|
0
|
my $proxy_vars = $self->_proxy_vars($base); |
402
|
0
|
|
|
|
|
0
|
my $url = "$base$file"; |
403
|
0
|
0
|
0
|
|
|
0
|
if ( |
|
|
0
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
404
|
|
|
|
|
|
|
($CPAN::META->has_usable('HTTP::Tiny') |
405
|
|
|
|
|
|
|
&& $CPAN::META->has_usable('Net::SSLeay') |
406
|
|
|
|
|
|
|
&& $CPAN::META->has_usable('IO::Socket::SSL') |
407
|
|
|
|
|
|
|
) |
408
|
|
|
|
|
|
|
){ |
409
|
|
|
|
|
|
|
# mostly c&p from below |
410
|
0
|
|
|
|
|
0
|
require CPAN::HTTP::Client; |
411
|
|
|
|
|
|
|
my $chc = CPAN::HTTP::Client->new( |
412
|
|
|
|
|
|
|
proxy => $CPAN::Config->{http_proxy} || $ENV{http_proxy}, |
413
|
|
|
|
|
|
|
no_proxy => $CPAN::Config->{no_proxy} || $ENV{no_proxy}, |
414
|
0
|
|
0
|
|
|
0
|
); |
|
|
|
0
|
|
|
|
|
415
|
0
|
0
|
|
|
|
0
|
for my $try ( $url, ( $url !~ /\.gz(?!\n)\Z/ ? "$url.gz" : () ) ) { |
416
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->myprint("Fetching with HTTP::Tiny:\n$try\n"); |
417
|
0
|
|
|
|
|
0
|
my $res = eval { $chc->mirror($try, $aslocal) }; |
|
0
|
|
|
|
|
0
|
|
418
|
0
|
0
|
0
|
|
|
0
|
if ( $res && $res->{success} ) { |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
419
|
0
|
|
|
|
|
0
|
my $now = time; |
420
|
0
|
|
|
|
|
0
|
utime $now, $now, $aslocal; # download time is more |
421
|
|
|
|
|
|
|
# important than upload |
422
|
|
|
|
|
|
|
# time |
423
|
0
|
|
|
|
|
0
|
return $aslocal; |
424
|
|
|
|
|
|
|
} |
425
|
|
|
|
|
|
|
elsif ( $res && $res->{status} ne '599') { |
426
|
|
|
|
|
|
|
$CPAN::Frontend->myprint(sprintf( |
427
|
|
|
|
|
|
|
"HTTP::Tiny failed with code[%s] message[%s]\n", |
428
|
|
|
|
|
|
|
$res->{status}, |
429
|
|
|
|
|
|
|
$res->{reason}, |
430
|
|
|
|
|
|
|
) |
431
|
0
|
|
|
|
|
0
|
); |
432
|
|
|
|
|
|
|
} |
433
|
|
|
|
|
|
|
elsif ( $res && $res->{status} eq '599') { |
434
|
|
|
|
|
|
|
$CPAN::Frontend->myprint(sprintf( |
435
|
|
|
|
|
|
|
"HTTP::Tiny failed with an internal error: %s\n", |
436
|
|
|
|
|
|
|
$res->{content}, |
437
|
|
|
|
|
|
|
) |
438
|
0
|
|
|
|
|
0
|
); |
439
|
|
|
|
|
|
|
} |
440
|
|
|
|
|
|
|
else { |
441
|
0
|
|
0
|
|
|
0
|
my $err = $@ || 'Unknown error'; |
442
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->myprint(sprintf( |
443
|
|
|
|
|
|
|
"Error downloading with HTTP::Tiny: %s\n", $err |
444
|
|
|
|
|
|
|
) |
445
|
|
|
|
|
|
|
); |
446
|
|
|
|
|
|
|
} |
447
|
|
|
|
|
|
|
} |
448
|
|
|
|
|
|
|
} elsif ($CPAN::Config->{curl} || $CPAN::Config->{wget}){ |
449
|
|
|
|
|
|
|
# c&p from further down |
450
|
0
|
|
|
|
|
0
|
my($src_switch, $stdout_redir); |
451
|
0
|
|
0
|
|
|
0
|
my($devnull) = $CPAN::Config->{devnull} || ""; |
452
|
0
|
|
|
|
|
0
|
DLPRG: for my $dlprg (qw(curl wget)) { |
453
|
0
|
|
|
|
|
0
|
my $dlprg_configured = $CPAN::Config->{$dlprg}; |
454
|
0
|
0
|
|
|
|
0
|
next unless defined $dlprg_configured; |
455
|
0
|
|
|
|
|
0
|
my $funkyftp = CPAN::HandleConfig->safe_quote($dlprg_configured); |
456
|
0
|
0
|
|
|
|
0
|
if ($dlprg eq "wget") { |
|
|
0
|
|
|
|
|
|
457
|
0
|
|
|
|
|
0
|
$src_switch = " -O \"$aslocal\""; |
458
|
0
|
|
|
|
|
0
|
$stdout_redir = ""; |
459
|
|
|
|
|
|
|
} elsif ($dlprg eq 'curl') { |
460
|
0
|
|
|
|
|
0
|
$src_switch = ' -L -f -s -S --netrc-optional'; |
461
|
0
|
0
|
|
|
|
0
|
if ($proxy_vars->{http_proxy}) { |
462
|
0
|
|
|
|
|
0
|
$src_switch .= qq{ -U "$proxy_vars->{proxy_user}:$proxy_vars->{proxy_pass}" -x "$proxy_vars->{http_proxy}"}; |
463
|
|
|
|
|
|
|
} |
464
|
|
|
|
|
|
|
} |
465
|
|
|
|
|
|
|
$CPAN::Frontend->myprint( |
466
|
0
|
|
|
|
|
0
|
qq[ |
467
|
|
|
|
|
|
|
Trying with |
468
|
|
|
|
|
|
|
$funkyftp$src_switch |
469
|
|
|
|
|
|
|
to get |
470
|
|
|
|
|
|
|
$url |
471
|
|
|
|
|
|
|
]); |
472
|
0
|
|
|
|
|
0
|
my($system) = |
473
|
|
|
|
|
|
|
"$funkyftp$src_switch \"$url\" $devnull$stdout_redir"; |
474
|
0
|
0
|
|
|
|
0
|
$self->debug("system[$system]") if $CPAN::DEBUG; |
475
|
0
|
|
|
|
|
0
|
my($wstatus) = system($system); |
476
|
0
|
0
|
|
|
|
0
|
if ($wstatus == 0) { |
477
|
0
|
|
|
|
|
0
|
return $aslocal; |
478
|
|
|
|
|
|
|
} else { |
479
|
0
|
|
|
|
|
0
|
my $estatus = $wstatus >> 8; |
480
|
0
|
0
|
|
|
|
0
|
my $size = -f $aslocal ? |
481
|
|
|
|
|
|
|
", left\n$aslocal with size ".-s _ : |
482
|
|
|
|
|
|
|
"\nWarning: expected file [$aslocal] doesn't exist"; |
483
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->myprint(qq{ |
484
|
|
|
|
|
|
|
Function system("$system") |
485
|
|
|
|
|
|
|
returned status $estatus (wstat $wstatus)$size |
486
|
|
|
|
|
|
|
}); |
487
|
|
|
|
|
|
|
} |
488
|
|
|
|
|
|
|
} # DLPRG |
489
|
|
|
|
|
|
|
} # curl, wget |
490
|
0
|
|
|
|
|
0
|
return; |
491
|
|
|
|
|
|
|
} |
492
|
|
|
|
|
|
|
|
493
|
|
|
|
|
|
|
#-> sub CPAN::FTP::localize ; |
494
|
|
|
|
|
|
|
sub localize_1995ff { |
495
|
3
|
|
|
3
|
0
|
9
|
my($self,$file,$aslocal,$force,$with_defaults) = @_; |
496
|
3
|
50
|
|
|
|
13
|
if ($^O eq 'MacOS') { |
497
|
|
|
|
|
|
|
# Comment by AK on 2000-09-03: Uniq short filenames would be |
498
|
|
|
|
|
|
|
# available in CHECKSUMS file |
499
|
0
|
|
|
|
|
0
|
my($name, $path) = File::Basename::fileparse($aslocal, ''); |
500
|
0
|
0
|
|
|
|
0
|
if (length($name) > 31) { |
501
|
0
|
|
|
|
|
0
|
$name =~ s/( |
502
|
|
|
|
|
|
|
\.( |
503
|
|
|
|
|
|
|
readme(\.(gz|Z))? | |
504
|
|
|
|
|
|
|
(tar\.)?(gz|Z) | |
505
|
|
|
|
|
|
|
tgz | |
506
|
|
|
|
|
|
|
zip | |
507
|
|
|
|
|
|
|
pm\.(gz|Z) |
508
|
|
|
|
|
|
|
) |
509
|
|
|
|
|
|
|
)$//x; |
510
|
0
|
|
|
|
|
0
|
my $suf = $1; |
511
|
0
|
|
|
|
|
0
|
my $size = 31 - length($suf); |
512
|
0
|
|
|
|
|
0
|
while (length($name) > $size) { |
513
|
0
|
|
|
|
|
0
|
chop $name; |
514
|
|
|
|
|
|
|
} |
515
|
0
|
|
|
|
|
0
|
$name .= $suf; |
516
|
0
|
|
|
|
|
0
|
$aslocal = File::Spec->catfile($path, $name); |
517
|
|
|
|
|
|
|
} |
518
|
|
|
|
|
|
|
} |
519
|
|
|
|
|
|
|
|
520
|
3
|
50
|
|
|
|
11
|
return $aslocal if $self->have_promising_aslocal($aslocal, $force); |
521
|
3
|
|
|
|
|
9
|
my($maybe_restore) = 0; |
522
|
3
|
50
|
|
|
|
33
|
if (-f $aslocal) { |
523
|
0
|
|
|
|
|
0
|
rename $aslocal, "$aslocal.bak$$"; |
524
|
0
|
|
|
|
|
0
|
$maybe_restore++; |
525
|
|
|
|
|
|
|
} |
526
|
|
|
|
|
|
|
|
527
|
3
|
|
|
|
|
271
|
my($aslocal_dir) = dirname($aslocal); |
528
|
|
|
|
|
|
|
# Inheritance is not easier to manage than a few if/else branches |
529
|
3
|
50
|
|
|
|
22
|
if ($CPAN::META->has_usable('LWP::UserAgent')) { |
530
|
0
|
0
|
|
|
|
0
|
unless ($Ua) { |
531
|
0
|
|
|
|
|
0
|
CPAN::LWP::UserAgent->config; |
532
|
0
|
|
|
|
|
0
|
eval {$Ua = CPAN::LWP::UserAgent->new;}; # Why is has_usable still not fit enough? |
|
0
|
|
|
|
|
0
|
|
533
|
0
|
0
|
|
|
|
0
|
if ($@) { |
534
|
0
|
0
|
|
|
|
0
|
$CPAN::Frontend->mywarn("CPAN::LWP::UserAgent->new dies with $@\n") |
535
|
|
|
|
|
|
|
if $CPAN::DEBUG; |
536
|
|
|
|
|
|
|
} else { |
537
|
0
|
|
|
|
|
0
|
my($var); |
538
|
|
|
|
|
|
|
$Ua->proxy('ftp', $var) |
539
|
0
|
0
|
0
|
|
|
0
|
if $var = $CPAN::Config->{ftp_proxy} || $ENV{ftp_proxy}; |
540
|
|
|
|
|
|
|
$Ua->proxy('http', $var) |
541
|
0
|
0
|
0
|
|
|
0
|
if $var = $CPAN::Config->{http_proxy} || $ENV{http_proxy}; |
542
|
|
|
|
|
|
|
$Ua->no_proxy($var) |
543
|
0
|
0
|
0
|
|
|
0
|
if $var = $CPAN::Config->{no_proxy} || $ENV{no_proxy}; |
544
|
|
|
|
|
|
|
} |
545
|
|
|
|
|
|
|
} |
546
|
|
|
|
|
|
|
} |
547
|
3
|
|
|
|
|
16
|
for my $prx (qw(ftp_proxy http_proxy no_proxy)) { |
548
|
9
|
50
|
|
|
|
26
|
$ENV{$prx} = $CPAN::Config->{$prx} if $CPAN::Config->{$prx}; |
549
|
|
|
|
|
|
|
} |
550
|
|
|
|
|
|
|
|
551
|
|
|
|
|
|
|
# Try the list of urls for each single object. We keep a record |
552
|
|
|
|
|
|
|
# where we did get a file from |
553
|
3
|
|
|
|
|
6
|
my(@reordered,$last); |
554
|
3
|
|
|
|
|
18
|
my $ccurllist = $self->_get_urllist($with_defaults); |
555
|
3
|
|
|
|
|
8
|
$last = $#$ccurllist; |
556
|
3
|
50
|
|
|
|
11
|
if ($force & 2) { # local cpans probably out of date, don't reorder |
557
|
3
|
|
|
|
|
11
|
@reordered = (0..$last); |
558
|
|
|
|
|
|
|
} else { |
559
|
|
|
|
|
|
|
@reordered = |
560
|
|
|
|
|
|
|
sort { |
561
|
0
|
0
|
0
|
|
|
0
|
(substr($ccurllist->[$b],0,4) eq "file") |
|
0
|
|
|
|
|
0
|
|
562
|
|
|
|
|
|
|
<=> |
563
|
|
|
|
|
|
|
(substr($ccurllist->[$a],0,4) eq "file") |
564
|
|
|
|
|
|
|
or |
565
|
|
|
|
|
|
|
defined($ThesiteURL) |
566
|
|
|
|
|
|
|
and |
567
|
|
|
|
|
|
|
($ccurllist->[$b] eq $ThesiteURL) |
568
|
|
|
|
|
|
|
<=> |
569
|
|
|
|
|
|
|
($ccurllist->[$a] eq $ThesiteURL) |
570
|
|
|
|
|
|
|
} 0..$last; |
571
|
|
|
|
|
|
|
} |
572
|
3
|
|
|
|
|
5
|
my(@levels); |
573
|
3
|
|
100
|
|
|
23
|
$Themethod ||= ""; |
574
|
3
|
50
|
|
|
|
11
|
$self->debug("Themethod[$Themethod]reordered[@reordered]") if $CPAN::DEBUG; |
575
|
3
|
|
|
|
|
30
|
my @all_levels = ( |
576
|
|
|
|
|
|
|
["dleasy", "file"], |
577
|
|
|
|
|
|
|
["dleasy"], |
578
|
|
|
|
|
|
|
["dlhard"], |
579
|
|
|
|
|
|
|
["dlhardest"], |
580
|
|
|
|
|
|
|
["dleasy", "http","defaultsites"], |
581
|
|
|
|
|
|
|
["dlhard", "http","defaultsites"], |
582
|
|
|
|
|
|
|
["dleasy", "ftp", "defaultsites"], |
583
|
|
|
|
|
|
|
["dlhard", "ftp", "defaultsites"], |
584
|
|
|
|
|
|
|
["dlhardest","", "defaultsites"], |
585
|
|
|
|
|
|
|
); |
586
|
3
|
100
|
|
|
|
9
|
if ($Themethod) { |
587
|
2
|
|
|
|
|
5
|
@levels = grep {$_->[0] eq $Themethod} @all_levels; |
|
18
|
|
|
|
|
35
|
|
588
|
2
|
|
|
|
|
5
|
push @levels, grep {$_->[0] ne $Themethod} @all_levels; |
|
18
|
|
|
|
|
30
|
|
589
|
|
|
|
|
|
|
} else { |
590
|
1
|
|
|
|
|
8
|
@levels = @all_levels; |
591
|
|
|
|
|
|
|
} |
592
|
3
|
50
|
|
|
|
13
|
@levels = qw/dleasy/ if $^O eq 'MacOS'; |
593
|
3
|
|
|
|
|
10
|
my($levelno); |
594
|
|
|
|
|
|
|
local $ENV{FTP_PASSIVE} = |
595
|
|
|
|
|
|
|
exists $CPAN::Config->{ftp_passive} ? |
596
|
3
|
50
|
|
|
|
33
|
$CPAN::Config->{ftp_passive} : 1; |
597
|
3
|
|
|
|
|
7
|
my $ret; |
598
|
3
|
|
|
|
|
21
|
my $stats = $self->_new_stats($file); |
599
|
3
|
|
|
|
|
12
|
LEVEL: for $levelno (0..$#levels) { |
600
|
3
|
|
|
|
|
7
|
my $level_tuple = $levels[$levelno]; |
601
|
3
|
|
|
|
|
9
|
my($level,$scheme,$sitetag) = @$level_tuple; |
602
|
3
|
50
|
33
|
|
|
22
|
$self->mymkpath($aslocal_dir) unless $scheme && "file" eq $scheme; |
603
|
3
|
|
33
|
|
|
10
|
my $defaultsites = $sitetag && $sitetag eq "defaultsites" && !@$ccurllist; |
604
|
3
|
|
|
|
|
39
|
my @urllist; |
605
|
3
|
50
|
|
|
|
14
|
if ($defaultsites) { |
606
|
0
|
0
|
|
|
|
0
|
unless (defined $connect_to_internet_ok) { |
607
|
|
|
|
|
|
|
$CPAN::Frontend->myprint(sprintf qq{ |
608
|
|
|
|
|
|
|
I would like to connect to one of the following sites to get '%s': |
609
|
|
|
|
|
|
|
|
610
|
|
|
|
|
|
|
%s |
611
|
|
|
|
|
|
|
}, |
612
|
|
|
|
|
|
|
$file, |
613
|
0
|
|
|
|
|
0
|
join("",map { " ".$_->text."\n" } @CPAN::Defaultsites), |
|
0
|
|
|
|
|
0
|
|
614
|
|
|
|
|
|
|
); |
615
|
0
|
|
|
|
|
0
|
my $answer = CPAN::Shell::colorable_makemaker_prompt("Is it OK to try to connect to the Internet?", "yes"); |
616
|
0
|
0
|
|
|
|
0
|
if ($answer =~ /^y/i) { |
617
|
0
|
|
|
|
|
0
|
$connect_to_internet_ok = 1; |
618
|
|
|
|
|
|
|
} else { |
619
|
0
|
|
|
|
|
0
|
$connect_to_internet_ok = 0; |
620
|
|
|
|
|
|
|
} |
621
|
|
|
|
|
|
|
} |
622
|
0
|
0
|
|
|
|
0
|
if ($connect_to_internet_ok) { |
623
|
0
|
|
|
|
|
0
|
@urllist = @CPAN::Defaultsites; |
624
|
|
|
|
|
|
|
} else { |
625
|
0
|
|
|
|
|
0
|
my $sleep = 2; |
626
|
|
|
|
|
|
|
# the tricky thing about dying here is that everybody |
627
|
|
|
|
|
|
|
# believes that calls to exists() or all_objects() are |
628
|
|
|
|
|
|
|
# safe. |
629
|
0
|
|
|
|
|
0
|
require CPAN::Exception::blocked_urllist; |
630
|
0
|
|
|
|
|
0
|
die CPAN::Exception::blocked_urllist->new; |
631
|
|
|
|
|
|
|
} |
632
|
|
|
|
|
|
|
} else { # ! $defaultsites |
633
|
3
|
50
|
|
|
|
19
|
my @host_seq = $level =~ /dleasy/ ? |
634
|
|
|
|
|
|
|
@reordered : 0..$last; # reordered has file and $Thesiteurl first |
635
|
3
|
|
|
|
|
8
|
@urllist = map { $ccurllist->[$_] } @host_seq; |
|
3
|
|
|
|
|
13
|
|
636
|
|
|
|
|
|
|
} |
637
|
3
|
50
|
|
|
|
9
|
$self->debug("synth. urllist[@urllist]") if $CPAN::DEBUG; |
638
|
3
|
|
|
|
|
18
|
my $aslocal_tempfile = $aslocal . ".tmp" . $$; |
639
|
3
|
50
|
|
|
|
17
|
if (my $recommend = $self->_recommend_url_for($file,\@urllist)) { |
640
|
0
|
|
|
|
|
0
|
@urllist = grep { $_ ne $recommend } @urllist; |
|
0
|
|
|
|
|
0
|
|
641
|
0
|
|
|
|
|
0
|
unshift @urllist, $recommend; |
642
|
|
|
|
|
|
|
} |
643
|
3
|
50
|
|
|
|
9
|
$self->debug("synth. urllist[@urllist]") if $CPAN::DEBUG; |
644
|
3
|
|
|
|
|
18
|
$ret = $self->hostdlxxx($level,$scheme,\@urllist,$file,$aslocal_tempfile,$stats); |
645
|
3
|
50
|
|
|
|
14
|
if ($ret) { |
646
|
3
|
50
|
|
|
|
8
|
CPAN->debug("ret[$ret]aslocal[$aslocal]") if $CPAN::DEBUG; |
647
|
3
|
50
|
33
|
|
|
70
|
if ($ret eq $aslocal_tempfile) { |
|
|
50
|
|
|
|
|
|
648
|
|
|
|
|
|
|
# if we got it exactly as we asked for, only then we |
649
|
|
|
|
|
|
|
# want to rename |
650
|
0
|
0
|
|
|
|
0
|
rename $aslocal_tempfile, $aslocal |
651
|
|
|
|
|
|
|
or $CPAN::Frontend->mydie("Error while trying to rename ". |
652
|
|
|
|
|
|
|
"'$ret' to '$aslocal': $!"); |
653
|
0
|
|
|
|
|
0
|
$ret = $aslocal; |
654
|
|
|
|
|
|
|
} |
655
|
|
|
|
|
|
|
elsif (-f $ret && $scheme eq 'file' ) { |
656
|
|
|
|
|
|
|
# it's a local file, so there's nothing left to do, we |
657
|
|
|
|
|
|
|
# let them read from where it is |
658
|
|
|
|
|
|
|
} |
659
|
3
|
|
|
|
|
7
|
$Themethod = $level; |
660
|
3
|
|
|
|
|
7
|
my $now = time; |
661
|
|
|
|
|
|
|
# utime $now, $now, $aslocal; # too bad, if we do that, we |
662
|
|
|
|
|
|
|
# might alter a local mirror |
663
|
3
|
50
|
|
|
|
7
|
$self->debug("level[$level]") if $CPAN::DEBUG; |
664
|
3
|
|
|
|
|
32
|
last LEVEL; |
665
|
|
|
|
|
|
|
} else { |
666
|
0
|
|
|
|
|
0
|
unlink $aslocal_tempfile; |
667
|
0
|
0
|
|
|
|
0
|
last if $CPAN::Signal; # need to cleanup |
668
|
|
|
|
|
|
|
} |
669
|
|
|
|
|
|
|
} |
670
|
3
|
50
|
|
|
|
9
|
if ($ret) { |
671
|
3
|
|
|
|
|
54
|
$stats->{filesize} = -s $ret; |
672
|
|
|
|
|
|
|
} |
673
|
3
|
50
|
|
|
|
13
|
$self->debug("before _add_to_statistics") if $CPAN::DEBUG; |
674
|
3
|
|
|
|
|
18
|
$self->_add_to_statistics($stats); |
675
|
3
|
50
|
|
|
|
11
|
$self->debug("after _add_to_statistics") if $CPAN::DEBUG; |
676
|
3
|
50
|
|
|
|
8
|
if ($ret) { |
677
|
3
|
|
|
|
|
41
|
unlink "$aslocal.bak$$"; |
678
|
3
|
|
|
|
|
57
|
return $ret; |
679
|
|
|
|
|
|
|
} |
680
|
0
|
0
|
|
|
|
0
|
unless ($CPAN::Signal) { |
681
|
0
|
|
|
|
|
0
|
my(@mess); |
682
|
0
|
|
|
|
|
0
|
local $" = " "; |
683
|
0
|
0
|
|
|
|
0
|
if (@{$CPAN::Config->{urllist}}) { |
|
0
|
|
|
|
|
0
|
|
684
|
|
|
|
|
|
|
push @mess, |
685
|
|
|
|
|
|
|
qq{Please check, if the URLs I found in your configuration file \(}. |
686
|
0
|
|
|
|
|
0
|
join(", ", @{$CPAN::Config->{urllist}}). |
|
0
|
|
|
|
|
0
|
|
687
|
|
|
|
|
|
|
qq{\) are valid.}; |
688
|
|
|
|
|
|
|
} else { |
689
|
0
|
|
|
|
|
0
|
push @mess, qq{Your urllist is empty!}; |
690
|
|
|
|
|
|
|
} |
691
|
0
|
|
|
|
|
0
|
push @mess, qq{The urllist can be edited.}, |
692
|
|
|
|
|
|
|
qq{E.g. with 'o conf urllist push ftp://myurl/'}; |
693
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->mywarn(Text::Wrap::wrap("","","@mess"). "\n\n"); |
694
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->mydie("Could not fetch $file\n"); |
695
|
|
|
|
|
|
|
} |
696
|
0
|
0
|
|
|
|
0
|
if ($maybe_restore) { |
697
|
0
|
|
|
|
|
0
|
rename "$aslocal.bak$$", $aslocal; |
698
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->myprint("Trying to get away with old file:\n" . |
699
|
|
|
|
|
|
|
$self->ls($aslocal) . "\n"); |
700
|
0
|
|
|
|
|
0
|
return $aslocal; |
701
|
|
|
|
|
|
|
} |
702
|
0
|
|
|
|
|
0
|
return; |
703
|
|
|
|
|
|
|
} |
704
|
|
|
|
|
|
|
|
705
|
|
|
|
|
|
|
sub mymkpath { |
706
|
0
|
|
|
0
|
0
|
0
|
my($self, $aslocal_dir) = @_; |
707
|
0
|
|
|
|
|
0
|
mkpath($aslocal_dir); |
708
|
0
|
0
|
|
|
|
0
|
$CPAN::Frontend->mywarn(qq{Warning: You are not allowed to write into }. |
709
|
|
|
|
|
|
|
qq{directory "$aslocal_dir". |
710
|
|
|
|
|
|
|
I\'ll continue, but if you encounter problems, they may be due |
711
|
|
|
|
|
|
|
to insufficient permissions.\n}) unless -w $aslocal_dir; |
712
|
|
|
|
|
|
|
} |
713
|
|
|
|
|
|
|
|
714
|
|
|
|
|
|
|
sub hostdlxxx { |
715
|
3
|
|
|
3
|
0
|
7
|
my $self = shift; |
716
|
3
|
|
|
|
|
6
|
my $level = shift; |
717
|
3
|
|
|
|
|
5
|
my $scheme = shift; |
718
|
3
|
|
|
|
|
5
|
my $h = shift; |
719
|
3
|
50
|
|
|
|
75
|
$h = [ grep /^\Q$scheme\E:/, @$h ] if $scheme; |
720
|
3
|
|
|
|
|
10
|
my $method = "host$level"; |
721
|
3
|
|
|
|
|
27
|
$self->$method($h, @_); |
722
|
|
|
|
|
|
|
} |
723
|
|
|
|
|
|
|
|
724
|
|
|
|
|
|
|
sub _set_attempt { |
725
|
3
|
|
|
3
|
|
16
|
my($self,$stats,$method,$url) = @_; |
726
|
3
|
|
|
|
|
9
|
push @{$stats->{attempts}}, { |
|
3
|
|
|
|
|
13
|
|
727
|
|
|
|
|
|
|
method => $method, |
728
|
|
|
|
|
|
|
start => _mytime, |
729
|
|
|
|
|
|
|
url => $url, |
730
|
|
|
|
|
|
|
}; |
731
|
|
|
|
|
|
|
} |
732
|
|
|
|
|
|
|
|
733
|
|
|
|
|
|
|
# package CPAN::FTP; |
734
|
|
|
|
|
|
|
sub hostdleasy { #called from hostdlxxx |
735
|
3
|
|
|
3
|
0
|
11
|
my($self,$host_seq,$file,$aslocal,$stats) = @_; |
736
|
3
|
|
|
|
|
5
|
my($ro_url); |
737
|
3
|
|
|
|
|
13
|
HOSTEASY: for $ro_url (@$host_seq) { |
738
|
3
|
|
|
|
|
24
|
$self->_set_attempt($stats,"dleasy",$ro_url); |
739
|
3
|
|
|
|
|
12
|
my $url = "$ro_url$file"; |
740
|
3
|
50
|
|
|
|
16
|
$self->debug("localizing perlish[$url]") if $CPAN::DEBUG; |
741
|
3
|
50
|
|
|
|
27
|
if ($url =~ /^file:/) { |
742
|
3
|
|
|
|
|
7
|
my $l; |
743
|
3
|
50
|
|
|
|
10
|
if ($CPAN::META->has_inst('URI::URL')) { |
744
|
3
|
|
|
|
|
21
|
my $u = URI::URL->new($url); |
745
|
3
|
|
|
|
|
8830
|
$l = $u->file; |
746
|
|
|
|
|
|
|
} else { # works only on Unix, is poorly constructed, but |
747
|
|
|
|
|
|
|
# hopefully better than nothing. |
748
|
|
|
|
|
|
|
# RFC 1738 says fileurl BNF is |
749
|
|
|
|
|
|
|
# fileurl = "file://" [ host | "localhost" ] "/" fpath |
750
|
|
|
|
|
|
|
# Thanks to "Mark D. Baushke" for |
751
|
|
|
|
|
|
|
# the code |
752
|
0
|
|
|
|
|
0
|
($l = $url) =~ s|^file://[^/]*/|/|; # discard the host part |
753
|
0
|
|
|
|
|
0
|
$l =~ s|^file:||; # assume they |
754
|
|
|
|
|
|
|
# meant |
755
|
|
|
|
|
|
|
# file://localhost |
756
|
0
|
0
|
0
|
|
|
0
|
$l =~ s|^/||s |
757
|
|
|
|
|
|
|
if ! -f $l && $l =~ m|^/\w:|; # e.g. /P: |
758
|
|
|
|
|
|
|
} |
759
|
3
|
50
|
|
|
|
4486
|
$self->debug("local file[$l]") if $CPAN::DEBUG; |
760
|
3
|
50
|
33
|
|
|
93
|
if ( -f $l && -r _) { |
761
|
0
|
|
|
|
|
0
|
$ThesiteURL = $ro_url; |
762
|
0
|
|
|
|
|
0
|
return $l; |
763
|
|
|
|
|
|
|
} |
764
|
|
|
|
|
|
|
# If request is for a compressed file and we can find the |
765
|
|
|
|
|
|
|
# uncompressed file also, return the path of the uncompressed file |
766
|
|
|
|
|
|
|
# otherwise, decompress it and return the resulting path |
767
|
3
|
50
|
0
|
|
|
41
|
if ($l =~ /(.+)\.gz$/) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
768
|
3
|
|
|
|
|
17
|
my $ungz = $1; |
769
|
3
|
50
|
33
|
|
|
81
|
if ( -f $ungz && -r _) { |
|
|
0
|
0
|
|
|
|
|
770
|
3
|
|
|
|
|
14
|
$ThesiteURL = $ro_url; |
771
|
3
|
|
|
|
|
35
|
return $ungz; |
772
|
|
|
|
|
|
|
} |
773
|
|
|
|
|
|
|
elsif (-f $l && -r _) { |
774
|
0
|
|
|
|
|
0
|
eval { CPAN::Tarzip->new($l)->gunzip($aslocal) }; |
|
0
|
|
|
|
|
0
|
|
775
|
0
|
0
|
0
|
|
|
0
|
if ( -f $aslocal && -s _) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
776
|
0
|
|
|
|
|
0
|
$ThesiteURL = $ro_url; |
777
|
0
|
|
|
|
|
0
|
return $aslocal; |
778
|
|
|
|
|
|
|
} |
779
|
|
|
|
|
|
|
elsif (! -s $aslocal) { |
780
|
0
|
|
|
|
|
0
|
unlink $aslocal; |
781
|
|
|
|
|
|
|
} |
782
|
|
|
|
|
|
|
elsif (-f $l) { |
783
|
0
|
0
|
|
|
|
0
|
$CPAN::Frontend->mywarn("Error decompressing '$l': $@\n") |
784
|
|
|
|
|
|
|
if $@; |
785
|
0
|
|
|
|
|
0
|
return; |
786
|
|
|
|
|
|
|
} |
787
|
|
|
|
|
|
|
} |
788
|
|
|
|
|
|
|
} |
789
|
|
|
|
|
|
|
# Otherwise, return the local file path if it exists |
790
|
|
|
|
|
|
|
elsif ( -f $l && -r _) { |
791
|
0
|
|
|
|
|
0
|
$ThesiteURL = $ro_url; |
792
|
0
|
|
|
|
|
0
|
return $l; |
793
|
|
|
|
|
|
|
} |
794
|
|
|
|
|
|
|
# If we can't find it, but there is a compressed version |
795
|
|
|
|
|
|
|
# of it, then decompress it |
796
|
|
|
|
|
|
|
elsif (-f "$l.gz") { |
797
|
0
|
0
|
|
|
|
0
|
$self->debug("found compressed $l.gz") if $CPAN::DEBUG; |
798
|
0
|
|
|
|
|
0
|
eval { CPAN::Tarzip->new("$l.gz")->gunzip($aslocal) }; |
|
0
|
|
|
|
|
0
|
|
799
|
0
|
0
|
|
|
|
0
|
if ( -f $aslocal) { |
800
|
0
|
|
|
|
|
0
|
$ThesiteURL = $ro_url; |
801
|
0
|
|
|
|
|
0
|
return $aslocal; |
802
|
|
|
|
|
|
|
} |
803
|
|
|
|
|
|
|
else { |
804
|
0
|
0
|
|
|
|
0
|
$CPAN::Frontend->mywarn("Error decompressing '$l': $@\n") |
805
|
|
|
|
|
|
|
if $@; |
806
|
0
|
|
|
|
|
0
|
return; |
807
|
|
|
|
|
|
|
} |
808
|
|
|
|
|
|
|
} |
809
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->mywarn("Could not find '$l'\n"); |
810
|
|
|
|
|
|
|
} |
811
|
0
|
0
|
|
|
|
0
|
$self->debug("it was not a file URL") if $CPAN::DEBUG; |
812
|
0
|
0
|
0
|
|
|
0
|
if ($CPAN::META->has_usable('LWP')) { |
|
|
0
|
|
|
|
|
|
813
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->myprint("Fetching with LWP:\n$url\n"); |
814
|
0
|
0
|
|
|
|
0
|
unless ($Ua) { |
815
|
0
|
|
|
|
|
0
|
CPAN::LWP::UserAgent->config; |
816
|
0
|
|
|
|
|
0
|
eval { $Ua = CPAN::LWP::UserAgent->new; }; |
|
0
|
|
|
|
|
0
|
|
817
|
0
|
0
|
|
|
|
0
|
if ($@) { |
818
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->mywarn("CPAN::LWP::UserAgent->new dies with $@\n"); |
819
|
|
|
|
|
|
|
} |
820
|
|
|
|
|
|
|
} |
821
|
0
|
|
|
|
|
0
|
my $res = $Ua->mirror($url, $aslocal); |
822
|
0
|
0
|
|
|
|
0
|
if ($res->is_success) { |
|
|
0
|
|
|
|
|
|
823
|
0
|
|
|
|
|
0
|
$ThesiteURL = $ro_url; |
824
|
0
|
|
|
|
|
0
|
my $now = time; |
825
|
0
|
|
|
|
|
0
|
utime $now, $now, $aslocal; # download time is more |
826
|
|
|
|
|
|
|
# important than upload |
827
|
|
|
|
|
|
|
# time |
828
|
0
|
|
|
|
|
0
|
return $aslocal; |
829
|
|
|
|
|
|
|
} elsif ($url !~ /\.gz(?!\n)\Z/) { |
830
|
0
|
|
|
|
|
0
|
my $gzurl = "$url.gz"; |
831
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->myprint("Fetching with LWP:\n$gzurl\n"); |
832
|
0
|
|
|
|
|
0
|
$res = $Ua->mirror($gzurl, "$aslocal.gz"); |
833
|
0
|
0
|
|
|
|
0
|
if ($res->is_success) { |
834
|
0
|
0
|
|
|
|
0
|
if (eval {CPAN::Tarzip->new("$aslocal.gz")->gunzip($aslocal)}) { |
|
0
|
|
|
|
|
0
|
|
835
|
0
|
|
|
|
|
0
|
$ThesiteURL = $ro_url; |
836
|
0
|
|
|
|
|
0
|
return $aslocal; |
837
|
|
|
|
|
|
|
} |
838
|
|
|
|
|
|
|
} |
839
|
|
|
|
|
|
|
} else { |
840
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->myprint(sprintf( |
841
|
|
|
|
|
|
|
"LWP failed with code[%s] message[%s]\n", |
842
|
|
|
|
|
|
|
$res->code, |
843
|
|
|
|
|
|
|
$res->message, |
844
|
|
|
|
|
|
|
)); |
845
|
|
|
|
|
|
|
# Alan Burlison informed me that in firewall environments |
846
|
|
|
|
|
|
|
# Net::FTP can still succeed where LWP fails. So we do not |
847
|
|
|
|
|
|
|
# skip Net::FTP anymore when LWP is available. |
848
|
|
|
|
|
|
|
} |
849
|
|
|
|
|
|
|
} elsif ($url =~ /^http:/i && $CPAN::META->has_usable('HTTP::Tiny')) { |
850
|
0
|
|
|
|
|
0
|
require CPAN::HTTP::Client; |
851
|
|
|
|
|
|
|
my $chc = CPAN::HTTP::Client->new( |
852
|
|
|
|
|
|
|
proxy => $CPAN::Config->{http_proxy} || $ENV{http_proxy}, |
853
|
|
|
|
|
|
|
no_proxy => $CPAN::Config->{no_proxy} || $ENV{no_proxy}, |
854
|
0
|
|
0
|
|
|
0
|
); |
|
|
|
0
|
|
|
|
|
855
|
0
|
0
|
|
|
|
0
|
for my $try ( $url, ( $url !~ /\.gz(?!\n)\Z/ ? "$url.gz" : () ) ) { |
856
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->myprint("Fetching with HTTP::Tiny:\n$try\n"); |
857
|
0
|
|
|
|
|
0
|
my $res = eval { $chc->mirror($try, $aslocal) }; |
|
0
|
|
|
|
|
0
|
|
858
|
0
|
0
|
0
|
|
|
0
|
if ( $res && $res->{success} ) { |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
859
|
0
|
|
|
|
|
0
|
$ThesiteURL = $ro_url; |
860
|
0
|
|
|
|
|
0
|
my $now = time; |
861
|
0
|
|
|
|
|
0
|
utime $now, $now, $aslocal; # download time is more |
862
|
|
|
|
|
|
|
# important than upload |
863
|
|
|
|
|
|
|
# time |
864
|
0
|
|
|
|
|
0
|
return $aslocal; |
865
|
|
|
|
|
|
|
} |
866
|
|
|
|
|
|
|
elsif ( $res && $res->{status} ne '599') { |
867
|
|
|
|
|
|
|
$CPAN::Frontend->myprint(sprintf( |
868
|
|
|
|
|
|
|
"HTTP::Tiny failed with code[%s] message[%s]\n", |
869
|
|
|
|
|
|
|
$res->{status}, |
870
|
|
|
|
|
|
|
$res->{reason}, |
871
|
|
|
|
|
|
|
) |
872
|
0
|
|
|
|
|
0
|
); |
873
|
|
|
|
|
|
|
} |
874
|
|
|
|
|
|
|
elsif ( $res && $res->{status} eq '599') { |
875
|
|
|
|
|
|
|
$CPAN::Frontend->myprint(sprintf( |
876
|
|
|
|
|
|
|
"HTTP::Tiny failed with an internal error: %s\n", |
877
|
|
|
|
|
|
|
$res->{content}, |
878
|
|
|
|
|
|
|
) |
879
|
0
|
|
|
|
|
0
|
); |
880
|
|
|
|
|
|
|
} |
881
|
|
|
|
|
|
|
else { |
882
|
0
|
|
0
|
|
|
0
|
my $err = $@ || 'Unknown error'; |
883
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->myprint(sprintf( |
884
|
|
|
|
|
|
|
"Error downloading with HTTP::Tiny: %s\n", $err |
885
|
|
|
|
|
|
|
) |
886
|
|
|
|
|
|
|
); |
887
|
|
|
|
|
|
|
} |
888
|
|
|
|
|
|
|
} |
889
|
|
|
|
|
|
|
} |
890
|
0
|
0
|
|
|
|
0
|
return if $CPAN::Signal; |
891
|
0
|
0
|
|
|
|
0
|
if ($url =~ m|^ftp://(.*?)/(.*)/(.*)|) { |
892
|
|
|
|
|
|
|
# that's the nice and easy way thanks to Graham |
893
|
0
|
0
|
|
|
|
0
|
$self->debug("recognized ftp") if $CPAN::DEBUG; |
894
|
0
|
|
|
|
|
0
|
my($host,$dir,$getfile) = ($1,$2,$3); |
895
|
0
|
0
|
|
|
|
0
|
if ($CPAN::META->has_usable('Net::FTP')) { |
896
|
0
|
|
|
|
|
0
|
$dir =~ s|/+|/|g; |
897
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->myprint("Fetching with Net::FTP:\n$url\n"); |
898
|
0
|
0
|
|
|
|
0
|
$self->debug("getfile[$getfile]dir[$dir]host[$host]" . |
899
|
|
|
|
|
|
|
"aslocal[$aslocal]") if $CPAN::DEBUG; |
900
|
0
|
0
|
|
|
|
0
|
if (CPAN::FTP->ftp_get($host,$dir,$getfile,$aslocal)) { |
901
|
0
|
|
|
|
|
0
|
$ThesiteURL = $ro_url; |
902
|
0
|
|
|
|
|
0
|
return $aslocal; |
903
|
|
|
|
|
|
|
} |
904
|
0
|
0
|
|
|
|
0
|
if ($aslocal !~ /\.gz(?!\n)\Z/) { |
905
|
0
|
|
|
|
|
0
|
my $gz = "$aslocal.gz"; |
906
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->myprint("Fetching with Net::FTP\n$url.gz\n"); |
907
|
0
|
0
|
0
|
|
|
0
|
if (CPAN::FTP->ftp_get($host, |
908
|
|
|
|
|
|
|
$dir, |
909
|
|
|
|
|
|
|
"$getfile.gz", |
910
|
|
|
|
|
|
|
$gz) && |
911
|
0
|
|
|
|
|
0
|
eval{CPAN::Tarzip->new($gz)->gunzip($aslocal)} |
912
|
|
|
|
|
|
|
) { |
913
|
0
|
|
|
|
|
0
|
$ThesiteURL = $ro_url; |
914
|
0
|
|
|
|
|
0
|
return $aslocal; |
915
|
|
|
|
|
|
|
} |
916
|
|
|
|
|
|
|
} |
917
|
|
|
|
|
|
|
# next HOSTEASY; |
918
|
|
|
|
|
|
|
} else { |
919
|
0
|
0
|
|
|
|
0
|
CPAN->debug("Net::FTP does not count as usable atm") if $CPAN::DEBUG; |
920
|
|
|
|
|
|
|
} |
921
|
|
|
|
|
|
|
} |
922
|
0
|
0
|
0
|
|
|
0
|
if ( |
923
|
|
|
|
|
|
|
UNIVERSAL::can($ro_url,"text") |
924
|
|
|
|
|
|
|
and |
925
|
|
|
|
|
|
|
$ro_url->{FROM} eq "USER" |
926
|
|
|
|
|
|
|
) { |
927
|
|
|
|
|
|
|
##address #17973: default URLs should not try to override |
928
|
|
|
|
|
|
|
##user-defined URLs just because LWP is not available |
929
|
0
|
|
|
|
|
0
|
my $ret = $self->hostdlhard([$ro_url],$file,$aslocal,$stats); |
930
|
0
|
0
|
|
|
|
0
|
return $ret if $ret; |
931
|
|
|
|
|
|
|
} |
932
|
0
|
0
|
|
|
|
0
|
return if $CPAN::Signal; |
933
|
|
|
|
|
|
|
} |
934
|
|
|
|
|
|
|
} |
935
|
|
|
|
|
|
|
|
936
|
|
|
|
|
|
|
# package CPAN::FTP; |
937
|
|
|
|
|
|
|
sub hostdlhard { |
938
|
0
|
|
|
0
|
0
|
0
|
my($self,$host_seq,$file,$aslocal,$stats) = @_; |
939
|
|
|
|
|
|
|
|
940
|
|
|
|
|
|
|
# Came back if Net::FTP couldn't establish connection (or |
941
|
|
|
|
|
|
|
# failed otherwise) Maybe they are behind a firewall, but they |
942
|
|
|
|
|
|
|
# gave us a socksified (or other) ftp program... |
943
|
|
|
|
|
|
|
|
944
|
0
|
|
|
|
|
0
|
my($ro_url); |
945
|
0
|
|
0
|
|
|
0
|
my($devnull) = $CPAN::Config->{devnull} || ""; |
946
|
|
|
|
|
|
|
# < /dev/null "; |
947
|
0
|
|
|
|
|
0
|
my($aslocal_dir) = dirname($aslocal); |
948
|
0
|
|
|
|
|
0
|
mkpath($aslocal_dir); |
949
|
0
|
|
|
|
|
0
|
my $some_dl_success = 0; |
950
|
0
|
|
|
|
|
0
|
my $any_attempt = 0; |
951
|
0
|
|
|
|
|
0
|
HOSTHARD: for $ro_url (@$host_seq) { |
952
|
0
|
|
|
|
|
0
|
$self->_set_attempt($stats,"dlhard",$ro_url); |
953
|
0
|
|
|
|
|
0
|
my $url = "$ro_url$file"; |
954
|
0
|
|
|
|
|
0
|
my($proto,$host,$dir,$getfile); |
955
|
|
|
|
|
|
|
|
956
|
|
|
|
|
|
|
# Courtesy Mark Conty mark_conty@cargill.com change from |
957
|
|
|
|
|
|
|
# if ($url =~ m|^ftp://(.*?)/(.*)/(.*)|) { |
958
|
|
|
|
|
|
|
# to |
959
|
0
|
0
|
|
|
|
0
|
if ($url =~ m|^([^:]+)://(.*?)/(.*)/(.*)|) { |
960
|
|
|
|
|
|
|
# proto not yet used |
961
|
0
|
|
|
|
|
0
|
($proto,$host,$dir,$getfile) = ($1,$2,$3,$4); |
962
|
|
|
|
|
|
|
} else { |
963
|
0
|
|
|
|
|
0
|
next HOSTHARD; # who said, we could ftp anything except ftp? |
964
|
|
|
|
|
|
|
} |
965
|
0
|
0
|
|
|
|
0
|
next HOSTHARD if $proto eq "file"; # file URLs would have had |
966
|
|
|
|
|
|
|
# success above. Likely a bogus URL |
967
|
|
|
|
|
|
|
|
968
|
|
|
|
|
|
|
# making at least one attempt against a host |
969
|
0
|
|
|
|
|
0
|
$any_attempt++; |
970
|
|
|
|
|
|
|
|
971
|
0
|
0
|
|
|
|
0
|
$self->debug("localizing funkyftpwise[$url]") if $CPAN::DEBUG; |
972
|
|
|
|
|
|
|
|
973
|
|
|
|
|
|
|
# Try the most capable first and leave ncftp* for last as it only |
974
|
|
|
|
|
|
|
# does FTP. |
975
|
0
|
|
|
|
|
0
|
my $proxy_vars = $self->_proxy_vars($ro_url); |
976
|
0
|
|
|
|
|
0
|
DLPRG: for my $f (qw(curl wget lynx ncftpget ncftp)) { |
977
|
0
|
|
|
|
|
0
|
my $funkyftp = CPAN::HandleConfig->safe_quote($CPAN::Config->{$f}); |
978
|
0
|
0
|
|
|
|
0
|
next DLPRG unless defined $funkyftp; |
979
|
0
|
0
|
|
|
|
0
|
next DLPRG if $funkyftp =~ /^\s*$/; |
980
|
|
|
|
|
|
|
|
981
|
0
|
|
|
|
|
0
|
my($src_switch) = ""; |
982
|
0
|
|
|
|
|
0
|
my($chdir) = ""; |
983
|
0
|
|
|
|
|
0
|
my($stdout_redir) = " > \"$aslocal\""; |
984
|
0
|
0
|
|
|
|
0
|
if ($f eq "lynx") { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
985
|
0
|
|
|
|
|
0
|
$src_switch = " -source"; |
986
|
|
|
|
|
|
|
} elsif ($f eq "ncftp") { |
987
|
0
|
0
|
|
|
|
0
|
next DLPRG unless $url =~ m{\Aftp://}; |
988
|
0
|
|
|
|
|
0
|
$src_switch = " -c"; |
989
|
|
|
|
|
|
|
} elsif ($f eq "wget") { |
990
|
0
|
|
|
|
|
0
|
$src_switch = " -O \"$aslocal\""; |
991
|
0
|
|
|
|
|
0
|
$stdout_redir = ""; |
992
|
|
|
|
|
|
|
} elsif ($f eq 'curl') { |
993
|
0
|
|
|
|
|
0
|
$src_switch = ' -L -f -s -S --netrc-optional'; |
994
|
0
|
0
|
|
|
|
0
|
if ($proxy_vars->{http_proxy}) { |
995
|
0
|
|
|
|
|
0
|
$src_switch .= qq{ -U "$proxy_vars->{proxy_user}:$proxy_vars->{proxy_pass}" -x "$proxy_vars->{http_proxy}"}; |
996
|
|
|
|
|
|
|
} |
997
|
|
|
|
|
|
|
} elsif ($f eq "ncftpget") { |
998
|
0
|
0
|
|
|
|
0
|
next DLPRG unless $url =~ m{\Aftp://}; |
999
|
0
|
|
|
|
|
0
|
$chdir = "cd $aslocal_dir && "; |
1000
|
0
|
|
|
|
|
0
|
$stdout_redir = ""; |
1001
|
|
|
|
|
|
|
} |
1002
|
|
|
|
|
|
|
$CPAN::Frontend->myprint( |
1003
|
0
|
|
|
|
|
0
|
qq[ |
1004
|
|
|
|
|
|
|
Trying with |
1005
|
|
|
|
|
|
|
$funkyftp$src_switch |
1006
|
|
|
|
|
|
|
to get |
1007
|
|
|
|
|
|
|
$url |
1008
|
|
|
|
|
|
|
]); |
1009
|
0
|
|
|
|
|
0
|
my($system) = |
1010
|
|
|
|
|
|
|
"$chdir$funkyftp$src_switch \"$url\" $devnull$stdout_redir"; |
1011
|
0
|
0
|
|
|
|
0
|
$self->debug("system[$system]") if $CPAN::DEBUG; |
1012
|
0
|
|
|
|
|
0
|
my($wstatus) = system($system); |
1013
|
0
|
0
|
|
|
|
0
|
if ($f eq "lynx") { |
1014
|
|
|
|
|
|
|
# lynx returns 0 when it fails somewhere |
1015
|
0
|
0
|
|
|
|
0
|
if (-s $aslocal) { |
1016
|
0
|
|
|
|
|
0
|
my $content = do { local *FH; |
|
0
|
|
|
|
|
0
|
|
1017
|
0
|
0
|
|
|
|
0
|
open FH, $aslocal or die; |
1018
|
0
|
|
|
|
|
0
|
local $/; |
1019
|
0
|
|
|
|
|
0
|
}; |
1020
|
0
|
0
|
|
|
|
0
|
if ($content =~ /^<.*([45]|Error [45])/si) { |
1021
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->mywarn(qq{ |
1022
|
|
|
|
|
|
|
No success, the file that lynx has downloaded looks like an error message: |
1023
|
|
|
|
|
|
|
$content |
1024
|
|
|
|
|
|
|
}); |
1025
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->mysleep(1); |
1026
|
0
|
|
|
|
|
0
|
next DLPRG; |
1027
|
|
|
|
|
|
|
} |
1028
|
0
|
|
|
|
|
0
|
$some_dl_success++; |
1029
|
|
|
|
|
|
|
} else { |
1030
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->myprint(qq{ |
1031
|
|
|
|
|
|
|
No success, the file that lynx has downloaded is an empty file. |
1032
|
|
|
|
|
|
|
}); |
1033
|
0
|
|
|
|
|
0
|
next DLPRG; |
1034
|
|
|
|
|
|
|
} |
1035
|
|
|
|
|
|
|
} |
1036
|
0
|
0
|
|
|
|
0
|
if ($wstatus == 0) { |
1037
|
0
|
0
|
|
|
|
0
|
if (-s $aslocal) { |
1038
|
|
|
|
|
|
|
# Looks good |
1039
|
0
|
|
|
|
|
0
|
$some_dl_success++; |
1040
|
|
|
|
|
|
|
} |
1041
|
0
|
|
|
|
|
0
|
$ThesiteURL = $ro_url; |
1042
|
0
|
|
|
|
|
0
|
return $aslocal; |
1043
|
|
|
|
|
|
|
} else { |
1044
|
0
|
|
|
|
|
0
|
my $estatus = $wstatus >> 8; |
1045
|
0
|
0
|
|
|
|
0
|
my $size = -f $aslocal ? |
1046
|
|
|
|
|
|
|
", left\n$aslocal with size ".-s _ : |
1047
|
|
|
|
|
|
|
"\nWarning: expected file [$aslocal] doesn't exist"; |
1048
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->myprint(qq{ |
1049
|
|
|
|
|
|
|
Function system("$system") |
1050
|
|
|
|
|
|
|
returned status $estatus (wstat $wstatus)$size |
1051
|
|
|
|
|
|
|
}); |
1052
|
|
|
|
|
|
|
} |
1053
|
0
|
0
|
|
|
|
0
|
return if $CPAN::Signal; |
1054
|
|
|
|
|
|
|
} # download/transfer programs (DLPRG) |
1055
|
|
|
|
|
|
|
} # host |
1056
|
0
|
0
|
|
|
|
0
|
return unless $any_attempt; |
1057
|
0
|
0
|
|
|
|
0
|
if ($some_dl_success) { |
1058
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->mywarn("Warning: doesn't seem we had substantial success downloading '$aslocal'. Don't know how to proceed.\n"); |
1059
|
|
|
|
|
|
|
} else { |
1060
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->mywarn("Warning: no success downloading '$aslocal'. Giving up on it.\n"); |
1061
|
|
|
|
|
|
|
} |
1062
|
0
|
|
|
|
|
0
|
return; |
1063
|
|
|
|
|
|
|
} |
1064
|
|
|
|
|
|
|
|
1065
|
|
|
|
|
|
|
#-> CPAN::FTP::_proxy_vars |
1066
|
|
|
|
|
|
|
sub _proxy_vars { |
1067
|
2
|
|
|
2
|
|
6738
|
my($self,$url) = @_; |
1068
|
2
|
|
|
|
|
5
|
my $ret = +{}; |
1069
|
2
|
|
33
|
|
|
9
|
my $http_proxy = $CPAN::Config->{'http_proxy'} || $ENV{'http_proxy'}; |
1070
|
2
|
50
|
|
|
|
7
|
if ($http_proxy) { |
1071
|
2
|
|
|
|
|
19
|
my($host) = $url =~ m|://([^/:]+)|; |
1072
|
2
|
|
|
|
|
7
|
my $want_proxy = 1; |
1073
|
2
|
|
0
|
|
|
10
|
my $noproxy = $CPAN::Config->{'no_proxy'} || $ENV{'no_proxy'} || ""; |
1074
|
2
|
|
|
|
|
8
|
my @noproxy = split /\s*,\s*/, $noproxy; |
1075
|
2
|
50
|
|
|
|
7
|
if ($host) { |
1076
|
2
|
|
|
|
|
10
|
DOMAIN: for my $domain (@noproxy) { |
1077
|
2
|
100
|
|
|
|
46
|
if ($host =~ /\Q$domain\E$/) { # cf. LWP::UserAgent |
1078
|
1
|
|
|
|
|
5
|
$want_proxy = 0; |
1079
|
1
|
|
|
|
|
4
|
last DOMAIN; |
1080
|
|
|
|
|
|
|
} |
1081
|
|
|
|
|
|
|
} |
1082
|
|
|
|
|
|
|
} else { |
1083
|
0
|
|
|
|
|
0
|
$CPAN::Frontend->mywarn(" Could not determine host from http_proxy '$http_proxy'\n"); |
1084
|
|
|
|
|
|
|
} |
1085
|
2
|
100
|
|
|
|
6
|
if ($want_proxy) { |
1086
|
1
|
|
|
|
|
27
|
my($user, $pass) = |
1087
|
|
|
|
|
|
|
CPAN::HTTP::Credentials->get_proxy_credentials(); |
1088
|
1
|
|
|
|
|
7
|
$ret = { |
1089
|
|
|
|
|
|
|
proxy_user => $user, |
1090
|
|
|
|
|
|
|
proxy_pass => $pass, |
1091
|
|
|
|
|
|
|
http_proxy => $http_proxy |
1092
|
|
|
|
|
|
|
}; |
1093
|
|
|
|
|
|
|
} |
1094
|
|
|
|
|
|
|
} |
1095
|
2
|
|
|
|
|
7
|
return $ret; |
1096
|
|
|
|
|
|
|
} |
1097
|
|
|
|
|
|
|
|
1098
|
|
|
|
|
|
|
# package CPAN::FTP; |
1099
|
|
|
|
|
|
|
sub hostdlhardest { |
1100
|
0
|
|
|
0
|
0
|
|
my($self,$host_seq,$file,$aslocal,$stats) = @_; |
1101
|
|
|
|
|
|
|
|
1102
|
0
|
0
|
|
|
|
|
return unless @$host_seq; |
1103
|
0
|
|
|
|
|
|
my($ro_url); |
1104
|
0
|
|
|
|
|
|
my($aslocal_dir) = dirname($aslocal); |
1105
|
0
|
|
|
|
|
|
mkpath($aslocal_dir); |
1106
|
0
|
|
|
|
|
|
my $ftpbin = $CPAN::Config->{ftp}; |
1107
|
0
|
0
|
0
|
|
|
|
unless ($ftpbin && length $ftpbin && MM->maybe_command($ftpbin)) { |
|
|
|
0
|
|
|
|
|
1108
|
0
|
|
|
|
|
|
$CPAN::Frontend->myprint("No external ftp command available\n\n"); |
1109
|
0
|
|
|
|
|
|
return; |
1110
|
|
|
|
|
|
|
} |
1111
|
0
|
|
|
|
|
|
$CPAN::Frontend->mywarn(qq{ |
1112
|
|
|
|
|
|
|
As a last resort we now switch to the external ftp command '$ftpbin' |
1113
|
|
|
|
|
|
|
to get '$aslocal'. |
1114
|
|
|
|
|
|
|
|
1115
|
|
|
|
|
|
|
Doing so often leads to problems that are hard to diagnose. |
1116
|
|
|
|
|
|
|
|
1117
|
|
|
|
|
|
|
If you're the victim of such problems, please consider unsetting the |
1118
|
|
|
|
|
|
|
ftp config variable with |
1119
|
|
|
|
|
|
|
|
1120
|
|
|
|
|
|
|
o conf ftp "" |
1121
|
|
|
|
|
|
|
o conf commit |
1122
|
|
|
|
|
|
|
|
1123
|
|
|
|
|
|
|
}); |
1124
|
0
|
|
|
|
|
|
$CPAN::Frontend->mysleep(2); |
1125
|
0
|
|
|
|
|
|
HOSTHARDEST: for $ro_url (@$host_seq) { |
1126
|
0
|
|
|
|
|
|
$self->_set_attempt($stats,"dlhardest",$ro_url); |
1127
|
0
|
|
|
|
|
|
my $url = "$ro_url$file"; |
1128
|
0
|
0
|
|
|
|
|
$self->debug("localizing ftpwise[$url]") if $CPAN::DEBUG; |
1129
|
0
|
0
|
|
|
|
|
unless ($url =~ m|^ftp://(.*?)/(.*)/(.*)|) { |
1130
|
0
|
|
|
|
|
|
next; |
1131
|
|
|
|
|
|
|
} |
1132
|
0
|
|
|
|
|
|
my($host,$dir,$getfile) = ($1,$2,$3); |
1133
|
0
|
|
|
|
|
|
my $timestamp = 0; |
1134
|
0
|
|
|
|
|
|
my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime, |
1135
|
|
|
|
|
|
|
$ctime,$blksize,$blocks) = stat($aslocal); |
1136
|
0
|
|
0
|
|
|
|
$timestamp = $mtime ||= 0; |
1137
|
0
|
|
|
|
|
|
my($netrc) = CPAN::FTP::netrc->new; |
1138
|
0
|
|
|
|
|
|
my($netrcfile) = $netrc->netrc; |
1139
|
0
|
0
|
|
|
|
|
my($verbose) = $CPAN::DEBUG{'FTP'} & $CPAN::DEBUG ? " -v" : ""; |
1140
|
0
|
|
|
|
|
|
my $targetfile = File::Basename::basename($aslocal); |
1141
|
0
|
|
|
|
|
|
my(@dialog); |
1142
|
0
|
|
|
|
|
|
push( |
1143
|
|
|
|
|
|
|
@dialog, |
1144
|
|
|
|
|
|
|
"lcd $aslocal_dir", |
1145
|
|
|
|
|
|
|
"cd /", |
1146
|
|
|
|
|
|
|
map("cd $_", split /\//, $dir), # RFC 1738 |
1147
|
|
|
|
|
|
|
"bin", |
1148
|
|
|
|
|
|
|
"passive", |
1149
|
|
|
|
|
|
|
"get $getfile $targetfile", |
1150
|
|
|
|
|
|
|
"quit" |
1151
|
|
|
|
|
|
|
); |
1152
|
0
|
0
|
0
|
|
|
|
if (! $netrcfile) { |
|
|
0
|
|
|
|
|
|
1153
|
0
|
0
|
|
|
|
|
CPAN->debug("No ~/.netrc file found") if $CPAN::DEBUG; |
1154
|
|
|
|
|
|
|
} elsif ($netrc->hasdefault || $netrc->contains($host)) { |
1155
|
0
|
0
|
|
|
|
|
CPAN->debug(sprintf("hasdef[%d]cont($host)[%d]", |
1156
|
|
|
|
|
|
|
$netrc->hasdefault, |
1157
|
|
|
|
|
|
|
$netrc->contains($host))) if $CPAN::DEBUG; |
1158
|
0
|
0
|
|
|
|
|
if ($netrc->protected) { |
1159
|
0
|
|
|
|
|
|
my $dialog = join "", map { " $_\n" } @dialog; |
|
0
|
|
|
|
|
|
|
1160
|
0
|
|
|
|
|
|
my $netrc_explain; |
1161
|
0
|
0
|
|
|
|
|
if ($netrc->contains($host)) { |
1162
|
0
|
|
|
|
|
|
$netrc_explain = "Relying that your .netrc entry for '$host' ". |
1163
|
|
|
|
|
|
|
"manages the login"; |
1164
|
|
|
|
|
|
|
} else { |
1165
|
0
|
|
|
|
|
|
$netrc_explain = "Relying that your default .netrc entry ". |
1166
|
|
|
|
|
|
|
"manages the login"; |
1167
|
|
|
|
|
|
|
} |
1168
|
0
|
|
|
|
|
|
$CPAN::Frontend->myprint(qq{ |
1169
|
|
|
|
|
|
|
Trying with external ftp to get |
1170
|
|
|
|
|
|
|
'$url' |
1171
|
|
|
|
|
|
|
$netrc_explain |
1172
|
|
|
|
|
|
|
Sending the dialog |
1173
|
|
|
|
|
|
|
$dialog |
1174
|
|
|
|
|
|
|
} |
1175
|
|
|
|
|
|
|
); |
1176
|
0
|
|
|
|
|
|
$self->talk_ftp("$ftpbin$verbose $host", |
1177
|
|
|
|
|
|
|
@dialog); |
1178
|
0
|
|
|
|
|
|
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, |
1179
|
|
|
|
|
|
|
$atime,$mtime,$ctime,$blksize,$blocks) = stat($aslocal); |
1180
|
0
|
|
0
|
|
|
|
$mtime ||= 0; |
1181
|
0
|
0
|
|
|
|
|
if ($mtime > $timestamp) { |
1182
|
0
|
|
|
|
|
|
$CPAN::Frontend->myprint("GOT $aslocal\n"); |
1183
|
0
|
|
|
|
|
|
$ThesiteURL = $ro_url; |
1184
|
0
|
|
|
|
|
|
return $aslocal; |
1185
|
|
|
|
|
|
|
} else { |
1186
|
0
|
|
|
|
|
|
$CPAN::Frontend->myprint("Hmm... Still failed!\n"); |
1187
|
|
|
|
|
|
|
} |
1188
|
0
|
0
|
|
|
|
|
return if $CPAN::Signal; |
1189
|
|
|
|
|
|
|
} else { |
1190
|
0
|
|
|
|
|
|
$CPAN::Frontend->mywarn(qq{Your $netrcfile is not }. |
1191
|
|
|
|
|
|
|
qq{correctly protected.\n}); |
1192
|
|
|
|
|
|
|
} |
1193
|
|
|
|
|
|
|
} else { |
1194
|
0
|
|
|
|
|
|
$CPAN::Frontend->mywarn("Your ~/.netrc neither contains $host |
1195
|
|
|
|
|
|
|
nor does it have a default entry\n"); |
1196
|
|
|
|
|
|
|
} |
1197
|
|
|
|
|
|
|
|
1198
|
|
|
|
|
|
|
# OK, they don't have a valid ~/.netrc. Use 'ftp -n' |
1199
|
|
|
|
|
|
|
# then and login manually to host, using e-mail as |
1200
|
|
|
|
|
|
|
# password. |
1201
|
0
|
|
|
|
|
|
$CPAN::Frontend->myprint(qq{Issuing "$ftpbin$verbose -n"\n}); |
1202
|
0
|
|
|
|
|
|
unshift( |
1203
|
|
|
|
|
|
|
@dialog, |
1204
|
|
|
|
|
|
|
"open $host", |
1205
|
|
|
|
|
|
|
"user anonymous $Config::Config{'cf_email'}" |
1206
|
|
|
|
|
|
|
); |
1207
|
0
|
|
|
|
|
|
my $dialog = join "", map { " $_\n" } @dialog; |
|
0
|
|
|
|
|
|
|
1208
|
0
|
|
|
|
|
|
$CPAN::Frontend->myprint(qq{ |
1209
|
|
|
|
|
|
|
Trying with external ftp to get |
1210
|
|
|
|
|
|
|
$url |
1211
|
|
|
|
|
|
|
Sending the dialog |
1212
|
|
|
|
|
|
|
$dialog |
1213
|
|
|
|
|
|
|
} |
1214
|
|
|
|
|
|
|
); |
1215
|
0
|
|
|
|
|
|
$self->talk_ftp("$ftpbin$verbose -n", @dialog); |
1216
|
0
|
|
|
|
|
|
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, |
1217
|
|
|
|
|
|
|
$atime,$mtime,$ctime,$blksize,$blocks) = stat($aslocal); |
1218
|
0
|
|
0
|
|
|
|
$mtime ||= 0; |
1219
|
0
|
0
|
|
|
|
|
if ($mtime > $timestamp) { |
1220
|
0
|
|
|
|
|
|
$CPAN::Frontend->myprint("GOT $aslocal\n"); |
1221
|
0
|
|
|
|
|
|
$ThesiteURL = $ro_url; |
1222
|
0
|
|
|
|
|
|
return $aslocal; |
1223
|
|
|
|
|
|
|
} else { |
1224
|
0
|
|
|
|
|
|
$CPAN::Frontend->myprint("Bad luck... Still failed!\n"); |
1225
|
|
|
|
|
|
|
} |
1226
|
0
|
0
|
|
|
|
|
return if $CPAN::Signal; |
1227
|
0
|
|
|
|
|
|
$CPAN::Frontend->mywarn("Can't access URL $url.\n\n"); |
1228
|
0
|
|
|
|
|
|
$CPAN::Frontend->mysleep(2); |
1229
|
|
|
|
|
|
|
} # host |
1230
|
|
|
|
|
|
|
} |
1231
|
|
|
|
|
|
|
|
1232
|
|
|
|
|
|
|
# package CPAN::FTP; |
1233
|
|
|
|
|
|
|
sub talk_ftp { |
1234
|
0
|
|
|
0
|
0
|
|
my($self,$command,@dialog) = @_; |
1235
|
0
|
|
|
|
|
|
my $fh = FileHandle->new; |
1236
|
0
|
0
|
|
|
|
|
$fh->open("|$command") or die "Couldn't open ftp: $!"; |
1237
|
0
|
|
|
|
|
|
foreach (@dialog) { $fh->print("$_\n") } |
|
0
|
|
|
|
|
|
|
1238
|
0
|
|
|
|
|
|
$fh->close; # Wait for process to complete |
1239
|
0
|
|
|
|
|
|
my $wstatus = $?; |
1240
|
0
|
|
|
|
|
|
my $estatus = $wstatus >> 8; |
1241
|
0
|
0
|
|
|
|
|
$CPAN::Frontend->myprint(qq{ |
1242
|
|
|
|
|
|
|
Subprocess "|$command" |
1243
|
|
|
|
|
|
|
returned status $estatus (wstat $wstatus) |
1244
|
|
|
|
|
|
|
}) if $wstatus; |
1245
|
|
|
|
|
|
|
} |
1246
|
|
|
|
|
|
|
|
1247
|
|
|
|
|
|
|
# find2perl needs modularization, too, all the following is stolen |
1248
|
|
|
|
|
|
|
# from there |
1249
|
|
|
|
|
|
|
# CPAN::FTP::ls |
1250
|
|
|
|
|
|
|
sub ls { |
1251
|
0
|
|
|
0
|
0
|
|
my($self,$name) = @_; |
1252
|
0
|
|
|
|
|
|
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$sizemm, |
1253
|
|
|
|
|
|
|
$atime,$mtime,$ctime,$blksize,$blocks) = lstat($name); |
1254
|
|
|
|
|
|
|
|
1255
|
0
|
|
|
|
|
|
my($perms,%user,%group); |
1256
|
0
|
|
|
|
|
|
my $pname = $name; |
1257
|
|
|
|
|
|
|
|
1258
|
0
|
0
|
|
|
|
|
if ($blocks) { |
1259
|
0
|
|
|
|
|
|
$blocks = int(($blocks + 1) / 2); |
1260
|
|
|
|
|
|
|
} |
1261
|
|
|
|
|
|
|
else { |
1262
|
0
|
|
|
|
|
|
$blocks = int(($sizemm + 1023) / 1024); |
1263
|
|
|
|
|
|
|
} |
1264
|
|
|
|
|
|
|
|
1265
|
0
|
0
|
|
|
|
|
if (-f _) { $perms = '-'; } |
|
0
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
1266
|
0
|
|
|
|
|
|
elsif (-d _) { $perms = 'd'; } |
1267
|
0
|
|
|
|
|
|
elsif (-c _) { $perms = 'c'; $sizemm = &sizemm; } |
|
0
|
|
|
|
|
|
|
1268
|
0
|
|
|
|
|
|
elsif (-b _) { $perms = 'b'; $sizemm = &sizemm; } |
|
0
|
|
|
|
|
|
|
1269
|
0
|
|
|
|
|
|
elsif (-p _) { $perms = 'p'; } |
1270
|
0
|
|
|
|
|
|
elsif (-S _) { $perms = 's'; } |
1271
|
0
|
|
|
|
|
|
else { $perms = 'l'; $pname .= ' -> ' . readlink($_); } |
|
0
|
|
|
|
|
|
|
1272
|
|
|
|
|
|
|
|
1273
|
0
|
|
|
|
|
|
my(@rwx) = ('---','--x','-w-','-wx','r--','r-x','rw-','rwx'); |
1274
|
0
|
|
|
|
|
|
my(@moname) = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); |
1275
|
0
|
|
|
|
|
|
my $tmpmode = $mode; |
1276
|
0
|
|
|
|
|
|
my $tmp = $rwx[$tmpmode & 7]; |
1277
|
0
|
|
|
|
|
|
$tmpmode >>= 3; |
1278
|
0
|
|
|
|
|
|
$tmp = $rwx[$tmpmode & 7] . $tmp; |
1279
|
0
|
|
|
|
|
|
$tmpmode >>= 3; |
1280
|
0
|
|
|
|
|
|
$tmp = $rwx[$tmpmode & 7] . $tmp; |
1281
|
0
|
0
|
|
|
|
|
substr($tmp,2,1) =~ tr/-x/Ss/ if -u _; |
1282
|
0
|
0
|
|
|
|
|
substr($tmp,5,1) =~ tr/-x/Ss/ if -g _; |
1283
|
0
|
0
|
|
|
|
|
substr($tmp,8,1) =~ tr/-x/Tt/ if -k _; |
1284
|
0
|
|
|
|
|
|
$perms .= $tmp; |
1285
|
|
|
|
|
|
|
|
1286
|
0
|
|
0
|
|
|
|
my $user = $user{$uid} || $uid; # too lazy to implement lookup |
1287
|
0
|
|
0
|
|
|
|
my $group = $group{$gid} || $gid; |
1288
|
|
|
|
|
|
|
|
1289
|
0
|
|
|
|
|
|
my($sec,$min,$hour,$mday,$mon,$year) = localtime($mtime); |
1290
|
0
|
|
|
|
|
|
my($timeyear); |
1291
|
0
|
|
|
|
|
|
my($moname) = $moname[$mon]; |
1292
|
0
|
0
|
|
|
|
|
if (-M _ > 365.25 / 2) { |
1293
|
0
|
|
|
|
|
|
$timeyear = $year + 1900; |
1294
|
|
|
|
|
|
|
} |
1295
|
|
|
|
|
|
|
else { |
1296
|
0
|
|
|
|
|
|
$timeyear = sprintf("%02d:%02d", $hour, $min); |
1297
|
|
|
|
|
|
|
} |
1298
|
|
|
|
|
|
|
|
1299
|
0
|
|
|
|
|
|
sprintf "%5lu %4ld %-10s %2d %-8s %-8s %8s %s %2d %5s %s\n", |
1300
|
|
|
|
|
|
|
$ino, |
1301
|
|
|
|
|
|
|
$blocks, |
1302
|
|
|
|
|
|
|
$perms, |
1303
|
|
|
|
|
|
|
$nlink, |
1304
|
|
|
|
|
|
|
$user, |
1305
|
|
|
|
|
|
|
$group, |
1306
|
|
|
|
|
|
|
$sizemm, |
1307
|
|
|
|
|
|
|
$moname, |
1308
|
|
|
|
|
|
|
$mday, |
1309
|
|
|
|
|
|
|
$timeyear, |
1310
|
|
|
|
|
|
|
$pname; |
1311
|
|
|
|
|
|
|
} |
1312
|
|
|
|
|
|
|
|
1313
|
|
|
|
|
|
|
1; |