summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Blin <oblin@mandriva.org>2004-01-26 22:20:57 +0000
committerOlivier Blin <oblin@mandriva.org>2004-01-26 22:20:57 +0000
commitc9fdb6d4e5b72adba69f81692ee12c2e20366a85 (patch)
tree927d0f51c84340976d6ae781f31aba59eca43835
parent80f4f65fcc51e585aa165e95710b37194b5ae5a3 (diff)
downloadurpmi-c9fdb6d4e5b72adba69f81692ee12c2e20366a85.tar
urpmi-c9fdb6d4e5b72adba69f81692ee12c2e20366a85.tar.gz
urpmi-c9fdb6d4e5b72adba69f81692ee12c2e20366a85.tar.bz2
urpmi-c9fdb6d4e5b72adba69f81692ee12c2e20366a85.tar.xz
urpmi-c9fdb6d4e5b72adba69f81692ee12c2e20366a85.zip
add downloader option in global config section
-rw-r--r--urpm.pm21
-rwxr-xr-xurpmi11
-rwxr-xr-xurpmi.addmedia7
-rw-r--r--urpmi.spec1
-rwxr-xr-xurpmq7
5 files changed, 23 insertions, 24 deletions
diff --git a/urpm.pm b/urpm.pm
index 7d34fb38..eaf8a58a 100644
--- a/urpm.pm
+++ b/urpm.pm
@@ -45,7 +45,8 @@ sub new {
provides => {},
depslist => [],
- sync => \&sync_webfetch, #- first argument is directory, others are url to fetch.
+ #- sync: first argument is directory, others are url to fetch.
+ sync => sub { $self->sync_webfetch(@_) },
proxy => get_proxy(),
options => {},
@@ -118,6 +119,7 @@ sub unquotespace { local $_ = $_[0] || ''; s/\\(\s)/$1/g; $_ }
#- syncing algorithms, currently is implemented wget and curl methods,
#- webfetch is trying to find the best (and one which will work :-)
sub sync_webfetch {
+ my $urpm = shift @_;
my $options = shift @_;
my %files;
#- extract files according to protocol supported.
@@ -132,12 +134,21 @@ sub sync_webfetch {
delete @files{qw(removable file)};
}
if ($files{ftp} || $files{http} || $files{https}) {
- if (-x "/usr/bin/curl" && (! ref($options) || $options->{prefer} ne 'wget' || ! -x "/usr/bin/wget")) {
+ my @webfetch = qw(curl wget);
+ my @available_webfetch = grep { -x "/usr/bin/$_" } @webfetch;
+ my $prefered;
+ #- use user default downloader if provided and available
+ if ($urpm->{options}{downloader}) {
+ $prefered = find { $_ eq $urpm->{options}{downloader} } @available_webfetch;
+ }
+ #- else first downloader of @webfetch is the default one
+ $prefered ||= $available_webfetch[0];
+ if ($prefered eq 'curl') {
sync_curl($options, @{$files{ftp} || []}, @{$files{http} || []}, @{$files{https} || []});
- } elsif (-x "/usr/bin/wget") {
+ } elsif ($prefered eq 'wget') {
sync_wget($options, @{$files{ftp} || []}, @{$files{http} || []}, @{$files{https} || []});
} else {
- die N("no webfetch (curl or wget currently) found\n");
+ die N("no webfetch (" . join(" or ", @webfetch) . " currently) found\n");
}
delete @files{qw(ftp http https)};
}
@@ -472,7 +483,7 @@ sub read_config {
$no and $urpm->{options}{$k} = ! $urpm->{options}{$k} || 0;
}
next;
- } elsif (($k, $v) = /^(limit-rate|excludepath|key[\-_]ids|split-(?:level|length)|priority-upgrade)\s*:\s*(.*)$/) {
+ } elsif (($k, $v) = /^(limit-rate|excludepath|key[\-_]ids|split-(?:level|length)|priority-upgrade|downloader)\s*:\s*(.*)$/) {
unless (exists($urpm->{options}{$k})) {
$v =~ /^'([^']*)'$/ and $v = $1; $v =~ /^"([^"]*)"$/ and $v = $1;
$urpm->{options}{$k} = $v;
diff --git a/urpmi b/urpmi
index c6cb6e87..996b5c84 100755
--- a/urpmi
+++ b/urpmi
@@ -38,7 +38,6 @@ my $split_level = 20;
my $split_length = 1;
my $force = 0;
my $parallel = '';
-my $sync;
my $X = 0;
my $WID = 0;
my $all = 0;
@@ -178,11 +177,8 @@ while (defined($_ = shift @argv)) {
/^--allow-nodeps$/ and do { $urpm->{options}{'allow-nodeps'} = 1; next };
/^--allow-force$/ and do { $urpm->{options}{'allow-force'} = 1; next };
/^--parallel$/ and do { push @nextargv, \$parallel; next };
- /^--wget$/ and do { $sync = sub { my $options = shift @_;
- if (ref $options) { $options->{prefer} = 'wget' }
- else { $options = { dir => $options, prefer => 'wget' } }
- urpm::sync_webfetch($options, @_) }; next };
- /^--curl$/ and do { $sync = \&urpm::sync_webfetch; next };
+ /^--wget$/ and do { $urpm->{options}{downloader} = 'wget'; next };
+ /^--curl$/ and do { $urpm->{options}{downloader} = 'curl'; next };
/^--limit-rate$/ and do { push @nextargv, \$urpm->{options}{'limit-rate'}; next };
/^--proxy$/ and do {
my ($proxy, $port) = ($_ = shift @argv) =~ m,^(?:http://)?([^:]+(:\d+)?)/*$, or
@@ -316,9 +312,6 @@ if ($log) {
open SAVEERR, ">&STDERR"; select SAVEERR; $| = 1;
}
-#- use specific sync routine.
-$sync and $urpm->{sync} = $sync;
-
#- remove verbose if not asked.
unless ($bug) {
$urpm->{fatal} = sub { printf SAVEERR "%s\n", $_[1]; exit($_[0]) };
diff --git a/urpmi.addmedia b/urpmi.addmedia
index caecc345..5e0f3f38 100755
--- a/urpmi.addmedia
+++ b/urpmi.addmedia
@@ -90,11 +90,8 @@ and [options] are from
/^--?h$/ and next;
/^--?f$/ and ++$options{force}, next;
/^--?z$/ and ++$options{compress}, next;
- /^--wget$/ and $urpm->{sync} = sub { my $options = shift @_;
- if (ref $options) { $options->{prefer} = 'wget' }
- else { $options = { dir => $options, prefer => 'wget' } }
- urpm::sync_webfetch($options, @_) }, next;
- /^--curl$/ and $urpm->{sync} = \&urpm::sync_webfetch, next;
+ /^--wget$/ and $urpm->{options}{downloader} = 'wget', next;
+ /^--curl$/ and $urpm->{options}{downloader} = 'curl', next;
/^--limit-rate$/ and do { $options{limit_rate} = shift @_; next };
/^--proxy$/ and do {
my ($proxy, $port) = ($_ = shift @_) =~ m,^(?:http://)?([^:]+(:\d+)?)/*$, or
diff --git a/urpmi.spec b/urpmi.spec
index a94120c9..4a08dc8c 100644
--- a/urpmi.spec
+++ b/urpmi.spec
@@ -237,6 +237,7 @@ $urpm->update_media(nolock => 1, nopubkey => 1);
%changelog
* Wed Jan 21 2004 Olivier Blin <blino@mandrake.org> 4.4.3-1mdk
+- add downloader option in global config section
- better error reporting for curl
- fix urpmq -i on media with synthesis hdlist
- fix --limit-rate in man pages (it's in bytes/sec)
diff --git a/urpmq b/urpmq
index 4c96516c..d8dd1580 100755
--- a/urpmq
+++ b/urpmq
@@ -120,11 +120,8 @@ while (defined($_ = shift @ARGV)) {
/^--root$/ and do { push @nextargv, \$query->{root}; next };
/^--use-distrib$/ and do { push @nextargv, \$query->{usedistrib}; next };
/^--parallel$/ and do { push @nextargv, \$query->{parallel}; next };
- /^--wget$/ and do { $urpm->{sync} = sub { my $options = shift @_;
- if (ref($options)) { $options->{prefer} = 'wget' }
- else { $options = { dir => $options, prefer => 'wget' } }
- urpm::sync_webfetch($options, @_) }; next };
- /^--curl$/ and do { $urpm->{sync} = \&urpm::sync_webfetch; next };
+ /^--wget$/ and do { $urpm->{options}{downloader} = 'wget'; next };
+ /^--curl$/ and do { $urpm->{options}{downloader} = 'curl'; next };
/^--proxy$/ and do {
my ($proxy, $port) = ($_ = shift @ARGV) =~ m,^(?:http://)?([^:]+(:\d+)?)/*$, or
die N("bad proxy declaration on command line\n");