OK, I've got a way to test the code with a working, private, proxy and
I have not been able to reproduce the bug.

To test, I disabled the route to the specific mirror used for the
download (ftp.fr.debian.org):

# route add -host 212.27.32.66 reject
and re-enabled it later:
# route del -host 212.27.32.66 reject

(The test script is run as a user, not as root, so this is done
separately.)

With the route disabled, the test script (which looks for a file
on an ftp:// apt source using the same lwpprogress subroutine as
apt-cross) fails:

$ ./test.pl 
$VAR1 = {};
 to download: (nothing to
do)                                                                             
                          ]
Server Error: LWP::Protocol::MyFTP: connect: Network is unreachable :
Error. Failed to locate . Died at ./test.pl line 22.

With http_proxy set, it still fails. With ftp_proxy set, the
*unmodified* test script works:

(Name of the actual private proxy obfuscated for the bug report).

$ export ftp_proxy=http://proxy.foobar.net:3128/
$ ./test.pl 
$VAR1 = {
          'ftp' => 'http://proxy.foobar.net:3128/'
        };
 to download: 100%
[================================================================================================================]
D 0h00m00s

With the modified script (uncommenting the ua->env_proxy call), nothing
changes! If the variable is set, it works, irrespective of changes in
the script itself.

Once the route is reset, everything is back to normal.

So, it's http_proxy for http:// sources and ftp_proxy for ftp://
sources. (Verify by changing the prefix of the URL in the test script to
ftp:// instead of http:// and vice-versa.)

If http is set with the route disabled and the source is specified as
ftp://, it will fail to use the proxy. Vice versa is also true.

When the variable matches the prefix to the source, the proxy is used
without any changes to apt-cross. All other downloads are managed by
calling apt directly.

All this with the *unmodified* test script that doesn't explicitly look
for the proxy variable - that is done internally in LWP.

Adding the extra line makes absolutely no difference.

Therefore, I'm happy that apt-cross does the right thing under test and
that any problems are with your proxy config and/or apt config.

I'm happy to add a note to the manpage about which variable to set and
when but apart from that, this is not a bug in the code.

I'm attaching the test script.

I'll close this bug when the manpage is updated but I will not be
making changes to apt-cross itself.

-- 


Neil Williams
=============
http://www.data-freedom.org/
http://www.nosoftwarepatents.com/
http://www.linux.codehelp.co.uk/

#!/usr/bin/perl

use LWP::Simple;
use LWP::Simple qw($ua);
use Term::ProgressBar;

$verbose = 3;
unlink ("libqof2_0.8.0-1_armel.deb");
$uri = "ftp://ftp.fr.debian.org/debian/pool/main/q/qof/libqof2_0.8.0-1_armel.deb";;

$deb = lwpprogress($uri);
while (is_error($deb) and (scalar @$prefix > 0))
{
	$server = pop @$prefix;
	$uri = $server . $path;
	print "Trying: path=$uri\n" if ($verbose >= 2);
	$deb = lwpprogress($uri);
}
if (is_error($deb))
{
	warn "$progname: Error. Failed to locate $pkg.\n";
	die;
}

use Data::Dumper;
sub lwpprogress
{
	my $url = shift;
	my $errcode;
	my $uri = URI->new($url);
#	$ua->env_proxy;
	print Dumper ($ua->{'proxy'});
	my $path = $uri->path;
	my $output = 0;
	my $target_is_set = 0;
	my $next_so_far = 0;
	$path =~ s{.*/}{};
	return unless length $path;
	# md5sum already checked so if it exists, it's borked.
	unlink ($path) if -e $path;
	open my $outhandle, ">", $path or die "Cannot create $path: $!";
	if ($verbose < 1)
	{
		$errcode = $ua->get ($url,":content_cb" => sub {
			my ($chunk, $response, $protocol) = @_;
			print {$outhandle} $chunk;
		});
	}
	else
	{
		my $title = $download_count." to download";
		my $bar = Term::ProgressBar->new({ name => $title, count => 1024, ETA => 'linear'});
		$errcode = $ua->get ($url,":content_cb" => sub {
			my ($chunk, $response, $protocol) = @_;
			unless ($target_is_set) {
				if (my $cl = $response->content_length) {
					$bar->target($cl);
					$target_is_set = 1;
				} else {
					$bar->target($output + 2 * length $chunk);
				}
			}
			$output += length $chunk;
			print {$outhandle} $chunk;
			if ($output >= $next_so_far) {
				$next_so_far = $bar->update($output);
			}
		});
		$bar->target($output);
		$bar->update($output);
	}
	print "Server Error: " . $errcode->message . "\n"
		if ((is_error($errcode->code)) and ($verbose >= 1));
	close ($outhandle);
	$download_count--;
	return $errcode->code;
}

Attachment: pgp2RIloifLdY.pgp
Description: PGP signature

Reply via email to