diff options
author | Rafael Garcia-Suarez <rgarciasuarez@mandriva.org> | 2004-06-30 06:54:29 +0000 |
---|---|---|
committer | Rafael Garcia-Suarez <rgarciasuarez@mandriva.org> | 2004-06-30 06:54:29 +0000 |
commit | dfc692d5cfbb26fdc6494d862c6c14691b7fe986 (patch) | |
tree | 15edb86e837dd6f81bb61ffc94a1de84cb07272f /urpm | |
parent | a39274fe2de1263ba7fd9bcb8fd7b2ff977e060b (diff) | |
download | urpmi-dfc692d5cfbb26fdc6494d862c6c14691b7fe986.tar urpmi-dfc692d5cfbb26fdc6494d862c6c14691b7fe986.tar.gz urpmi-dfc692d5cfbb26fdc6494d862c6c14691b7fe986.tar.bz2 urpmi-dfc692d5cfbb26fdc6494d862c6c14691b7fe986.tar.xz urpmi-dfc692d5cfbb26fdc6494d862c6c14691b7fe986.zip |
Functions to write proxy.cfg (and regression tests)
Diffstat (limited to 'urpm')
-rw-r--r-- | urpm/download.pm | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/urpm/download.pm b/urpm/download.pm index f94ba20a..b0e7b01d 100644 --- a/urpm/download.pm +++ b/urpm/download.pm @@ -17,11 +17,13 @@ sub import () { foreach my $symbol (qw(get_proxy propagate_sync_callback sync_file sync_wget sync_curl sync_rsync sync_ssh + set_proxy_config dump_proxy_config )) { *{$c.'::'.$symbol} = *$symbol; } } +#- parses proxy.cfg (private) sub load_proxy_config () { return if defined $proxy_config; open my $f, $PROXY_CFG or $proxy_config = {}, return; @@ -32,7 +34,7 @@ sub load_proxy_config () { $proxy_config->{$1 || ''}{$2} = $3; next; } - if (/^(?:(.*):\s*)?proxy_user\s*=\s*(.*)(?::(.*))?$/) { + if (/^(?:(.*):\s*)?proxy_user\s*=\s*([^:]*)(?::(.*))?$/) { $proxy_config->{$1 || ''}{user} = $2; $proxy_config->{$1 || ''}{pwd} = $3 if defined $3; next; @@ -41,6 +43,26 @@ sub load_proxy_config () { close $f; } +#- writes proxy.cfg +sub dump_proxy_config () { + return 0 unless defined $proxy_config; #- hasn't been read yet + open my $f, '>', $PROXY_CFG or return 0; + print $f "# generated ".(scalar localtime)."\n"; + for ('', sort grep { !/^(|cmd_line)$/ } keys %$proxy_config) { + my $m = $_ eq '' ? '' : "$_:"; + my $p = $proxy_config->{$_}; + for (qw(http_proxy ftp_proxy)) { + defined $p->{$_} && $p->{$_} ne '' + and print $f "$m$_=$p->{$_}\n"; + } + defined $p->{user} && $p->{user} ne '' + and print $f "${m}proxy_user=$p->{user}:$p->{pwd}\n"; + } + close $f; + chmod 0600, $PROXY_CFG; #- may contain passwords + return 1; +} + #- reads and loads the proxy.cfg file ; #- returns the global proxy settings (without arguments) or the #- proxy settings for the specified media (with a media name as argument) @@ -70,6 +92,12 @@ sub set_cmdline_proxy { $proxy_config->{cmd_line}{$_} = $h{$_} for keys %h; } +#- changes permanently the proxy settings +sub set_proxy_config { + my ($key, $value, $o_media) = @_; + $proxy_config->{$o_media || ''}{$key} = $value; +} + #- set up the environment for proxy usage for the appropriate tool. #- returns an array of command-line arguments. sub set_proxy { |