blib/lib/CPAN/FTP.pm

filter: Statementstmt 29.2% 205 / 702 Branchbran 16.0% 73 / 456 Conditioncond 14.4% 29 / 201 MC/DCmcdc 4.2% 5 / 119 Subroutinesub 70.9% 22 / 31 Podpod 0.0% 0 / 13 totaltotal 21.9% 334 / 1522 CC 315 SCAR 65.8
CC
315
Cov
23%
hostdleasy
2490.4
hostdl_2021
812.0
hostdlhard
812.0
CRAP 721.3
« blib/lib/CPAN/FirstTime.pm ↑ Summary blib/lib/CPAN.pm »
1 # -*- Mode: cperl; coding: utf-8; cperl-indent-level: 4 -*-
2 # vim: ts=4 sts=4 sw=4:
3 package CPAN::FTP;
4 24 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 24 ▶use Errno ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 24 ▶use Fcntl qw(:flock);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 24 ▶use File::Basename qw(dirname);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 24 ▶use File::Path qw(mkpath);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 24 ▶use CPAN::FTP::netrc;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 24 ▶use vars qw($connect_to_internet_ok $Ua $Thesite $ThesiteURL $Themethod);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 24 @CPAN::FTP::ISA = qw(CPAN::Debug);
14  
15 24 use vars qw(
16 $VERSION
17 24 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 24 $VERSION = "5.5018";
19  
20 sub _plus_append_open {
21 7 ▶ my($fh, $file) = @_;
Subroutine _plus_append_open: called CC=5 SCAR=25.2
22 7 my $parent_dir = dirname $file;
23 7 mkpath $parent_dir;
24 7 my($cnt);
25 7 ▶ until (open $fh, "+>>$file") {
Branch: 1 branch
BranchTrueFalseTotal
unless (open $fh, "+>>$file") 0 7 7
26 0 ▶ next if exists &Errno::EAGAIN && $! == &Errno::EAGAIN; # don't increment on EAGAIN
Branch: 1 branch
BranchTrueFalseTotal
if exists &Errno::EAGAIN and $! == &Errno::EAGAIN 0 0 0
Condition0%0/3
exists &Errno::EAGAIN and $! == &Errno::EAGAIN
!ll&&!rl&&r
000
MC/DC0%0/2
exists &Errno::EAGAIN and $! == &Errno::EAGAIN
exists &Errno::EAGAIN $! == &Errno::EAGAIN
Truth table0%0/3
A and B
A= exists &Errno::EAGAINB= $! == &Errno::EAGAIN
ABresult
0X0
100
111
27 0 ▶ $CPAN::Frontend->mydie("Could not open '$file' after 10000 tries: $!") if ++$cnt > 100000;
Branch: 1 branch
BranchTrueFalseTotal
if ++$cnt > 100000 0 0 0
28 0 sleep 0.0001;
29 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 7 ▶ my($self,$fh) = @_;
Subroutine _ftp_statistics: called CC=15 SCAR=43.5
37 7 my $ftpstats_size = $CPAN::Config->{ftpstats_size};
38 7 ▶ return if defined $ftpstats_size && $ftpstats_size <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ftpstats_size and $ftpstats_size <= 0 0 7 7
Condition33%1/3
defined $ftpstats_size and $ftpstats_size <= 0
!ll&&!rl&&r
700
MC/DC0%0/2
defined $ftpstats_size and $ftpstats_size <= 0
defined $ftpstats_size $ftpstats_size <= 0
Truth table33%1/3
A and B
A= defined $ftpstats_sizeB= $ftpstats_size <= 0
ABresult
0X0
100
111
39 7 ▶ my $locktype = $fh ? LOCK_EX : LOCK_SH;
Branch: 1 branch
BranchTrueFalseTotal
$fh ? : 0 7 7
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 7 ▶ $locktype = LOCK_SH if $^O eq "MSWin32";
Branch: 1 branch
BranchTrueFalseTotal
if $^O eq "MSWin32" 0 7 7
44  
45 7 ▶ $fh ||= FileHandle->new;
Condition33%1/3
$fh ||= "FileHandle"->new
l!l&&r!l&&!r
070
MC/DC0%0/2
$fh ||= "FileHandle"->new
$fh "FileHandle"->new
Truth table33%1/3
A ||= B
A= $fhB= "FileHandle"->new
ABresult
1X1
011
000
46 7 my $file = File::Spec->catfile($CPAN::Config->{cpan_home},"FTPstats.yml");
47 7 _plus_append_open($fh,$file);
48 7 my $sleep = 1;
49 7 my $waitstart;
50 7 ▶ while (!CPAN::_flock($fh, $locktype|LOCK_NB)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (CPAN::_flock($fh, $locktype | 4)) 0 7 7
51 0 ▶ $waitstart ||= localtime();
Condition0%0/3
$waitstart ||= localtime()
l!l&&r!l&&!r
000
MC/DC0%0/2
$waitstart ||= localtime()
$waitstart localtime()
Truth table0%0/3
A ||= B
A= $waitstartB= localtime()
ABresult
1X1
011
000
52 0 ▶ if ($sleep>3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sleep > 3) 0 0 0
53 0 my $now = localtime();
54 0 $CPAN::Frontend->mywarn("$now: waiting for read lock on '$file' (since $waitstart)\n");
55 }
56 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 ▶ if ($sleep <= 6) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sleep <= 6) { } 0 0 0
60 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 _plus_append_open($fh, $file);
64 }
65 }
66 7 my $stats = eval { CPAN->_yaml_loadfile($file, {loadblessed => 1}); };
67 7 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 7 7
68 0 ▶ if (ref $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $@) { } 0 0 0
69 0 ▶ if (ref $@ eq "CPAN::Exception::yaml_not_installed") {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $@ eq 'CPAN::Exception::yaml_not_installed') { } 0 0 0
elsif (ref $@ eq 'CPAN::Exception::yaml_process_error') { } 0 0 0
70 0 chomp $@;
71 0 $CPAN::Frontend->myprintonce("Warning (usually harmless): $@\n");
72 0 return;
73 } elsif (ref $@ eq "CPAN::Exception::yaml_process_error") {
74 0 my $time = time;
75 0 my $to = "$file.$time";
76 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 ▶ rename $file, $to or $CPAN::Frontend->mywarn("Could not rename '$file' to '$to': $!\n");
Branch: 1 branch
BranchTrueFalseTotal
rename $file, $to or $CPAN::Frontend->mywarn("Could not rename '${file}' to '${to}': $!\n") 0 0 0
81 0 return;
82 }
83 } else {
84 0 $CPAN::Frontend->mydie($@);
85 }
86 }
87 7 CPAN::_flock($fh, LOCK_UN);
88 7 return $stats->[0];
89 }
90  
91 #-> sub CPAN::FTP::_mytime
92 sub _mytime () {
93 76 ▶ if (CPAN->has_inst("Time::HiRes")) {
Subroutine _mytime: called CC=2 SCAR=8.1
Branch: 1 branch
BranchTrueFalseTotal
if ('CPAN'->has_inst('Time::HiRes')) { } 76 0 76
94 76 return Time::HiRes::time();
95 } else {
96 0 return time;
97 }
98 }
99  
100 #-> sub CPAN::FTP::_new_stats
101 sub _new_stats {
102 38 ▶ my($self,$file) = @_;
Subroutine _new_stats: called CC=1 SCAR=0.0
103 38 my $ret = {
104 file => $file,
105 attempts => [],
106 start => _mytime,
107 };
108 38 $ret;
109 }
110  
111 #-> sub CPAN::FTP::_add_to_statistics
112 sub _add_to_statistics {
113 38 ▶ my($self,$stats) = @_;
Subroutine _add_to_statistics: called CC=23 SCAR=61.1
114 38 my $yaml_module = CPAN::_yaml_module();
115 38 ▶ $self->debug("yaml_module[$yaml_module]") if $CPAN::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::DEBUG 0 38 38
116 38 ▶ if ($CPAN::META->has_inst($yaml_module)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CPAN::META->has_inst($yaml_module)) 0 38 38
117 0 $stats->{thesiteurl} = $ThesiteURL;
118 0 $stats->{end} = CPAN::FTP::_mytime();
119 0 my $fh = FileHandle->new;
120 0 my $time = time;
121 0 my $sdebug = 0;
122 0 my @debug;
123 0 ▶ @debug = $time if $sdebug;
Branch: 1 branch
BranchTrueFalseTotal
if $sdebug 0 0 0
124 0 my $fullstats = $self->_ftp_statistics($fh);
125 0 ▶ close $fh if $fh && defined(fileno($fh));
Branch: 1 branch
BranchTrueFalseTotal
if $fh and defined fileno $fh 0 0 0
Condition0%0/3
$fh and defined fileno $fh
!ll&&!rl&&r
000
MC/DC0%0/2
$fh and defined fileno $fh
$fh defined fileno $fh
Truth table0%0/3
A and B
A= $fhB= defined fileno $fh
ABresult
0X0
100
111
126 0 ▶ $fullstats->{history} ||= [];
Condition0%0/2
$fullstats->{"history"} ||= []
l!l
00
MC/DC0%0/1
$fullstats->{"history"} ||= []
$fullstats->{"history"}
Truth table0%0/2
A
A= $fullstats->{"history"}
Aresult
11
00
127 0 ▶ push @debug, scalar @{$fullstats->{history}} if $sdebug;
Branch: 1 branch
BranchTrueFalseTotal
if $sdebug 0 0 0
128 0 ▶ push @debug, time if $sdebug;
Branch: 1 branch
BranchTrueFalseTotal
if $sdebug 0 0 0
129 0 push @{$fullstats->{history}}, $stats;
130 # YAML.pm 0.62 is unacceptably slow with 999;
131 # YAML::Syck 0.82 has no noticable performance problem with 999;
132 0 my $ftpstats_size = $CPAN::Config->{ftpstats_size};
133 0 ▶ $ftpstats_size = 99 unless defined $ftpstats_size;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ftpstats_size 0 0 0
134 0 ▶ my $ftpstats_period = $CPAN::Config->{ftpstats_period} || 14;
Condition0%0/2
$CPAN::Config->{'ftpstats_period'} || 14
l!l
00
MC/DC0%0/1
$CPAN::Config->{'ftpstats_period'} || 14
$CPAN::Config->{'ftpstats_period'}
Truth table0%0/2
A
A= $CPAN::Config->{'ftpstats_period'}
Aresult
11
00
135 0 ▶ while (
Branch: 1 branch
BranchTrueFalseTotal
if (@{$fullstats->{"history"} or [];} and @{$fullstats->{"history"};} > $ftpstats_size || $time - $fullstats->{"history"}[0]{"start"} > 86400 * $ftpstats_period) 0 0 0
Condition0%0/3
@{$fullstats->{"history"} or [];} and @{$fullstats->{"history"};} > $ftpstats_size || $time - $fullstats->{"history"}[0]{"start"} > 86400 * $ftpstats_period
!ll&&!rl&&r
000
MC/DC0%0/2
@{$fullstats->{"history"} or [];} and @{$fullstats->{"history"};} > $ftpstats_size || $time - $fullstats->{"history"}[0]{"start"} > 86400 * $ftpstats_period
@{$fullstats->{"history"} or [];} @{$fullstats->{"history"};} > $ftpstats_size || $time - $fullstats->{"history"}[0]{"start"} > 86400 * $ftpstats_period
Truth table0%0/3
A and B
A= @{$fullstats->{"history"} or [];}B= @{$fullstats->{"history"};} > $ftpstats_size || $time - $fullstats->{"history"}[0]{"start"} > 86400 * $ftpstats_period
ABresult
0X0
100
111
136 0 ▶ @{$fullstats->{history} || []}
Branch: 1 branch
BranchTrueFalseTotal
$fullstats->{"history"} or [] 0 0 0
Condition0%0/3
@{$fullstats->{"history"};} > $ftpstats_size or $time - $fullstats->{"history"}[0]{"start"} > 86400 * $ftpstats_period
l!l&&r!l&&!r
000
MC/DC0%0/2
@{$fullstats->{"history"};} > $ftpstats_size or $time - $fullstats->{"history"}[0]{"start"} > 86400 * $ftpstats_period
@{$fullstats->{"history"};} > $ftpstats_size $time - $fullstats->{"history"}[0]{"start"} > 86400 * $ftpstats_period
Truth table0%0/3
A or B
A= @{$fullstats->{"history"};} > $ftpstats_sizeB= $time - $fullstats->{"history"}[0]{"start"} > 86400 * $ftpstats_period
ABresult
1X1
011
000
137 &&
138 (
139 0 @{$fullstats->{history}} > $ftpstats_size
140 || $time - $fullstats->{history}[0]{start} > 86400*$ftpstats_period
141 )
142 ) {
143 0 shift @{$fullstats->{history}}
144 }
145 0 ▶ push @debug, scalar @{$fullstats->{history}} if $sdebug;
Branch: 1 branch
BranchTrueFalseTotal
if $sdebug 0 0 0
146 0 ▶ push @debug, time if $sdebug;
Branch: 1 branch
BranchTrueFalseTotal
if $sdebug 0 0 0
147 0 ▶ push @debug, scalar localtime($fullstats->{history}[0]{start}) if $sdebug;
Branch: 1 branch
BranchTrueFalseTotal
if $sdebug 0 0 0
148 # need no eval because if this fails, it is serious
149 0 my $sfile = File::Spec->catfile($CPAN::Config->{cpan_home},"FTPstats.yml");
150 0 CPAN->_yaml_dumpfile("$sfile.$$",$fullstats);
151 0 ▶ if ( $sdebug ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sdebug) 0 0 0
152 0 local $CPAN::DEBUG = 512; # FTP
153 0 push @debug, time;
154 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 ▶ unlink($sfile) if ($^O eq 'MSWin32' or $^O eq 'os2');
Branch: 1 branch
BranchTrueFalseTotal
if $^O eq "MSWin32" or $^O eq "os2" 0 0 0
Condition0%0/3
$^O eq "MSWin32" or $^O eq "os2"
l!l&&r!l&&!r
000
MC/DC0%0/2
$^O eq "MSWin32" or $^O eq "os2"
$^O eq "MSWin32" $^O eq "os2"
Truth table0%0/3
A or B
A= $^O eq "MSWin32"B= $^O eq "os2"
ABresult
1X1
011
000
161 0 ▶ _copy_stat($sfile, "$sfile.$$") if -e $sfile;
Branch: 1 branch
BranchTrueFalseTotal
if -e $sfile 0 0 0
162 0 ▶ rename "$sfile.$$", $sfile
Branch: 1 branch
BranchTrueFalseTotal
rename "$sfile.${$}", $sfile or $CPAN::Frontend->mywarn("Could not rename '$sfile.${$}' to '${sfile}': $!\nGiving up\n") 0 0 0
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 ▶ my($src, $dest) = @_;
Subroutine _copy_stat: not called CC=6 SCAR=37.4
173 0 my @stat = stat($src);
174 0 ▶ if (!@stat) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@stat) 0 0 0
175 0 $CPAN::Frontend->mywarn("Can't stat '$src': $!\n");
176 0 return;
177 }
178  
179 0 eval {
180 0 ▶ chmod $stat[2], $dest
Branch: 1 branch
BranchTrueFalseTotal
chmod $stat[2], $dest or $CPAN::Frontend->mywarn("Can't chmod '${dest}' to " . sprintf("0%o", $stat[2]) . ": $!\n") 0 0 0
181 or $CPAN::Frontend->mywarn("Can't chmod '$dest' to " . sprintf("0%o", $stat[2]) . ": $!\n");
182 };
183 0 ▶ warn $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
184 0 eval {
185 chown $stat[4], $stat[5], $dest
186 0 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
chown $stat[4], $stat[5], $dest or do { my $save_err = $!; $CPAN::Frontend->mywarn("Can't chown '${dest}' to " . (getpwuid $stat[4])[0] . '/' . (getgrgid $stat[5])[0] . ": $save_err\n") } 0 0 0
187 0 my $save_err = $!; # otherwise it's lost in the get... calls
188 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 ▶ warn $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
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 38 ▶ my($self, $file, $urllist) = @_;
Subroutine _recommend_url_for: called CC=9 SCAR=31.2
202 38 ▶ if ($file =~ s|/CHECKSUMS(.gz)?$||) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ s[/CHECKSUMS(.gz)?$][]) 7 31 38
203 7 my $fullstats = $self->_ftp_statistics();
204 7 ▶ my $history = $fullstats->{history} || [];
Condition50%1/2
$fullstats->{'history'} || []
l!l
07
MC/DC0%0/1
$fullstats->{'history'} || []
$fullstats->{'history'}
Truth table50%1/2
A
A= $fullstats->{'history'}
Aresult
11
00
205 7 ▶ while (my $last = pop @$history) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $last = pop @$history) 0 7 7
206 0 ▶ last if $last->{end} - time > 3600; # only young results are interesting
Branch: 1 branch
BranchTrueFalseTotal
if $last->{"end"} - time > 3600 0 0 0
207 0 ▶ next unless $last->{file}; # dirname of nothing dies!
Branch: 1 branch
BranchTrueFalseTotal
unless $last->{"file"} 0 0 0
208 0 ▶ next unless $file eq dirname($last->{file});
Branch: 1 branch
BranchTrueFalseTotal
unless $file eq dirname($last->{"file"}) 0 0 0
209 0 return $last->{thesiteurl};
210 }
211 }
212 38 ▶ if ($CPAN::Config->{randomize_urllist}
Branch: 1 branch
BranchTrueFalseTotal
if ($CPAN::Config->{'randomize_urllist'} and rand 1 < $CPAN::Config->{'randomize_urllist'}) { } 0 38 38
Condition33%1/3
$CPAN::Config->{"randomize_urllist"} and rand 1 < $CPAN::Config->{"randomize_urllist"}
!ll&&!rl&&r
3800
MC/DC0%0/2
$CPAN::Config->{"randomize_urllist"} and rand 1 < $CPAN::Config->{"randomize_urllist"}
$CPAN::Config->{"randomize_urllist"} rand 1 < $CPAN::Config->{"randomize_urllist"}
Truth table33%1/3
A and B
A= $CPAN::Config->{"randomize_urllist"}B= rand 1 < $CPAN::Config->{"randomize_urllist"}
ABresult
0X0
100
111
213 &&
214 rand(1) < $CPAN::Config->{randomize_urllist}
215 ) {
216 0 $urllist->[int rand scalar @$urllist];
217 } else {
218 38 return ();
219 }
220 }
221  
222 #-> sub CPAN::FTP::_get_urllist
223 sub _get_urllist {
224 38 ▶ my($self, $with_defaults) = @_;
Subroutine _get_urllist: called CC=12 SCAR=29.5
225 38 ▶ $with_defaults ||= 0;
Condition50%1/2
$with_defaults ||= 0
l!l
038
MC/DC0%0/1
$with_defaults ||= 0
$with_defaults
Truth table50%1/2
A
A= $with_defaults
Aresult
11
00
226 38 ▶ CPAN->debug("with_defaults[$with_defaults]") if $CPAN::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::DEBUG 0 38 38
227  
228 38 ▶ $CPAN::Config->{urllist} ||= [];
Condition50%1/2
$CPAN::Config->{"urllist"} ||= []
l!l
380
MC/DC0%0/1
$CPAN::Config->{"urllist"} ||= []
$CPAN::Config->{"urllist"}
Truth table50%1/2
A
A= $CPAN::Config->{"urllist"}
Aresult
11
00
229 38 ▶ unless (ref $CPAN::Config->{urllist} eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $CPAN::Config->{"urllist"} eq "ARRAY") 0 38 38
230 0 $CPAN::Frontend->mywarn("Malformed urllist; ignoring. Configuration file corrupt?\n");
231 0 $CPAN::Config->{urllist} = [];
232 }
233 38 ▶ my @urllist = grep { defined $_ and length $_ } @{$CPAN::Config->{urllist}};
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and length $_ 38 0 38
234 38 ▶ push @urllist, @CPAN::Defaultsites if $with_defaults;
Branch: 1 branch
BranchTrueFalseTotal
if $with_defaults 0 38 38
235 38 for my $u (@urllist) {
236 38 ▶ CPAN->debug("u[$u]") if $CPAN::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::DEBUG 0 38 38
237 38 ▶ if (UNIVERSAL::can($u,"text")) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::can($u, 'text')) { } 0 38 38
238 0 ▶ $u->{TEXT} .= "/" unless substr($u->{TEXT},-1) eq "/";
Branch: 1 branch
BranchTrueFalseTotal
unless substr($u->{"TEXT"}, -1) eq "/" 0 0 0
239 } else {
240 38 ▶ $u .= "/" unless substr($u,-1) eq "/";
Branch: 1 branch
BranchTrueFalseTotal
unless substr($u, -1) eq "/" 38 0 38
241 38 $u = CPAN::URL->new(TEXT => $u, FROM => "USER");
242 }
243 }
244 38 \@urllist;
245 }
246  
247 #-> sub CPAN::FTP::ftp_get ;
248 sub ftp_get {
249 0 ▶ my($class,$host,$dir,$file,$target) = @_;
Subroutine ftp_get: not called CC=9 SCAR=45.0
Pod undocumented
250 0 ▶ $class->debug(
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::DEBUG 0 0 0
251 qq[Going to fetch file [$file] from dir [$dir]
252 on host [$host] as local [$target]\n]
253 ) if $CPAN::DEBUG;
254 0 my $ftp = Net::FTP->new($host);
255 0 ▶ unless ($ftp) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ftp) 0 0 0
256 0 $CPAN::Frontend->mywarn(" Could not connect to host '$host' with Net::FTP\n");
257 0 return;
258 }
259 0 ▶ return 0 unless defined $ftp;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ftp 0 0 0
260 0 ▶ $ftp->debug(1) if $CPAN::DEBUG{'FTP'} & $CPAN::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::DEBUG{"FTP"} & $CPAN::DEBUG 0 0 0
261 0 $class->debug(qq[Going to login("anonymous","$Config::Config{cf_email}")]);
262 0 ▶ unless ( $ftp->login("anonymous",$Config::Config{'cf_email'}) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ftp->login("anonymous", $Config::Config{"cf_email"})) 0 0 0
263 0 my $msg = $ftp->message;
264 0 $CPAN::Frontend->mywarn(" Couldn't login on $host: $msg\n");
265 0 return;
266 }
267 0 ▶ unless ( $ftp->cwd($dir) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ftp->cwd($dir)) 0 0 0
268 0 my $msg = $ftp->message;
269 0 $CPAN::Frontend->mywarn(" Couldn't cwd $dir: $msg\n");
270 0 return;
271 }
272 0 $ftp->binary;
273 0 ▶ $class->debug(qq[Going to ->get("$file","$target")\n]) if $CPAN::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::DEBUG 0 0 0
274 0 ▶ unless ( $ftp->get($file,$target) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ftp->get($file, $target)) 0 0 0
275 0 my $msg = $ftp->message;
276 0 $CPAN::Frontend->mywarn(" Couldn't fetch $file from $host: $msg\n");
277 0 return;
278 }
279 0 $ftp->quit; # it's ok if this fails
280 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 38 ▶ my($self,$file,$aslocal,$force,$with_defaults) = @_;
Subroutine localize: called CC=9 SCAR=24.4
Pod undocumented
314 38 ▶ $force ||= 0;
Condition100%2/2
$force ||= 0
l!l
317
MC/DC100%1/1
$force ||= 0
$force
Truth table100%2/2
A
A= $force
Aresult
11
00
315 38 ▶ Carp::croak( "Usage: ->localize(cpan_file,as_local_file[,\$force])" )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $aslocal 0 38 38
316 unless defined $aslocal;
317 38 ▶ if ($CPAN::DEBUG){
Branch: 1 branch
BranchTrueFalseTotal
if ($CPAN::DEBUG) 0 38 38
318 0 require Carp;
319 0 my $longmess = Carp::longmess();
320 0 $self->debug("file[$file] aslocal[$aslocal] force[$force] carplongmess[$longmess]");
321 }
322 38 for ($CPAN::Config->{connect_to_internet_ok}) {
323 38 ▶ $connect_to_internet_ok = $_ if not defined $connect_to_internet_ok and defined $_;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $CPAN::FTP::connect_to_internet_ok and defined $_ 7 31 38
Condition100%3/3
not defined $CPAN::FTP::connect_to_internet_ok and defined $_
!ll&&!rl&&r
2837
MC/DC100%2/2
not defined $CPAN::FTP::connect_to_internet_ok and defined $_
not defined $CPAN::FTP::connect_to_internet_ok defined $_
Truth table100%3/3
not(A) and B
A= not defined $CPAN::FTP::connect_to_internet_okB= defined $_
ABresult
0X0
100
111
324 }
325 38 my $ph = $CPAN::Config->{pushy_https};
326 38 ▶ if (!defined $ph || $ph) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $ph or $ph) { } 0 38 38
Condition33%1/3
not defined $ph or $ph
l!l&&r!l&&!r
0038
MC/DC0%0/2
not defined $ph or $ph
not defined $ph $ph
Truth table33%1/3
not(A) or B
A= not defined $phB= $ph
ABresult
1X1
011
000
327 0 return $self->localize_2021($file,$aslocal,$force,$with_defaults);
328 } else {
329 38 return $self->localize_1995ff($file,$aslocal,$force,$with_defaults);
330 }
331 }
332  
333 sub have_promising_aslocal {
334 38 ▶ my($self, $aslocal, $force) = @_;
Subroutine have_promising_aslocal: called CC=7 SCAR=32.5
Pod undocumented
335 38 ▶ if (-f $aslocal && -r _ && !($force & 1)) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $aslocal and -r _ and not $force & 1) 0 38 38
Condition33%2/6
-f $aslocal and -r _ and not $force & 1
!ll&&!rl&&r
3800
-f $aslocal and -r _
!ll&&!rl&&r
3800
MC/DC0%0/3
-f $aslocal and -r _ and not $force & 1
-f $aslocal -r _ not $force & 1
Truth table25%1/4
A and B and not(C)
A= -f $aslocalB= -r _C= not $force & 1
ABCresult
0XX0
10X0
1100
1111
336 0 my $size;
337 0 ▶ if ($size = -s $aslocal) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size = -s $aslocal) { } 0 0 0
338 0 ▶ $self->debug("aslocal[$aslocal]size[$size]") if $CPAN::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::DEBUG 0 0 0
339 0 return 1;
340 } else {
341 # empty file from a previous unsuccessful attempt to download it
342 0 ▶ unlink $aslocal or
Branch: 1 branch
BranchTrueFalseTotal
unlink $aslocal or $CPAN::Frontend->mydie("Found a zero-length '${aslocal}' that I " . 'could not remove.') 0 0 0
343 $CPAN::Frontend->mydie("Found a zero-length '$aslocal' that I ".
344 "could not remove.");
345 }
346 }
347 38 return;
348 }
349  
350 #-> sub CPAN::FTP::localize ;
351 sub localize_2021 {
352 0 ▶ my($self,$file,$aslocal,$force,$with_defaults) = @_;
Subroutine localize_2021: not called CC=17 SCAR=57.2
Pod undocumented
353 0 ▶ return $aslocal if $self->have_promising_aslocal($aslocal, $force);
Branch: 1 branch
BranchTrueFalseTotal
if $self->have_promising_aslocal($aslocal, $force) 0 0 0
354 0 my($aslocal_dir) = dirname($aslocal);
355 0 my $ret;
356 0 $self->mymkpath($aslocal_dir);
357 0 my $aslocal_tempfile = $aslocal . ".tmp" . $$;
358 0 my $base;
359 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($CPAN::META->has_usable('HTTP::Tiny') and $CPAN::META->has_usable('Net::SSLeay') and $CPAN::META->has_usable('IO::Socket::SSL') or $CPAN::Config->{'curl'} or $CPAN::Config->{'wget'}) { } 0 0 0
Condition0%0/12
$CPAN::META->has_usable("HTTP::Tiny") and $CPAN::META->has_usable("Net::SSLeay") and $CPAN::META->has_usable("IO::Socket::SSL") or $CPAN::Config->{"curl"} or $CPAN::Config->{"wget"}
l!l&&r!l&&!r
000
$CPAN::META->has_usable("HTTP::Tiny") and $CPAN::META->has_usable("Net::SSLeay") and $CPAN::META->has_usable("IO::Socket::SSL") or $CPAN::Config->{"curl"}
l!l&&r!l&&!r
000
$CPAN::META->has_usable("HTTP::Tiny") and $CPAN::META->has_usable("Net::SSLeay") and $CPAN::META->has_usable("IO::Socket::SSL")
!ll&&!rl&&r
000
$CPAN::META->has_usable("HTTP::Tiny") and $CPAN::META->has_usable("Net::SSLeay")
!ll&&!rl&&r
000
MC/DC0%0/5
$CPAN::META->has_usable("HTTP::Tiny") and $CPAN::META->has_usable("Net::SSLeay") and $CPAN::META->has_usable("IO::Socket::SSL") or $CPAN::Config->{"curl"} or $CPAN::Config->{"wget"}
$CPAN::META->has_usable("HTTP::Tiny") $CPAN::META->has_usable("Net::SSLeay") $CPAN::META->has_usable("IO::Socket::SSL") $CPAN::Config->{"curl"} $CPAN::Config->{"wget"}
Truth table0%0/10
A and B and C or D or E
A= $CPAN::META->has_usable("HTTP::Tiny")B= $CPAN::META->has_usable("Net::SSLeay")C= $CPAN::META->has_usable("IO::Socket::SSL")D= $CPAN::Config->{"curl"}E= $CPAN::Config->{"wget"}
ABCDEresult
111XX1
0XX1X1
10X1X1
1101X1
0XX011
10X011
110011
0XX000
10X000
110000
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 for my $prx (qw(https_proxy no_proxy)) {
368 0 ▶ $ENV{$prx} = $CPAN::Config->{$prx} if $CPAN::Config->{$prx};
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::Config->{$prx} 0 0 0
369 }
370 0 $base = "https://www.cpan.org/";
371 } else {
372 0 my @missing_modules = grep { ! $CPAN::META->has_usable($_) } qw(HTTP::Tiny Net::SSLeay IO::Socket::SSL);
373 0 my $miss = join ", ", map { "'$_'" } @missing_modules;
374 0 ▶ my $modules = @missing_modules == 1 ? "module" : "modules";
Branch: 1 branch
BranchTrueFalseTotal
@missing_modules == 1 ? : 0 0 0
375 0 $CPAN::Frontend->mywarn("Missing or unusable $modules $miss, and found neither curl nor wget installed.\n");
376 0 ▶ if ($CPAN::META->has_usable('HTTP::Tiny')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CPAN::META->has_usable("HTTP::Tiny")) 0 0 0
377 0 $CPAN::Frontend->mywarn("Need to fall back to http.\n")
378 }
379 0 for my $prx (qw(http_proxy no_proxy)) {
380 0 ▶ $ENV{$prx} = $CPAN::Config->{$prx} if $CPAN::Config->{$prx};
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::Config->{$prx} 0 0 0
381 }
382 0 $base = "http://www.cpan.org/";
383 }
384 0 $ret = $self->hostdl_2021($base,$file,$aslocal_tempfile);
385 0 ▶ if ($ret) { # c&p from below
Branch: 1 branch
BranchTrueFalseTotal
if ($ret) { } 0 0 0
386 0 ▶ CPAN->debug("ret[$ret]aslocal[$aslocal]") if $CPAN::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::DEBUG 0 0 0
387 0 ▶ if ($ret eq $aslocal_tempfile) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ret eq $aslocal_tempfile) 0 0 0
388 # if we got it exactly as we asked for, only then we
389 # want to rename
390 0 ▶ rename $aslocal_tempfile, $aslocal
Branch: 1 branch
BranchTrueFalseTotal
rename $aslocal_tempfile, $aslocal or $CPAN::Frontend->mydie('Error while trying to rename ' . "'${ret}' to '${aslocal}': $!") 0 0 0
391 or $CPAN::Frontend->mydie("Error while trying to rename ".
392 "'$ret' to '$aslocal': $!");
393 0 $ret = $aslocal;
394 }
395 } else {
396 0 unlink $aslocal_tempfile;
397 0 return;
398 }
399 0 return $ret;
400 }
401  
402 sub hostdl_2021 {
403 0 ▶ my($self, $base, $file, $aslocal) = @_; # the $aslocal is $aslocal_tempfile in the caller (old convention)
Subroutine hostdl_2021: not called CC=28 SCAR=67.0
Pod undocumented
404 0 my $proxy_vars = $self->_proxy_vars($base);
405 0 my($proto) = $base =~ /^(https?)/;
406 0 my $url = "$base$file";
407 # hostdl_2021 may be called with either http or https urls
408 0 ▶ if (
Branch: 2 branches
BranchTrueFalseTotal
if ($CPAN::META->has_usable('HTTP::Tiny') and $proto eq 'http' || $CPAN::META->has_usable('Net::SSLeay') && $CPAN::META->has_usable('IO::Socket::SSL')) { } 0 0 0
elsif ($CPAN::Config->{'curl'} or $CPAN::Config->{'wget'}) { } 0 0 0
Condition0%0/9
$CPAN::META->has_usable("HTTP::Tiny") and $proto eq "http" || $CPAN::META->has_usable("Net::SSLeay") && $CPAN::META->has_usable("IO::Socket::SSL")
!ll&&!rl&&r
000
$proto eq "http" or $CPAN::META->has_usable("Net::SSLeay") and $CPAN::META->has_usable("IO::Socket::SSL")
l!l&&r!l&&!r
000
$CPAN::META->has_usable("Net::SSLeay") and $CPAN::META->has_usable("IO::Socket::SSL")
!ll&&!rl&&r
000
MC/DC0%0/4
$CPAN::META->has_usable("HTTP::Tiny") and $proto eq "http" || $CPAN::META->has_usable("Net::SSLeay") && $CPAN::META->has_usable("IO::Socket::SSL")
$CPAN::META->has_usable("HTTP::Tiny") $proto eq "http" $CPAN::META->has_usable("Net::SSLeay") $CPAN::META->has_usable("IO::Socket::SSL")
Truth table0%0/5
A and B or C and D
A= $CPAN::META->has_usable("HTTP::Tiny")B= $proto eq "http"C= $CPAN::META->has_usable("Net::SSLeay")D= $CPAN::META->has_usable("IO::Socket::SSL")
ABCDresult
0XXX0
100X0
10100
11XX1
10111
409 $CPAN::META->has_usable('HTTP::Tiny')
410 &&
411 (
412 $proto eq "http"
413 ||
414 ( $CPAN::META->has_usable('Net::SSLeay')
415 && $CPAN::META->has_usable('IO::Socket::SSL') )
416 )
417 ){
418 # mostly c&p from below
419 0 require CPAN::HTTP::Client;
420 my $chc = CPAN::HTTP::Client->new(
421 proxy => $CPAN::Config->{http_proxy} || $ENV{http_proxy},
422 no_proxy => $CPAN::Config->{no_proxy} || $ENV{no_proxy},
423 0 ▶ );
Condition0%0/6
$CPAN::Config->{'http_proxy'} || $ENV{'http_proxy'}
l!l&&r!l&&!r
000
$CPAN::Config->{'no_proxy'} || $ENV{'no_proxy'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$CPAN::Config->{'http_proxy'} || $ENV{'http_proxy'}
$CPAN::Config->{'http_proxy'} $ENV{'http_proxy'}
MC/DC0%0/2
$CPAN::Config->{'no_proxy'} || $ENV{'no_proxy'}
$CPAN::Config->{'no_proxy'} $ENV{'no_proxy'}
Truth table0%0/3
A || B
A= $CPAN::Config->{'http_proxy'}B= $ENV{'http_proxy'}
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $CPAN::Config->{'no_proxy'}B= $ENV{'no_proxy'}
ABresult
1X1
011
000
424 0 ▶ for my $try ( $url, ( $url !~ /\.gz(?!\n)\Z/ ? "$url.gz" : () ) ) {
Branch: 1 branch
BranchTrueFalseTotal
!($url =~ /\.gz(?!\n)\Z/) ? : 0 0 0
425 0 $CPAN::Frontend->myprint("Fetching with HTTP::Tiny:\n$try\n");
426 0 my $res = eval { $chc->mirror($try, $aslocal) };
427 0 ▶ if ( $res && $res->{success} ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($res and $res->{'success'}) { } 0 0 0
elsif ($res and $res->{'status'} ne '599') { } 0 0 0
elsif ($res and $res->{'status'} eq '599') { } 0 0 0
Condition0%0/3
$res and $res->{"success"}
!ll&&!rl&&r
000
MC/DC0%0/2
$res and $res->{"success"}
$res $res->{"success"}
Truth table0%0/3
A and B
A= $resB= $res->{"success"}
ABresult
0X0
100
111
428 0 my $now = time;
429 0 utime $now, $now, $aslocal; # download time is more
430 # important than upload
431 # time
432 0 return $aslocal;
433 }
434 ▶ elsif ( $res && $res->{status} ne '599') {
Condition0%0/3
$res and $res->{"status"} ne 599
!ll&&!rl&&r
000
MC/DC0%0/2
$res and $res->{"status"} ne 599
$res $res->{"status"} ne 599
Truth table0%0/3
A and B
A= $resB= $res->{"status"} ne 599
ABresult
0X0
100
111
435 $CPAN::Frontend->myprint(sprintf(
436 "HTTP::Tiny failed with code[%s] message[%s]\n",
437 $res->{status},
438 $res->{reason},
439 )
440 0 );
441 }
442 ▶ elsif ( $res && $res->{status} eq '599') {
Condition0%0/3
$res and $res->{"status"} eq 599
!ll&&!rl&&r
000
MC/DC0%0/2
$res and $res->{"status"} eq 599
$res $res->{"status"} eq 599
Truth table0%0/3
A and B
A= $resB= $res->{"status"} eq 599
ABresult
0X0
100
111
443 $CPAN::Frontend->myprint(sprintf(
444 "HTTP::Tiny failed with an internal error: %s\n",
445 $res->{content},
446 )
447 0 );
448 }
449 else {
450 0 ▶ my $err = $@ || 'Unknown error';
Condition0%0/2
$@ || 'Unknown error'
l!l
00
MC/DC0%0/1
$@ || 'Unknown error'
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
451 0 $CPAN::Frontend->myprint(sprintf(
452 "Error downloading with HTTP::Tiny: %s\n", $err
453 )
454 );
455 }
456 }
457 ▶ } elsif ($CPAN::Config->{curl} || $CPAN::Config->{wget}){
Condition0%0/3
$CPAN::Config->{"curl"} or $CPAN::Config->{"wget"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$CPAN::Config->{"curl"} or $CPAN::Config->{"wget"}
$CPAN::Config->{"curl"} $CPAN::Config->{"wget"}
Truth table0%0/3
A or B
A= $CPAN::Config->{"curl"}B= $CPAN::Config->{"wget"}
ABresult
1X1
011
000
458 # c&p from further down
459 0 my($src_switch, $stdout_redir);
460 0 ▶ my($devnull) = $CPAN::Config->{devnull} || "";
Condition0%0/2
$CPAN::Config->{'devnull'} || ''
l!l
00
MC/DC0%0/1
$CPAN::Config->{'devnull'} || ''
$CPAN::Config->{'devnull'}
Truth table0%0/2
A
A= $CPAN::Config->{'devnull'}
Aresult
11
00
461 0 DLPRG: for my $dlprg (qw(curl wget)) {
462 0 my $dlprg_configured = $CPAN::Config->{$dlprg};
463 0 ▶ next unless defined $dlprg_configured && length $dlprg_configured;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dlprg_configured and length $dlprg_configured 0 0 0
Condition0%0/3
defined $dlprg_configured and length $dlprg_configured
!ll&&!rl&&r
000
MC/DC0%0/2
defined $dlprg_configured and length $dlprg_configured
defined $dlprg_configured length $dlprg_configured
Truth table0%0/3
A and B
A= defined $dlprg_configuredB= length $dlprg_configured
ABresult
0X0
100
111
464 0 my $funkyftp = CPAN::HandleConfig->safe_quote($dlprg_configured);
465 0 ▶ if ($dlprg eq "wget") {
Branch: 2 branches
BranchTrueFalseTotal
if ($dlprg eq 'wget') { } 0 0 0
elsif ($dlprg eq 'curl') { } 0 0 0
466 0 $src_switch = " -O \"$aslocal\"";
467 0 $stdout_redir = "";
468 } elsif ($dlprg eq 'curl') {
469 0 $src_switch = ' -L -f -s -S --netrc-optional';
470 0 $stdout_redir = " > \"$aslocal\"";
471 0 ▶ if ($proxy_vars->{http_proxy}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($proxy_vars->{"http_proxy"}) 0 0 0
472 0 $src_switch .= qq{ -U "$proxy_vars->{proxy_user}:$proxy_vars->{proxy_pass}" -x "$proxy_vars->{http_proxy}"};
473 }
474 }
475 $CPAN::Frontend->myprint(
476 0 qq[
477 Trying with
478 $funkyftp$src_switch
479 to get
480 $url
481 ]);
482 0 my($system) =
483 "$funkyftp$src_switch \"$url\" $devnull$stdout_redir";
484 0 ▶ $self->debug("system[$system]") if $CPAN::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::DEBUG 0 0 0
485 0 my($wstatus) = system($system);
486 0 ▶ if ($wstatus == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wstatus == 0) { } 0 0 0
487 0 return $aslocal;
488 } else {
489 0 my $estatus = $wstatus >> 8;
490 0 ▶ my $size = -f $aslocal ?
Branch: 1 branch
BranchTrueFalseTotal
-f $aslocal ? : 0 0 0
491 ", left\n$aslocal with size ".-s _ :
492 "\nWarning: expected file [$aslocal] doesn't exist";
493 0 $CPAN::Frontend->myprint(qq{
494 Function system("$system")
495 returned status $estatus (wstat $wstatus)$size
496 });
497 }
498 } # DLPRG
499 } # curl, wget
500 0 return;
501 }
502  
503 #-> sub CPAN::FTP::localize ;
504 sub localize_1995ff {
505 38 ▶ my($self,$file,$aslocal,$force,$with_defaults) = @_;
Subroutine localize_1995ff: called CC=50 SCAR=58.3
Pod undocumented
506  
507 38 ▶ return $aslocal if $self->have_promising_aslocal($aslocal, $force);
Branch: 1 branch
BranchTrueFalseTotal
if $self->have_promising_aslocal($aslocal, $force) 0 38 38
508 38 my($maybe_restore) = 0;
509 38 ▶ if (-f $aslocal) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $aslocal) 0 38 38
510 0 rename $aslocal, "$aslocal.bak$$";
511 0 $maybe_restore++;
512 }
513  
514 38 my($aslocal_dir) = dirname($aslocal);
515 # Inheritance is not easier to manage than a few if/else branches
516 38 ▶ if ($CPAN::META->has_usable('LWP::UserAgent')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CPAN::META->has_usable("LWP::UserAgent")) 38 0 38
517 38 ▶ unless ($Ua) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($CPAN::FTP::Ua) 8 30 38
518 8 CPAN::LWP::UserAgent->config;
519 8 eval {$Ua = CPAN::LWP::UserAgent->new;}; # Why is has_usable still not fit enough?
520 8 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 8 8
521 0 ▶ $CPAN::Frontend->mywarn("CPAN::LWP::UserAgent->new dies with $@\n")
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::DEBUG 0 0 0
522 if $CPAN::DEBUG;
523 } else {
524 8 my($var);
525 $Ua->proxy('ftp', $var)
526 8 ▶ if $var = $CPAN::Config->{ftp_proxy} || $ENV{ftp_proxy};
Branch: 1 branch
BranchTrueFalseTotal
if $var = $CPAN::Config->{"ftp_proxy"} || $ENV{"ftp_proxy"} 0 8 8
Condition33%1/3
$CPAN::Config->{'ftp_proxy'} || $ENV{'ftp_proxy'}
l!l&&r!l&&!r
008
MC/DC0%0/2
$CPAN::Config->{'ftp_proxy'} || $ENV{'ftp_proxy'}
$CPAN::Config->{'ftp_proxy'} $ENV{'ftp_proxy'}
Truth table33%1/3
A || B
A= $CPAN::Config->{'ftp_proxy'}B= $ENV{'ftp_proxy'}
ABresult
1X1
011
000
527 $Ua->proxy('http', $var)
528 8 ▶ if $var = $CPAN::Config->{http_proxy} || $ENV{http_proxy};
Branch: 1 branch
BranchTrueFalseTotal
if $var = $CPAN::Config->{"http_proxy"} || $ENV{"http_proxy"} 0 8 8
Condition33%1/3
$CPAN::Config->{'http_proxy'} || $ENV{'http_proxy'}
l!l&&r!l&&!r
008
MC/DC0%0/2
$CPAN::Config->{'http_proxy'} || $ENV{'http_proxy'}
$CPAN::Config->{'http_proxy'} $ENV{'http_proxy'}
Truth table33%1/3
A || B
A= $CPAN::Config->{'http_proxy'}B= $ENV{'http_proxy'}
ABresult
1X1
011
000
529 $Ua->no_proxy($var)
530 8 ▶ if $var = $CPAN::Config->{no_proxy} || $ENV{no_proxy};
Branch: 1 branch
BranchTrueFalseTotal
if $var = $CPAN::Config->{"no_proxy"} || $ENV{"no_proxy"} 0 8 8
Condition33%1/3
$CPAN::Config->{'no_proxy'} || $ENV{'no_proxy'}
l!l&&r!l&&!r
008
MC/DC0%0/2
$CPAN::Config->{'no_proxy'} || $ENV{'no_proxy'}
$CPAN::Config->{'no_proxy'} $ENV{'no_proxy'}
Truth table33%1/3
A || B
A= $CPAN::Config->{'no_proxy'}B= $ENV{'no_proxy'}
ABresult
1X1
011
000
531 }
532 }
533 }
534 38 for my $prx (qw(ftp_proxy http_proxy no_proxy)) {
535 114 ▶ $ENV{$prx} = $CPAN::Config->{$prx} if $CPAN::Config->{$prx};
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::Config->{$prx} 0 114 114
536 }
537  
538 # Try the list of urls for each single object. We keep a record
539 # where we did get a file from
540 38 my(@reordered,$last);
541 38 my $ccurllist = $self->_get_urllist($with_defaults);
542 38 $last = $#$ccurllist;
543 38 ▶ if ($force & 2) { # local cpans probably out of date, don't reorder
Branch: 1 branch
BranchTrueFalseTotal
if ($force & 2) { } 24 14 38
544 24 @reordered = (0..$last);
545 } else {
546 @reordered =
547 sort {
548 14 ▶ (substr($ccurllist->[$b],0,4) eq "file")
Branch: 1 branch
BranchTrueFalseTotal
(substr($ccurllist->[$b], 0, 4) eq "file") <=> (substr($ccurllist->[$a], 0, 4) eq "file") or defined $CPAN::FTP::ThesiteURL and ($ccurllist->[$b] eq $CPAN::FTP::ThesiteURL) <=> ($ccurllist->[$a] eq $CPAN::FTP::ThesiteURL) 0 0 0
Condition0%0/6
(substr($ccurllist->[$b], 0, 4) eq 'file') <=> (substr($ccurllist->[$a], 0, 4) eq 'file') || defined $CPAN::FTP::ThesiteURL && ($ccurllist->[$b] eq $CPAN::FTP::ThesiteURL) <=> ($ccurllist->[$a] eq $CPAN::FTP::ThesiteURL)
l!l&&r!l&&!r
000
defined $CPAN::FTP::ThesiteURL and ($ccurllist->[$b] eq $CPAN::FTP::ThesiteURL) <=> ($ccurllist->[$a] eq $CPAN::FTP::ThesiteURL)
!ll&&!rl&&r
000
MC/DC0%0/3
(substr($ccurllist->[$b], 0, 4) eq 'file') <=> (substr($ccurllist->[$a], 0, 4) eq 'file') || defined $CPAN::FTP::ThesiteURL && ($ccurllist->[$b] eq $CPAN::FTP::ThesiteURL) <=> ($ccurllist->[$a] eq $CPAN::FTP::ThesiteURL)
(substr($ccurllist->[$b], 0, 4) eq 'file') <=> (substr($ccurllist->[$a], 0, 4) eq 'file') defined $CPAN::FTP::ThesiteURL ($ccurllist->[$b] eq $CPAN::FTP::ThesiteURL) <=> ($ccurllist->[$a] eq $CPAN::FTP::ThesiteURL)
Truth table0%0/4
A || B and C
A= (substr($ccurllist->[$b], 0, 4) eq 'file') <=> (substr($ccurllist->[$a], 0, 4) eq 'file')B= defined $CPAN::FTP::ThesiteURLC= ($ccurllist->[$b] eq $CPAN::FTP::ThesiteURL) <=> ($ccurllist->[$a] eq $CPAN::FTP::ThesiteURL)
ABCresult
1XX1
0111
00X0
0100
549 <=>
550 (substr($ccurllist->[$a],0,4) eq "file")
551 or
552 defined($ThesiteURL)
553 and
554 ($ccurllist->[$b] eq $ThesiteURL)
555 <=>
556 ($ccurllist->[$a] eq $ThesiteURL)
557 } 0..$last;
558 }
559 38 my(@levels);
560 38 ▶ $Themethod ||= "";
Condition100%2/2
$CPAN::FTP::Themethod ||= ""
l!l
308
MC/DC100%1/1
$CPAN::FTP::Themethod ||= ""
$CPAN::FTP::Themethod
Truth table100%2/2
A
A= $CPAN::FTP::Themethod
Aresult
11
00
561 38 ▶ $self->debug("Themethod[$Themethod]reordered[@reordered]") if $CPAN::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::DEBUG 0 38 38
562 38 my @all_levels = (
563 ["dleasy", "file"],
564 ["dleasy"],
565 ["dlhard"],
566 ["dlhardest"],
567 ["dleasy", "http","defaultsites"],
568 ["dlhard", "http","defaultsites"],
569 ["dleasy", "ftp", "defaultsites"],
570 ["dlhard", "ftp", "defaultsites"],
571 ["dlhardest","", "defaultsites"],
572 );
573 38 ▶ if ($Themethod) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CPAN::FTP::Themethod) { } 30 8 38
574 30 @levels = grep {$_->[0] eq $Themethod} @all_levels;
575 30 push @levels, grep {$_->[0] ne $Themethod} @all_levels;
576 } else {
577 8 @levels = @all_levels;
578 }
579 38 my($levelno);
580 local $ENV{FTP_PASSIVE} =
581 exists $CPAN::Config->{ftp_passive} ?
582 38 ▶ $CPAN::Config->{ftp_passive} : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $CPAN::Config->{'ftp_passive'} ? : 35 3 38
583 38 my $ret;
584 38 my $stats = $self->_new_stats($file);
585 38 LEVEL: for $levelno (0..$#levels) {
586 38 my $level_tuple = $levels[$levelno];
587 38 my($level,$scheme,$sitetag) = @$level_tuple;
588 38 ▶ $self->mymkpath($aslocal_dir) unless $scheme && "file" eq $scheme;
Branch: 1 branch
BranchTrueFalseTotal
unless $scheme and "file" eq $scheme 0 38 38
Condition33%1/3
$scheme and "file" eq $scheme
!ll&&!rl&&r
0038
MC/DC0%0/2
$scheme and "file" eq $scheme
$scheme "file" eq $scheme
Truth table33%1/3
A and B
A= $schemeB= "file" eq $scheme
ABresult
0X0
100
111
589 38 ▶ my $defaultsites = $sitetag && $sitetag eq "defaultsites" && !@$ccurllist;
Condition33%2/6
$sitetag && $sitetag eq 'defaultsites' && !@$ccurllist
!ll&&!rl&&r
3800
$sitetag and $sitetag eq "defaultsites"
!ll&&!rl&&r
3800
MC/DC0%0/3
$sitetag && $sitetag eq 'defaultsites' && !@$ccurllist
$sitetag $sitetag eq "defaultsites" !@$ccurllist
Truth table25%1/4
A and B && not(C)
A= $sitetagB= $sitetag eq "defaultsites"C= !@$ccurllist
ABCresult
0XX0
10X0
1100
1111
590 38 my @urllist;
591 38 ▶ if ($defaultsites) {
Branch: 1 branch
BranchTrueFalseTotal
if ($defaultsites) { } 0 38 38
592 0 ▶ unless (defined $connect_to_internet_ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $CPAN::FTP::connect_to_internet_ok) 0 0 0
593 $CPAN::Frontend->myprint(sprintf qq{
594 I would like to connect to one of the following sites to get '%s':
595  
596 %s
597 },
598 $file,
599 0 join("",map { " ".$_->text."\n" } @CPAN::Defaultsites),
600 );
601 0 my $answer = CPAN::Shell::colorable_makemaker_prompt("Is it OK to try to connect to the Internet?", "yes");
602 0 ▶ if ($answer =~ /^y/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($answer =~ /^y/i) { } 0 0 0
603 0 $connect_to_internet_ok = 1;
604 } else {
605 0 $connect_to_internet_ok = 0;
606 }
607 }
608 0 ▶ if ($connect_to_internet_ok) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CPAN::FTP::connect_to_internet_ok) { } 0 0 0
609 0 @urllist = @CPAN::Defaultsites;
610 } else {
611 0 my $sleep = 2;
612 # the tricky thing about dying here is that everybody
613 # believes that calls to exists() or all_objects() are
614 # safe.
615 0 require CPAN::Exception::blocked_urllist;
616 0 die CPAN::Exception::blocked_urllist->new;
617 }
618 } else { # ! $defaultsites
619 38 ▶ my @host_seq = $level =~ /dleasy/ ?
Branch: 1 branch
BranchTrueFalseTotal
$level =~ /dleasy/ ? : 38 0 38
620 @reordered : 0..$last; # reordered has file and $Thesiteurl first
621 38 @urllist = map { $ccurllist->[$_] } @host_seq;
622 }
623 38 ▶ $self->debug("synth. urllist[@urllist]") if $CPAN::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::DEBUG 0 38 38
624 38 my $aslocal_tempfile = $aslocal . ".tmp" . $$;
625 38 ▶ if (my $recommend = $self->_recommend_url_for($file,\@urllist)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $recommend = $self->_recommend_url_for($file, \@urllist)) 0 38 38
626 0 @urllist = grep { $_ ne $recommend } @urllist;
627 0 unshift @urllist, $recommend;
628 }
629 38 ▶ $self->debug("synth. urllist[@urllist]") if $CPAN::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::DEBUG 0 38 38
630 38 $ret = $self->hostdlxxx($level,$scheme,\@urllist,$file,$aslocal_tempfile,$stats);
631 38 ▶ if ($ret) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ret) { } 38 0 38
632 38 ▶ CPAN->debug("ret[$ret]aslocal[$aslocal]") if $CPAN::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::DEBUG 0 38 38
633 38 ▶ if ($ret eq $aslocal_tempfile) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ret eq $aslocal_tempfile) { } 0 38 38
elsif (-f $ret and $scheme eq 'file') { } 38 0 38
634 # if we got it exactly as we asked for, only then we
635 # want to rename
636 0 ▶ rename $aslocal_tempfile, $aslocal
Branch: 1 branch
BranchTrueFalseTotal
rename $aslocal_tempfile, $aslocal or $CPAN::Frontend->mydie('Error while trying to rename ' . "'${ret}' to '${aslocal}': $!") 0 0 0
637 or $CPAN::Frontend->mydie("Error while trying to rename ".
638 "'$ret' to '$aslocal': $!");
639 0 $ret = $aslocal;
640 }
641 ▶ elsif (-f $ret && $scheme eq 'file' ) {
Condition33%1/3
-f $ret and $scheme eq "file"
!ll&&!rl&&r
0038
MC/DC0%0/2
-f $ret and $scheme eq "file"
-f $ret $scheme eq "file"
Truth table33%1/3
A and B
A= -f $retB= $scheme eq "file"
ABresult
0X0
100
111
642 # it's a local file, so there's nothing left to do, we
643 # let them read from where it is
644 }
645 38 $Themethod = $level;
646 38 my $now = time;
647 # utime $now, $now, $aslocal; # too bad, if we do that, we
648 # might alter a local mirror
649 38 ▶ $self->debug("level[$level]") if $CPAN::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::DEBUG 0 38 38
650 38 last LEVEL;
651 } else {
652 0 unlink $aslocal_tempfile;
653 0 ▶ last if $CPAN::Signal; # need to cleanup
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::Signal 0 0 0
654 }
655 }
656 38 ▶ if ($ret) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ret) 38 0 38
657 38 $stats->{filesize} = -s $ret;
658 }
659 38 ▶ $self->debug("before _add_to_statistics") if $CPAN::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::DEBUG 0 38 38
660 38 $self->_add_to_statistics($stats);
661 38 ▶ $self->debug("after _add_to_statistics") if $CPAN::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::DEBUG 0 38 38
662 38 ▶ if ($ret) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ret) 38 0 38
663 38 unlink "$aslocal.bak$$";
664 38 return $ret;
665 }
666 0 ▶ unless ($CPAN::Signal) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($CPAN::Signal) 0 0 0
667 0 my(@mess);
668 0 local $" = " ";
669 0 ▶ if (@{$CPAN::Config->{urllist}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$CPAN::Config->{'urllist'};}) { } 0 0 0
670 push @mess,
671 qq{Please check, if the URLs I found in your configuration file \(}.
672 0 join(", ", @{$CPAN::Config->{urllist}}).
673 qq{\) are valid.};
674 } else {
675 0 push @mess, qq{Your urllist is empty!};
676 }
677 0 push @mess, qq{The urllist can be edited.},
678 qq{E.g. with 'o conf urllist push ftp://myurl/'};
679 0 $CPAN::Frontend->mywarn(Text::Wrap::wrap("","","@mess"). "\n\n");
680 0 $CPAN::Frontend->mydie("Could not fetch $file\n");
681 }
682 0 ▶ if ($maybe_restore) {
Branch: 1 branch
BranchTrueFalseTotal
if ($maybe_restore) 0 0 0
683 0 rename "$aslocal.bak$$", $aslocal;
684 0 $CPAN::Frontend->myprint("Trying to get away with old file:\n" .
685 $self->ls($aslocal) . "\n");
686 0 return $aslocal;
687 }
688 0 return;
689 }
690  
691 sub mymkpath {
692 0 ▶ my($self, $aslocal_dir) = @_;
Subroutine mymkpath: not called CC=2 SCAR=17.9
Pod undocumented
693 0 mkpath($aslocal_dir);
694 0 ▶ $CPAN::Frontend->mywarn(qq{Warning: You are not allowed to write into }.
Branch: 1 branch
BranchTrueFalseTotal
unless -w $aslocal_dir 0 0 0
695 qq{directory "$aslocal_dir".
696 I\'ll continue, but if you encounter problems, they may be due
697 to insufficient permissions.\n}) unless -w $aslocal_dir;
698 }
699  
700 sub hostdlxxx {
701 38 ▶ my $self = shift;
Subroutine hostdlxxx: called CC=2 SCAR=7.0
Pod undocumented
702 38 my $level = shift;
703 38 my $scheme = shift;
704 38 my $h = shift;
705 38 ▶ $h = [ grep /^\Q$scheme\E:/, @$h ] if $scheme;
Branch: 1 branch
BranchTrueFalseTotal
if $scheme 38 0 38
706 38 my $method = "host$level";
707 38 $self->$method($h, @_);
708 }
709  
710 sub _set_attempt {
711 38 ▶ my($self,$stats,$method,$url) = @_;
Subroutine _set_attempt: called CC=1 SCAR=0.0
712 38 push @{$stats->{attempts}}, {
713 method => $method,
714 start => _mytime,
715 url => $url,
716 };
717 }
718  
719 # package CPAN::FTP;
720 sub hostdleasy { #called from hostdlxxx
721 38 ▶ my($self,$host_seq,$file,$aslocal,$stats) = @_;
Subroutine hostdleasy: called CC=61 SCAR=78.2
Pod undocumented
722 38 my($ro_url);
723 38 HOSTEASY: for $ro_url (@$host_seq) {
724 38 $self->_set_attempt($stats,"dleasy",$ro_url);
725 38 my $url = "$ro_url$file";
726 38 ▶ $self->debug("localizing perlish[$url]") if $CPAN::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::DEBUG 0 38 38
727 38 ▶ if ($url =~ /^file:/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($url =~ /^file:/) 38 0 38
728 38 my $l;
729 38 ▶ if ($CPAN::META->has_inst('URI::URL')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CPAN::META->has_inst('URI::URL')) { } 38 0 38
730 38 my $u = URI::URL->new($url);
731 38 $l = $u->file;
732 } else { # works only on Unix, is poorly constructed, but
733 # hopefully better than nothing.
734 # RFC 1738 says fileurl BNF is
735 # fileurl = "file://" [ host | "localhost" ] "/" fpath
736 # Thanks to "Mark D. Baushke" <mdb@cisco.com> for
737 # the code
738 0 ($l = $url) =~ s|^file://[^/]*/|/|; # discard the host part
739 0 $l =~ s|^file:||; # assume they
740 # meant
741 # file://localhost
742 0 ▶ $l =~ s|^/||s
Branch: 1 branch
BranchTrueFalseTotal
if not -f $l and $l =~ m[^/\w:] 0 0 0
Condition0%0/3
not -f $l and $l =~ m[^/\w:]
!ll&&!rl&&r
000
MC/DC0%0/2
not -f $l and $l =~ m[^/\w:]
not -f $l $l =~ m[^/\w:]
Truth table0%0/3
not(A) and B
A= not -f $lB= $l =~ m[^/\w:]
ABresult
0X0
100
111
743 if ! -f $l && $l =~ m|^/\w:|; # e.g. /P:
744 }
745 38 ▶ $self->debug("local file[$l]") if $CPAN::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::DEBUG 0 38 38
746 38 ▶ if ( -f $l && -r _) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $l and -r _) 28 10 38
Condition66%2/3
-f $l and -r _
!ll&&!rl&&r
10028
MC/DC50%1/2
-f $l and -r _
-f $l -r _
Truth table66%2/3
A and B
A= -f $lB= -r _
ABresult
0X0
100
111
747 28 $ThesiteURL = $ro_url;
748 28 return $l;
749 }
750 # If request is for a compressed file and we can find the
751 # uncompressed file also, return the path of the uncompressed file
752 # otherwise, decompress it and return the resulting path
753 10 ▶ if ($l =~ /(.+)\.gz$/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($l =~ /(.+)\.gz$/) { } 10 0 10
elsif (-f $l and -r _) { } 0 0 0
elsif (-f "$l.gz") { } 0 0 0
754 10 my $ungz = $1;
755 10 ▶ if ( -f $ungz && -r _) {
Branch: 2 branches
BranchTrueFalseTotal
if (-f $ungz and -r _) { } 10 0 10
elsif (-f $l and -r _) { } 0 0 0
Condition33%1/3
-f $ungz and -r _
!ll&&!rl&&r
0010
MC/DC0%0/2
-f $ungz and -r _
-f $ungz -r _
Truth table33%1/3
A and B
A= -f $ungzB= -r _
ABresult
0X0
100
111
756 10 $ThesiteURL = $ro_url;
757 10 return $ungz;
758 }
759 ▶ elsif (-f $l && -r _) {
Condition0%0/3
-f $l and -r _
!ll&&!rl&&r
000
MC/DC0%0/2
-f $l and -r _
-f $l -r _
Truth table0%0/3
A and B
A= -f $lB= -r _
ABresult
0X0
100
111
760 0 eval { CPAN::Tarzip->new($l)->gunzip($aslocal) };
761 0 ▶ if ( -f $aslocal && -s _) {
Branch: 3 branches
BranchTrueFalseTotal
if (-f $aslocal and -s _) { } 0 0 0
elsif (not -s $aslocal) { } 0 0 0
elsif (-f $l) { } 0 0 0
Condition0%0/3
-f $aslocal and -s _
!ll&&!rl&&r
000
MC/DC0%0/2
-f $aslocal and -s _
-f $aslocal -s _
Truth table0%0/3
A and B
A= -f $aslocalB= -s _
ABresult
0X0
100
111
762 0 $ThesiteURL = $ro_url;
763 0 return $aslocal;
764 }
765 elsif (! -s $aslocal) {
766 0 unlink $aslocal;
767 }
768 elsif (-f $l) {
769 0 ▶ $CPAN::Frontend->mywarn("Error decompressing '$l': $@\n")
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
770 if $@;
771 0 return;
772 }
773 }
774 }
775 # Otherwise, return the local file path if it exists
776 ▶ elsif ( -f $l && -r _) {
Condition0%0/3
-f $l and -r _
!ll&&!rl&&r
000
MC/DC0%0/2
-f $l and -r _
-f $l -r _
Truth table0%0/3
A and B
A= -f $lB= -r _
ABresult
0X0
100
111
777 0 $ThesiteURL = $ro_url;
778 0 return $l;
779 }
780 # If we can't find it, but there is a compressed version
781 # of it, then decompress it
782 elsif (-f "$l.gz") {
783 0 ▶ $self->debug("found compressed $l.gz") if $CPAN::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::DEBUG 0 0 0
784 0 eval { CPAN::Tarzip->new("$l.gz")->gunzip($aslocal) };
785 0 ▶ if ( -f $aslocal) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $aslocal) { } 0 0 0
786 0 $ThesiteURL = $ro_url;
787 0 return $aslocal;
788 }
789 else {
790 0 ▶ $CPAN::Frontend->mywarn("Error decompressing '$l': $@\n")
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
791 if $@;
792 0 return;
793 }
794 }
795 0 $CPAN::Frontend->mywarn("Could not find '$l'\n");
796 }
797 0 ▶ $self->debug("it was not a file URL") if $CPAN::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::DEBUG 0 0 0
798 0 ▶ if ($CPAN::META->has_usable('LWP')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($CPAN::META->has_usable('LWP')) { } 0 0 0
elsif ($url =~ /^http:/i and $CPAN::META->has_usable('HTTP::Tiny')) { } 0 0 0
799 0 $CPAN::Frontend->myprint("Fetching with LWP:\n$url\n");
800 0 ▶ unless ($Ua) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($CPAN::FTP::Ua) 0 0 0
801 0 CPAN::LWP::UserAgent->config;
802 0 eval { $Ua = CPAN::LWP::UserAgent->new; };
803 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
804 0 $CPAN::Frontend->mywarn("CPAN::LWP::UserAgent->new dies with $@\n");
805 }
806 }
807 0 my $res = $Ua->mirror($url, $aslocal);
808 0 ▶ if ($res->is_success) {
Branch: 2 branches
BranchTrueFalseTotal
if ($res->is_success) { } 0 0 0
elsif (not $url =~ /\.gz(?!\n)\Z/) { } 0 0 0
809 0 $ThesiteURL = $ro_url;
810 0 my $now = time;
811 0 utime $now, $now, $aslocal; # download time is more
812 # important than upload
813 # time
814 0 return $aslocal;
815 } elsif ($url !~ /\.gz(?!\n)\Z/) {
816 0 my $gzurl = "$url.gz";
817 0 $CPAN::Frontend->myprint("Fetching with LWP:\n$gzurl\n");
818 0 $res = $Ua->mirror($gzurl, "$aslocal.gz");
819 0 ▶ if ($res->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_success) 0 0 0
820 0 ▶ if (eval {CPAN::Tarzip->new("$aslocal.gz")->gunzip($aslocal)}) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { "CPAN::Tarzip"->new("$aslocal.gz")->gunzip($aslocal) } }) 0 0 0
821 0 $ThesiteURL = $ro_url;
822 0 return $aslocal;
823 }
824 }
825 } else {
826 0 $CPAN::Frontend->myprint(sprintf(
827 "LWP failed with code[%s] message[%s]\n",
828 $res->code,
829 $res->message,
830 ));
831 # Alan Burlison informed me that in firewall environments
832 # Net::FTP can still succeed where LWP fails. So we do not
833 # skip Net::FTP anymore when LWP is available.
834 }
835 ▶ } elsif ($url =~ /^http:/i && $CPAN::META->has_usable('HTTP::Tiny')) {
Condition0%0/3
$url =~ /^http:/i and $CPAN::META->has_usable("HTTP::Tiny")
!ll&&!rl&&r
000
MC/DC0%0/2
$url =~ /^http:/i and $CPAN::META->has_usable("HTTP::Tiny")
$url =~ /^http:/i $CPAN::META->has_usable("HTTP::Tiny")
Truth table0%0/3
A and B
A= $url =~ /^http:/iB= $CPAN::META->has_usable("HTTP::Tiny")
ABresult
0X0
100
111
836 0 require CPAN::HTTP::Client;
837 my $chc = CPAN::HTTP::Client->new(
838 proxy => $CPAN::Config->{http_proxy} || $ENV{http_proxy},
839 no_proxy => $CPAN::Config->{no_proxy} || $ENV{no_proxy},
840 0 ▶ );
Condition0%0/6
$CPAN::Config->{'http_proxy'} || $ENV{'http_proxy'}
l!l&&r!l&&!r
000
$CPAN::Config->{'no_proxy'} || $ENV{'no_proxy'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$CPAN::Config->{'http_proxy'} || $ENV{'http_proxy'}
$CPAN::Config->{'http_proxy'} $ENV{'http_proxy'}
MC/DC0%0/2
$CPAN::Config->{'no_proxy'} || $ENV{'no_proxy'}
$CPAN::Config->{'no_proxy'} $ENV{'no_proxy'}
Truth table0%0/3
A || B
A= $CPAN::Config->{'http_proxy'}B= $ENV{'http_proxy'}
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $CPAN::Config->{'no_proxy'}B= $ENV{'no_proxy'}
ABresult
1X1
011
000
841 0 ▶ for my $try ( $url, ( $url !~ /\.gz(?!\n)\Z/ ? "$url.gz" : () ) ) {
Branch: 1 branch
BranchTrueFalseTotal
!($url =~ /\.gz(?!\n)\Z/) ? : 0 0 0
842 0 $CPAN::Frontend->myprint("Fetching with HTTP::Tiny:\n$try\n");
843 0 my $res = eval { $chc->mirror($try, $aslocal) };
844 0 ▶ if ( $res && $res->{success} ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($res and $res->{'success'}) { } 0 0 0
elsif ($res and $res->{'status'} ne '599') { } 0 0 0
elsif ($res and $res->{'status'} eq '599') { } 0 0 0
Condition0%0/3
$res and $res->{"success"}
!ll&&!rl&&r
000
MC/DC0%0/2
$res and $res->{"success"}
$res $res->{"success"}
Truth table0%0/3
A and B
A= $resB= $res->{"success"}
ABresult
0X0
100
111
845 0 $ThesiteURL = $ro_url;
846 0 my $now = time;
847 0 utime $now, $now, $aslocal; # download time is more
848 # important than upload
849 # time
850 0 return $aslocal;
851 }
852 ▶ elsif ( $res && $res->{status} ne '599') {
Condition0%0/3
$res and $res->{"status"} ne 599
!ll&&!rl&&r
000
MC/DC0%0/2
$res and $res->{"status"} ne 599
$res $res->{"status"} ne 599
Truth table0%0/3
A and B
A= $resB= $res->{"status"} ne 599
ABresult
0X0
100
111
853 $CPAN::Frontend->myprint(sprintf(
854 "HTTP::Tiny failed with code[%s] message[%s]\n",
855 $res->{status},
856 $res->{reason},
857 )
858 0 );
859 }
860 ▶ elsif ( $res && $res->{status} eq '599') {
Condition0%0/3
$res and $res->{"status"} eq 599
!ll&&!rl&&r
000
MC/DC0%0/2
$res and $res->{"status"} eq 599
$res $res->{"status"} eq 599
Truth table0%0/3
A and B
A= $resB= $res->{"status"} eq 599
ABresult
0X0
100
111
861 $CPAN::Frontend->myprint(sprintf(
862 "HTTP::Tiny failed with an internal error: %s\n",
863 $res->{content},
864 )
865 0 );
866 }
867 else {
868 0 ▶ my $err = $@ || 'Unknown error';
Condition0%0/2
$@ || 'Unknown error'
l!l
00
MC/DC0%0/1
$@ || 'Unknown error'
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
869 0 $CPAN::Frontend->myprint(sprintf(
870 "Error downloading with HTTP::Tiny: %s\n", $err
871 )
872 );
873 }
874 }
875 }
876 0 ▶ return if $CPAN::Signal;
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::Signal 0 0 0
877 0 ▶ if ($url =~ m|^ftp://(.*?)/(.*)/(.*)|) {
Branch: 1 branch
BranchTrueFalseTotal
if ($url =~ m[^ftp://(.*?)/(.*)/(.*)]) 0 0 0
878 # that's the nice and easy way thanks to Graham
879 0 ▶ $self->debug("recognized ftp") if $CPAN::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::DEBUG 0 0 0
880 0 my($host,$dir,$getfile) = ($1,$2,$3);
881 0 ▶ if ($CPAN::META->has_usable('Net::FTP')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CPAN::META->has_usable('Net::FTP')) { } 0 0 0
882 0 $dir =~ s|/+|/|g;
883 0 $CPAN::Frontend->myprint("Fetching with Net::FTP:\n$url\n");
884 0 ▶ $self->debug("getfile[$getfile]dir[$dir]host[$host]" .
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::DEBUG 0 0 0
885 "aslocal[$aslocal]") if $CPAN::DEBUG;
886 0 ▶ if (CPAN::FTP->ftp_get($host,$dir,$getfile,$aslocal)) {
Branch: 1 branch
BranchTrueFalseTotal
if ("CPAN::FTP"->ftp_get($host, $dir, $getfile, $aslocal)) 0 0 0
887 0 $ThesiteURL = $ro_url;
888 0 return $aslocal;
889 }
890 0 ▶ if ($aslocal !~ /\.gz(?!\n)\Z/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($aslocal =~ /\.gz(?!\n)\Z/) 0 0 0
891 0 my $gz = "$aslocal.gz";
892 0 $CPAN::Frontend->myprint("Fetching with Net::FTP\n$url.gz\n");
893 0 ▶ if (CPAN::FTP->ftp_get($host,
Branch: 1 branch
BranchTrueFalseTotal
if ("CPAN::FTP"->ftp_get($host, $dir, "$getfile.gz", $gz) and eval { do { "CPAN::Tarzip"->new($gz)->gunzip($aslocal) } }) 0 0 0
Condition0%0/3
"CPAN::FTP"->ftp_get($host, $dir, "$getfile.gz", $gz) and eval { do { "CPAN::Tarzip"->new($gz)->gunzip($aslocal) } }
!ll&&!rl&&r
000
MC/DC0%0/2
"CPAN::FTP"->ftp_get($host, $dir, "$getfile.gz", $gz) and eval { do { "CPAN::Tarzip"->new($gz)->gunzip($aslocal) } }
"CPAN::FTP"->ftp_get($host, $dir, "$getfile.gz", $gz) eval { do { "CPAN::Tarzip"->new($gz)->gunzip($aslocal) } }
Truth table0%0/3
A and B
A= "CPAN::FTP"->ftp_get($host, $dir, "$getfile.gz", $gz)B= eval { do { "CPAN::Tarzip"->new($gz)->gunzip($aslocal) } }
ABresult
0X0
100
111
894 $dir,
895 "$getfile.gz",
896 $gz) &&
897 0 eval{CPAN::Tarzip->new($gz)->gunzip($aslocal)}
898 ) {
899 0 $ThesiteURL = $ro_url;
900 0 return $aslocal;
901 }
902 }
903 # next HOSTEASY;
904 } else {
905 0 ▶ CPAN->debug("Net::FTP does not count as usable atm") if $CPAN::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::DEBUG 0 0 0
906 }
907 }
908 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::can($ro_url, "text") and $ro_url->{"FROM"} eq "USER") 0 0 0
Condition0%0/3
UNIVERSAL::can($ro_url, "text") and $ro_url->{"FROM"} eq "USER"
!ll&&!rl&&r
000
MC/DC0%0/2
UNIVERSAL::can($ro_url, "text") and $ro_url->{"FROM"} eq "USER"
UNIVERSAL::can($ro_url, "text") $ro_url->{"FROM"} eq "USER"
Truth table0%0/3
A and B
A= UNIVERSAL::can($ro_url, "text")B= $ro_url->{"FROM"} eq "USER"
ABresult
0X0
100
111
909 UNIVERSAL::can($ro_url,"text")
910 and
911 $ro_url->{FROM} eq "USER"
912 ) {
913 ##address #17973: default URLs should not try to override
914 ##user-defined URLs just because LWP is not available
915 0 my $ret = $self->hostdlhard([$ro_url],$file,$aslocal,$stats);
916 0 ▶ return $ret if $ret;
Branch: 1 branch
BranchTrueFalseTotal
if $ret 0 0 0
917 }
918 0 ▶ return if $CPAN::Signal;
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::Signal 0 0 0
919 }
920 }
921  
922 # package CPAN::FTP;
923 sub hostdlhard {
924 0 ▶ my($self,$host_seq,$file,$aslocal,$stats) = @_;
Subroutine hostdlhard: not called CC=28 SCAR=67.0
Pod undocumented
925  
926 # Came back if Net::FTP couldn't establish connection (or
927 # failed otherwise) Maybe they are behind a firewall, but they
928 # gave us a socksified (or other) ftp program...
929  
930 0 my($ro_url);
931 0 ▶ my($devnull) = $CPAN::Config->{devnull} || "";
Condition0%0/2
$CPAN::Config->{'devnull'} || ''
l!l
00
MC/DC0%0/1
$CPAN::Config->{'devnull'} || ''
$CPAN::Config->{'devnull'}
Truth table0%0/2
A
A= $CPAN::Config->{'devnull'}
Aresult
11
00
932 # < /dev/null ";
933 0 my($aslocal_dir) = dirname($aslocal);
934 0 mkpath($aslocal_dir);
935 0 my $some_dl_success = 0;
936 0 my $any_attempt = 0;
937 0 HOSTHARD: for $ro_url (@$host_seq) {
938 0 $self->_set_attempt($stats,"dlhard",$ro_url);
939 0 my $url = "$ro_url$file";
940 0 my($proto,$host,$dir,$getfile);
941  
942 # Courtesy Mark Conty mark_conty@cargill.com change from
943 # if ($url =~ m|^ftp://(.*?)/(.*)/(.*)|) {
944 # to
945 0 ▶ if ($url =~ m|^([^:]+)://(.*?)/(.*)/(.*)|) {
Branch: 1 branch
BranchTrueFalseTotal
if ($url =~ m[^([^:]+)://(.*?)/(.*)/(.*)]) { } 0 0 0
946 # proto not yet used
947 0 ($proto,$host,$dir,$getfile) = ($1,$2,$3,$4);
948 } else {
949 0 next HOSTHARD; # who said, we could ftp anything except ftp?
950 }
951 0 ▶ next HOSTHARD if $proto eq "file"; # file URLs would have had
Branch: 1 branch
BranchTrueFalseTotal
if $proto eq "file" 0 0 0
952 # success above. Likely a bogus URL
953  
954 # making at least one attempt against a host
955 0 $any_attempt++;
956  
957 0 ▶ $self->debug("localizing funkyftpwise[$url]") if $CPAN::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::DEBUG 0 0 0
958  
959 # Try the most capable first and leave ncftp* for last as it only
960 # does FTP.
961 0 my $proxy_vars = $self->_proxy_vars($ro_url);
962 0 DLPRG: for my $f (qw(curl wget lynx ncftpget ncftp)) {
963 0 my $funkyftp = CPAN::HandleConfig->safe_quote($CPAN::Config->{$f});
964 0 ▶ next DLPRG unless defined $funkyftp;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $funkyftp 0 0 0
965 0 ▶ next DLPRG if $funkyftp =~ /^\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if $funkyftp =~ /^\s*$/ 0 0 0
966  
967 0 my($src_switch) = "";
968 0 my($chdir) = "";
969 0 my($stdout_redir) = " > \"$aslocal\"";
970 0 ▶ if ($f eq "lynx") {
Branch: 5 branches
BranchTrueFalseTotal
if ($f eq 'lynx') { } 0 0 0
elsif ($f eq 'ncftp') { } 0 0 0
elsif ($f eq 'wget') { } 0 0 0
elsif ($f eq 'curl') { } 0 0 0
elsif ($f eq 'ncftpget') { } 0 0 0
971 0 $src_switch = " -source";
972 } elsif ($f eq "ncftp") {
973 0 ▶ next DLPRG unless $url =~ m{\Aftp://};
Branch: 1 branch
BranchTrueFalseTotal
unless $url =~ m[\Aftp://] 0 0 0
974 0 $src_switch = " -c";
975 } elsif ($f eq "wget") {
976 0 $src_switch = " -O \"$aslocal\"";
977 0 $stdout_redir = "";
978 } elsif ($f eq 'curl') {
979 0 $src_switch = ' -L -f -s -S --netrc-optional';
980 0 ▶ if ($proxy_vars->{http_proxy}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($proxy_vars->{"http_proxy"}) 0 0 0
981 0 $src_switch .= qq{ -U "$proxy_vars->{proxy_user}:$proxy_vars->{proxy_pass}" -x "$proxy_vars->{http_proxy}"};
982 }
983 } elsif ($f eq "ncftpget") {
984 0 ▶ next DLPRG unless $url =~ m{\Aftp://};
Branch: 1 branch
BranchTrueFalseTotal
unless $url =~ m[\Aftp://] 0 0 0
985 0 $chdir = "cd $aslocal_dir && ";
986 0 $stdout_redir = "";
987 }
988 $CPAN::Frontend->myprint(
989 0 qq[
990 Trying with
991 $funkyftp$src_switch
992 to get
993 $url
994 ]);
995 0 my($system) =
996 "$chdir$funkyftp$src_switch \"$url\" $devnull$stdout_redir";
997 0 ▶ $self->debug("system[$system]") if $CPAN::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::DEBUG 0 0 0
998 0 my($wstatus) = system($system);
999 0 ▶ if ($f eq "lynx") {
Branch: 1 branch
BranchTrueFalseTotal
if ($f eq "lynx") 0 0 0
1000 # lynx returns 0 when it fails somewhere
1001 0 ▶ if (-s $aslocal) {
Branch: 1 branch
BranchTrueFalseTotal
if (-s $aslocal) { } 0 0 0
1002 0 my $content = do { local *FH;
1003 0 ▶ open FH, $aslocal or die;
Branch: 1 branch
BranchTrueFalseTotal
open FH, $aslocal or die 0 0 0
1004 0 local $/;
1005 0 <FH> };
1006 0 ▶ if ($content =~ /^<.*(<title>[45]|Error [45])/si) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ /^<.*(<title>[45]|Error [45])/is) 0 0 0
1007 0 $CPAN::Frontend->mywarn(qq{
1008 No success, the file that lynx has downloaded looks like an error message:
1009 $content
1010 });
1011 0 $CPAN::Frontend->mysleep(1);
1012 0 next DLPRG;
1013 }
1014 0 $some_dl_success++;
1015 } else {
1016 0 $CPAN::Frontend->myprint(qq{
1017 No success, the file that lynx has downloaded is an empty file.
1018 });
1019 0 next DLPRG;
1020 }
1021 }
1022 0 ▶ if ($wstatus == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wstatus == 0) { } 0 0 0
1023 0 ▶ if (-s $aslocal) {
Branch: 1 branch
BranchTrueFalseTotal
if (-s $aslocal) 0 0 0
1024 # Looks good
1025 0 $some_dl_success++;
1026 }
1027 0 $ThesiteURL = $ro_url;
1028 0 return $aslocal;
1029 } else {
1030 0 my $estatus = $wstatus >> 8;
1031 0 ▶ my $size = -f $aslocal ?
Branch: 1 branch
BranchTrueFalseTotal
-f $aslocal ? : 0 0 0
1032 ", left\n$aslocal with size ".-s _ :
1033 "\nWarning: expected file [$aslocal] doesn't exist";
1034 0 $CPAN::Frontend->myprint(qq{
1035 Function system("$system")
1036 returned status $estatus (wstat $wstatus)$size
1037 });
1038 }
1039 0 ▶ return if $CPAN::Signal;
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::Signal 0 0 0
1040 } # download/transfer programs (DLPRG)
1041 } # host
1042 0 ▶ return unless $any_attempt;
Branch: 1 branch
BranchTrueFalseTotal
unless $any_attempt 0 0 0
1043 0 ▶ if ($some_dl_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($some_dl_success) { } 0 0 0
1044 0 $CPAN::Frontend->mywarn("Warning: doesn't seem we had substantial success downloading '$aslocal'. Don't know how to proceed.\n");
1045 } else {
1046 0 $CPAN::Frontend->mywarn("Warning: no success downloading '$aslocal'. Giving up on it.\n");
1047 }
1048 0 return;
1049 }
1050  
1051 #-> CPAN::FTP::_proxy_vars
1052 sub _proxy_vars {
1053 2 ▶ my($self,$url) = @_;
Subroutine _proxy_vars: called CC=9 SCAR=23.1
1054 2 my $ret = +{};
1055 2 ▶ my $http_proxy = $CPAN::Config->{'http_proxy'} || $ENV{'http_proxy'};
Condition33%1/3
$CPAN::Config->{'http_proxy'} || $ENV{'http_proxy'}
l!l&&r!l&&!r
200
MC/DC0%0/2
$CPAN::Config->{'http_proxy'} || $ENV{'http_proxy'}
$CPAN::Config->{'http_proxy'} $ENV{'http_proxy'}
Truth table33%1/3
A || B
A= $CPAN::Config->{'http_proxy'}B= $ENV{'http_proxy'}
ABresult
1X1
011
000
1056 2 ▶ if ($http_proxy) {
Branch: 1 branch
BranchTrueFalseTotal
if ($http_proxy) 2 0 2
1057 2 my($host) = $url =~ m|://([^/:]+)|;
1058 2 my $want_proxy = 1;
1059 2 ▶ my $noproxy = $CPAN::Config->{'no_proxy'} || $ENV{'no_proxy'} || "";
Condition40%2/5
$CPAN::Config->{'no_proxy'} || $ENV{'no_proxy'} || ''
l!l
20
$CPAN::Config->{"no_proxy"} or $ENV{"no_proxy"}
l!l&&r!l&&!r
200
MC/DC0%0/2
$CPAN::Config->{'no_proxy'} || $ENV{'no_proxy'} || ''
$CPAN::Config->{"no_proxy"} $ENV{"no_proxy"}
Truth table33%1/3
A or B
A= $CPAN::Config->{"no_proxy"}B= $ENV{"no_proxy"}
ABresult
1X1
011
000
1060 2 my @noproxy = split /\s*,\s*/, $noproxy;
1061 2 ▶ if ($host) {
Branch: 1 branch
BranchTrueFalseTotal
if ($host) { } 2 0 2
1062 2 DOMAIN: for my $domain (@noproxy) {
1063 2 ▶ if ($host =~ /\Q$domain\E$/) { # cf. LWP::UserAgent
Branch: 1 branch
BranchTrueFalseTotal
if ($host =~ /\Q$domain\E$/) 1 1 2
1064 1 $want_proxy = 0;
1065 1 last DOMAIN;
1066 }
1067 }
1068 } else {
1069 0 $CPAN::Frontend->mywarn(" Could not determine host from http_proxy '$http_proxy'\n");
1070 }
1071 2 ▶ if ($want_proxy) {
Branch: 1 branch
BranchTrueFalseTotal
if ($want_proxy) 1 1 2
1072 1 my($user, $pass) =
1073 CPAN::HTTP::Credentials->get_proxy_credentials();
1074 1 $ret = {
1075 proxy_user => $user,
1076 proxy_pass => $pass,
1077 http_proxy => $http_proxy
1078 };
1079 }
1080 }
1081 2 return $ret;
1082 }
1083  
1084 # package CPAN::FTP;
1085 sub hostdlhardest {
1086 0 ▶ my($self,$host_seq,$file,$aslocal,$stats) = @_;
Subroutine hostdlhardest: not called CC=23 SCAR=63.1
Pod undocumented
1087  
1088 0 ▶ return unless @$host_seq;
Branch: 1 branch
BranchTrueFalseTotal
unless @$host_seq 0 0 0
1089 0 my($ro_url);
1090 0 my($aslocal_dir) = dirname($aslocal);
1091 0 mkpath($aslocal_dir);
1092 0 my $ftpbin = $CPAN::Config->{ftp};
1093 0 ▶ unless ($ftpbin && length $ftpbin && MM->maybe_command($ftpbin)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ftpbin and length $ftpbin and "MM"->maybe_command($ftpbin)) 0 0 0
Condition0%0/6
$ftpbin and length $ftpbin and "MM"->maybe_command($ftpbin)
!ll&&!rl&&r
000
$ftpbin and length $ftpbin
!ll&&!rl&&r
000
MC/DC0%0/3
$ftpbin and length $ftpbin and "MM"->maybe_command($ftpbin)
$ftpbin length $ftpbin "MM"->maybe_command($ftpbin)
Truth table0%0/4
A and B and C
A= $ftpbinB= length $ftpbinC= "MM"->maybe_command($ftpbin)
ABCresult
0XX0
10X0
1100
1111
1094 0 $CPAN::Frontend->myprint("No external ftp command available\n\n");
1095 0 return;
1096 }
1097 0 $CPAN::Frontend->mywarn(qq{
1098 As a last resort we now switch to the external ftp command '$ftpbin'
1099 to get '$aslocal'.
1100  
1101 Doing so often leads to problems that are hard to diagnose.
1102  
1103 If you're the victim of such problems, please consider unsetting the
1104 ftp config variable with
1105  
1106 o conf ftp ""
1107 o conf commit
1108  
1109 });
1110 0 $CPAN::Frontend->mysleep(2);
1111 0 HOSTHARDEST: for $ro_url (@$host_seq) {
1112 0 $self->_set_attempt($stats,"dlhardest",$ro_url);
1113 0 my $url = "$ro_url$file";
1114 0 ▶ $self->debug("localizing ftpwise[$url]") if $CPAN::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::DEBUG 0 0 0
1115 0 ▶ unless ($url =~ m|^ftp://(.*?)/(.*)/(.*)|) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($url =~ m[^ftp://(.*?)/(.*)/(.*)]) 0 0 0
1116 0 next;
1117 }
1118 0 my($host,$dir,$getfile) = ($1,$2,$3);
1119 0 my $timestamp = 0;
1120 0 my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,
1121 $ctime,$blksize,$blocks) = stat($aslocal);
1122 0 ▶ $timestamp = $mtime ||= 0;
Condition0%0/2
$mtime ||= 0
l!l
00
MC/DC0%0/1
$mtime ||= 0
$mtime
Truth table0%0/2
A
A= $mtime
Aresult
11
00
1123 0 my($netrc) = CPAN::FTP::netrc->new;
1124 0 my($netrcfile) = $netrc->netrc;
1125 0 ▶ my($verbose) = $CPAN::DEBUG{'FTP'} & $CPAN::DEBUG ? " -v" : "";
Branch: 1 branch
BranchTrueFalseTotal
$CPAN::DEBUG{'FTP'} & $CPAN::DEBUG ? : 0 0 0
1126 0 my $targetfile = File::Basename::basename($aslocal);
1127 0 my(@dialog);
1128 0 push(
1129 @dialog,
1130 "lcd $aslocal_dir",
1131 "cd /",
1132 map("cd $_", split /\//, $dir), # RFC 1738
1133 "bin",
1134 "passive",
1135 "get $getfile $targetfile",
1136 "quit"
1137 );
1138 0 ▶ if (! $netrcfile) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $netrcfile) { } 0 0 0
elsif ($netrc->hasdefault or $netrc->contains($host)) { } 0 0 0
1139 0 ▶ CPAN->debug("No ~/.netrc file found") if $CPAN::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::DEBUG 0 0 0
1140 ▶ } elsif ($netrc->hasdefault || $netrc->contains($host)) {
Condition0%0/3
$netrc->hasdefault or $netrc->contains($host)
l!l&&r!l&&!r
000
MC/DC0%0/2
$netrc->hasdefault or $netrc->contains($host)
$netrc->hasdefault $netrc->contains($host)
Truth table0%0/3
A or B
A= $netrc->hasdefaultB= $netrc->contains($host)
ABresult
1X1
011
000
1141 0 ▶ CPAN->debug(sprintf("hasdef[%d]cont($host)[%d]",
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::DEBUG 0 0 0
1142 $netrc->hasdefault,
1143 $netrc->contains($host))) if $CPAN::DEBUG;
1144 0 ▶ if ($netrc->protected) {
Branch: 1 branch
BranchTrueFalseTotal
if ($netrc->protected) { } 0 0 0
1145 0 my $dialog = join "", map { " $_\n" } @dialog;
1146 0 my $netrc_explain;
1147 0 ▶ if ($netrc->contains($host)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($netrc->contains($host)) { } 0 0 0
1148 0 $netrc_explain = "Relying that your .netrc entry for '$host' ".
1149 "manages the login";
1150 } else {
1151 0 $netrc_explain = "Relying that your default .netrc entry ".
1152 "manages the login";
1153 }
1154 0 $CPAN::Frontend->myprint(qq{
1155 Trying with external ftp to get
1156 '$url'
1157 $netrc_explain
1158 Sending the dialog
1159 $dialog
1160 }
1161 );
1162 0 $self->talk_ftp("$ftpbin$verbose $host",
1163 @dialog);
1164 0 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
1165 $atime,$mtime,$ctime,$blksize,$blocks) = stat($aslocal);
1166 0 ▶ $mtime ||= 0;
Condition0%0/2
$mtime ||= 0
l!l
00
MC/DC0%0/1
$mtime ||= 0
$mtime
Truth table0%0/2
A
A= $mtime
Aresult
11
00
1167 0 ▶ if ($mtime > $timestamp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mtime > $timestamp) { } 0 0 0
1168 0 $CPAN::Frontend->myprint("GOT $aslocal\n");
1169 0 $ThesiteURL = $ro_url;
1170 0 return $aslocal;
1171 } else {
1172 0 $CPAN::Frontend->myprint("Hmm... Still failed!\n");
1173 }
1174 0 ▶ return if $CPAN::Signal;
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::Signal 0 0 0
1175 } else {
1176 0 $CPAN::Frontend->mywarn(qq{Your $netrcfile is not }.
1177 qq{correctly protected.\n});
1178 }
1179 } else {
1180 0 $CPAN::Frontend->mywarn("Your ~/.netrc neither contains $host
1181 nor does it have a default entry\n");
1182 }
1183  
1184 # OK, they don't have a valid ~/.netrc. Use 'ftp -n'
1185 # then and login manually to host, using e-mail as
1186 # password.
1187 0 $CPAN::Frontend->myprint(qq{Issuing "$ftpbin$verbose -n"\n});
1188 0 unshift(
1189 @dialog,
1190 "open $host",
1191 "user anonymous $Config::Config{'cf_email'}"
1192 );
1193 0 my $dialog = join "", map { " $_\n" } @dialog;
1194 0 $CPAN::Frontend->myprint(qq{
1195 Trying with external ftp to get
1196 $url
1197 Sending the dialog
1198 $dialog
1199 }
1200 );
1201 0 $self->talk_ftp("$ftpbin$verbose -n", @dialog);
1202 0 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
1203 $atime,$mtime,$ctime,$blksize,$blocks) = stat($aslocal);
1204 0 ▶ $mtime ||= 0;
Condition0%0/2
$mtime ||= 0
l!l
00
MC/DC0%0/1
$mtime ||= 0
$mtime
Truth table0%0/2
A
A= $mtime
Aresult
11
00
1205 0 ▶ if ($mtime > $timestamp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mtime > $timestamp) { } 0 0 0
1206 0 $CPAN::Frontend->myprint("GOT $aslocal\n");
1207 0 $ThesiteURL = $ro_url;
1208 0 return $aslocal;
1209 } else {
1210 0 $CPAN::Frontend->myprint("Bad luck... Still failed!\n");
1211 }
1212 0 ▶ return if $CPAN::Signal;
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::Signal 0 0 0
1213 0 $CPAN::Frontend->mywarn("Can't access URL $url.\n\n");
1214 0 $CPAN::Frontend->mysleep(2);
1215 } # host
1216 }
1217  
1218 # package CPAN::FTP;
1219 sub talk_ftp {
1220 0 ▶ my($self,$command,@dialog) = @_;
Subroutine talk_ftp: not called CC=4 SCAR=30.0
Pod undocumented
1221 0 my $fh = FileHandle->new;
1222 0 ▶ $fh->open("|$command") or die "Couldn't open ftp: $!";
Branch: 1 branch
BranchTrueFalseTotal
$fh->open("|$command") or die "Couldn't open ftp: $!" 0 0 0
1223 0 foreach (@dialog) { $fh->print("$_\n") }
1224 0 $fh->close; # Wait for process to complete
1225 0 my $wstatus = $?;
1226 0 my $estatus = $wstatus >> 8;
1227 0 ▶ $CPAN::Frontend->myprint(qq{
Branch: 1 branch
BranchTrueFalseTotal
if $wstatus 0 0 0
1228 Subprocess "|$command"
1229 returned status $estatus (wstat $wstatus)
1230 }) if $wstatus;
1231 }
1232  
1233 # find2perl needs modularization, too, all the following is stolen
1234 # from there
1235 # CPAN::FTP::ls
1236 sub ls {
1237 0 ▶ my($self,$name) = @_;
Subroutine ls: not called CC=14 SCAR=53.5
Pod undocumented
1238 0 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$sizemm,
1239 $atime,$mtime,$ctime,$blksize,$blocks) = lstat($name);
1240  
1241 0 my($perms,%user,%group);
1242 0 my $pname = $name;
1243  
1244 0 ▶ if ($blocks) {
Branch: 1 branch
BranchTrueFalseTotal
if ($blocks) { } 0 0 0
1245 0 $blocks = int(($blocks + 1) / 2);
1246 }
1247 else {
1248 0 $blocks = int(($sizemm + 1023) / 1024);
1249 }
1250  
1251 0 ▶ if (-f _) { $perms = '-'; }
Branch: 6 branches
BranchTrueFalseTotal
if (-f _) { } 0 0 0
elsif (-d _) { } 0 0 0
elsif (-c _) { } 0 0 0
elsif (-b _) { } 0 0 0
elsif (-p _) { } 0 0 0
elsif (-S _) { } 0 0 0
1252 0 elsif (-d _) { $perms = 'd'; }
1253 0 elsif (-c _) { $perms = 'c'; $sizemm = &sizemm; }
1254 0 elsif (-b _) { $perms = 'b'; $sizemm = &sizemm; }
1255 0 elsif (-p _) { $perms = 'p'; }
1256 0 elsif (-S _) { $perms = 's'; }
1257 0 else { $perms = 'l'; $pname .= ' -> ' . readlink($_); }
1258  
1259 0 my(@rwx) = ('---','--x','-w-','-wx','r--','r-x','rw-','rwx');
1260 0 my(@moname) = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
1261 0 my $tmpmode = $mode;
1262 0 my $tmp = $rwx[$tmpmode & 7];
1263 0 $tmpmode >>= 3;
1264 0 $tmp = $rwx[$tmpmode & 7] . $tmp;
1265 0 $tmpmode >>= 3;
1266 0 $tmp = $rwx[$tmpmode & 7] . $tmp;
1267 0 ▶ substr($tmp,2,1) =~ tr/-x/Ss/ if -u _;
Branch: 1 branch
BranchTrueFalseTotal
if -u _ 0 0 0
1268 0 ▶ substr($tmp,5,1) =~ tr/-x/Ss/ if -g _;
Branch: 1 branch
BranchTrueFalseTotal
if -g _ 0 0 0
1269 0 ▶ substr($tmp,8,1) =~ tr/-x/Tt/ if -k _;
Branch: 1 branch
BranchTrueFalseTotal
if -k _ 0 0 0
1270 0 $perms .= $tmp;
1271  
1272 0 ▶ my $user = $user{$uid} || $uid; # too lazy to implement lookup
Condition0%0/3
$user{$uid} || $uid
l!l&&r!l&&!r
000
MC/DC0%0/2
$user{$uid} || $uid
$user{$uid} $uid
Truth table0%0/3
A || B
A= $user{$uid}B= $uid
ABresult
1X1
011
000
1273 0 ▶ my $group = $group{$gid} || $gid;
Condition0%0/3
$group{$gid} || $gid
l!l&&r!l&&!r
000
MC/DC0%0/2
$group{$gid} || $gid
$group{$gid} $gid
Truth table0%0/3
A || B
A= $group{$gid}B= $gid
ABresult
1X1
011
000
1274  
1275 0 my($sec,$min,$hour,$mday,$mon,$year) = localtime($mtime);
1276 0 my($timeyear);
1277 0 my($moname) = $moname[$mon];
1278 0 ▶ if (-M _ > 365.25 / 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (-M _ > 182.625) { } 0 0 0
1279 0 $timeyear = $year + 1900;
1280 }
1281 else {
1282 0 $timeyear = sprintf("%02d:%02d", $hour, $min);
1283 }
1284  
1285 0 sprintf "%5lu %4ld %-10s %2d %-8s %-8s %8s %s %2d %5s %s\n",
1286 $ino,
1287 $blocks,
1288 $perms,
1289 $nlink,
1290 $user,
1291 $group,
1292 $sizemm,
1293 $moname,
1294 $mday,
1295 $timeyear,
1296 $pname;
1297 }
1298  
1299 24 1;
« blib/lib/CPAN/FirstTime.pm ↑ Summary blib/lib/CPAN.pm »