summaryrefslogtreecommitdiffstats
path: root/urpm/cfg.pm
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2008-02-14 10:47:50 +0000
committerPascal Rigaux <pixel@mandriva.com>2008-02-14 10:47:50 +0000
commitdf55c40c5806b754c3ca717a3d79a853c2c9982c (patch)
tree03d67eef378fcab884b103f0a1817c7a62b3da9c /urpm/cfg.pm
parentfea31ffed0e831f446c6a4518483f24ae72a7588 (diff)
downloadurpmi-df55c40c5806b754c3ca717a3d79a853c2c9982c.tar
urpmi-df55c40c5806b754c3ca717a3d79a853c2c9982c.tar.gz
urpmi-df55c40c5806b754c3ca717a3d79a853c2c9982c.tar.bz2
urpmi-df55c40c5806b754c3ca717a3d79a853c2c9982c.tar.xz
urpmi-df55c40c5806b754c3ca717a3d79a853c2c9982c.zip
- urpmi handles /etc/urpmi/media.d/*.cfg
as an alternative to using urpmi.addmedia nb: need documentation
Diffstat (limited to 'urpm/cfg.pm')
-rw-r--r--urpm/cfg.pm63
1 files changed, 63 insertions, 0 deletions
diff --git a/urpm/cfg.pm b/urpm/cfg.pm
index a1c24d3f..634a188d 100644
--- a/urpm/cfg.pm
+++ b/urpm/cfg.pm
@@ -252,6 +252,69 @@ sub dump_config_raw {
1;
}
+sub load_ini_config_file_raw {
+ my ($file, $b_norewrite) = @_;
+
+ require Config::IniFiles;
+ my $cfg = Config::IniFiles->new('-file' => $file);
+ [ map {
+ my $section = $_;
+ my %h = map {
+ my $v = $cfg->val($section, $_);
+ $v = expand_line($v) if !$b_norewrite;
+ $_ => $v;
+ } $cfg->Parameters($section);
+ { conf_file__rel_media => $section, %h };
+ } $cfg->Sections ];
+}
+
+sub write_ini_config {
+ my ($file, $blocks) = @_;
+
+ if (@$blocks == 0) {
+ unlink $file;
+ return;
+ }
+ my $modified;
+
+ require Config::IniFiles;
+ my $cfg = Config::IniFiles->new('-file' => $file);
+ if ($cfg) {
+ # remove dropped blocks
+ foreach (difference2([ $cfg->Sections ], [ map { $_->{name} } @$blocks ])) {
+ $cfg->DeleteSection($_);
+ $modified = 1;
+ }
+ } else {
+ $cfg = Config::IniFiles->new;
+ }
+
+ my %uniq;
+
+ foreach (@$blocks) {
+ my %h = %$_;
+ my $section = delete $h{conf_file__rel_media} || '_';
+ $uniq{$section}++ or die "conflicting conf_file__rel_media value\n";
+
+ foreach (difference2([ $cfg->Parameters($section) ], [ keys %h ])) {
+ # remove those options which are no more wanted
+ $cfg->delval($section, $_);
+ $modified = 1;
+ }
+ foreach (keys %h) {
+ my $old_v = $cfg->getval($section, $_);
+ my $v = substitute_back($h{$_}, $old_v);
+ if ($old_v ne $v) {
+ $cfg->setval($section, $_, $v);
+ $modified = 1;
+ }
+ }
+ }
+ if ($modified) {
+ $cfg->RewriteConfig;
+ }
+}
+
#- routines to handle mirror list location
#- Default mirror list