summaryrefslogtreecommitdiffstats
path: root/urpm
diff options
context:
space:
mode:
authorRafael Garcia-Suarez <rgarciasuarez@mandriva.org>2004-06-23 14:16:40 +0000
committerRafael Garcia-Suarez <rgarciasuarez@mandriva.org>2004-06-23 14:16:40 +0000
commitc13069d9cf136a8f3ae26e9919b278c7414a0086 (patch)
tree376534c9b8eb610655c81b317165c272cac318d0 /urpm
parentc0a9b1584cbeab6476686e4d2b18b0a4e813af3c (diff)
downloadurpmi-c13069d9cf136a8f3ae26e9919b278c7414a0086.tar
urpmi-c13069d9cf136a8f3ae26e9919b278c7414a0086.tar.gz
urpmi-c13069d9cf136a8f3ae26e9919b278c7414a0086.tar.bz2
urpmi-c13069d9cf136a8f3ae26e9919b278c7414a0086.tar.xz
urpmi-c13069d9cf136a8f3ae26e9919b278c7414a0086.zip
New code to write urpmi.cfg.
Diffstat (limited to 'urpm')
-rw-r--r--urpm/cfg.pm33
1 files changed, 30 insertions, 3 deletions
diff --git a/urpm/cfg.pm b/urpm/cfg.pm
index f30c8b0d..0d9238d2 100644
--- a/urpm/cfg.pm
+++ b/urpm/cfg.pm
@@ -34,18 +34,21 @@ appropriate error message.)
=item dump_config($file, $config)
+Does the opposite: write the configuration file, from the same data structure.
+Returns 1 on success, 0 on failure.
+
=cut
our $err;
-sub _syntax_error () { $err = N("syntax error in config file at line %s" }
+sub _syntax_error () { $err = N("syntax error in config file at line %s") }
sub load_config ($) {
my ($file) = @_;
my %config;
my $medium = undef;
$err = '';
- open my $f, $file or do { $err = "Can't read $file: $!\n"; return }
+ open my $f, $file or do { $err = "Can't read $file: $!\n"; return };
local $_;
while (<$f>) {
chomp;
@@ -67,7 +70,7 @@ sub load_config ($) {
$medium = '';
next;
}
- if (/^(.*?[^\\])\s+(?:(.*?[^\\])\s+)?{$/ { #-} medium definition
+ if (/^(.*?[^\\])\s+(?:(.*?[^\\])\s+)?{$/) { #-} medium definition
$config{ $medium = unquotespace $1 }{url} = unquotespace $2;
next;
}
@@ -114,6 +117,30 @@ sub load_config ($) {
sub dump_config ($$) {
my ($file, $config) = @_;
+ my @media = sort {
+ return 0 if $a eq $b;
+ return -1 if $a eq '';
+ return 1 if $b eq '';
+ return $a cmp $b;
+ } keys %$config;
+ open my $f, '>', $file or do {
+ $err = "Can't write to $file: $!\n";
+ return 0;
+ };
+ print $f "# generated ".(scalar localtime)."\n";
+ for my $m (@media) {
+ print $f quotespace($m), ' ', quotespace($config->{$m}{url}), " {\n";
+ for (grep { $_ ne 'url' } keys %{$config->{$m}}) {
+ if (/^(update|ignore|synthesis|virtual)$/) {
+ print $f " $_\n";
+ } else {
+ print $f " $_: $config->{$m}{$_}\n";
+ }
+ }
+ print $f "}\n\n";
+ }
+ close $f;
+ return 1;
}
__END__