diff options
Diffstat (limited to 'lib/MDV/Distribconf')
-rw-r--r-- | lib/MDV/Distribconf/Build.pm | 115 |
1 files changed, 106 insertions, 9 deletions
diff --git a/lib/MDV/Distribconf/Build.pm b/lib/MDV/Distribconf/Build.pm index dd71ff6..756ddb8 100644 --- a/lib/MDV/Distribconf/Build.pm +++ b/lib/MDV/Distribconf/Build.pm @@ -13,6 +13,7 @@ MDV::Distribconf::Build - Subclass to MDV::Distribconf to build configuration use strict; use warnings; use MDV::Distribconf; +use File::Path; use base qw(MDV::Distribconf MDV::Distribconf::Checks); our $VERSION = (qq$Revision$ =~ /(\d+)/)[0]; @@ -53,8 +54,9 @@ sub init { } foreach my $dir (map { $self->getfullpath(undef, $_) } qw(mediadir infodir)) { if (!-d $dir) { - if (!mkdir($dir)) { - warn "Cannot create $dir: $!\n"; + eval { mkpath($dir) }; + if ($@) { + warn "Cannot create $dir: $@\n"; return 0; } } @@ -79,16 +81,18 @@ Return 1 on success, 0 otherwise sub create_media { my ($self, $media) = @_; + $self->setvalue($media, undef, undef); foreach my $dir (map { $self->getfullmediapath($media, $_) } qw(path infodir)) { if (!-d $dir) { - if (!mkdir($dir)) { - warn "Cannot create $dir: $!\n"; + eval { mkpath($dir) }; + if ($@) { + warn "Cannot create $dir: $@\n"; + $self->delvalue($media, undef); return 0; } } } - $self->setvalue($media, undef, undef); 1; } @@ -104,16 +108,71 @@ no defined parameters. sub setvalue { my ($distrib, $media, $var, $val) = @_; $media ||= 'media_info'; + $distrib->{cfg}->AddSection($media); if ($var) { + if ($media && !$distrib->mediaexists($media)) { + $distrib->setvalue($media); + } $var =~ /^(?:media|info)dir\z/ and do { $distrib->{$var} = $val; - return; + return 1; }; - $distrib->{cfg}->newval($media, $var, $val) - or warn "Can't set value [$var=$val] for $media\n"; + if ($val) { + $distrib->{cfg}->newval($media, $var, $val) + or warn "Can't set value [$var=$val] for $media\n"; + } else { + $distrib->{cfg}->delval($media, $var); + } + } + $distrib->_post_setvalue($media, $var, $val) if ($media); +} + +sub _post_setvalue { + my ($distrib, $cmedia, $cvar, $cval) = @_; + if ($cvar) { + my $vsettings = MDV::Distribconf::MediaCFG::_value_info($cvar); + if ($vsettings->{cross}) { + my %pointed_media = map { $_ => 1 } split(/\s/, $cval); + foreach my $media ($distrib->listmedia()) { + my %ml = map { $_ => 1 } + split(/\s/, $distrib->getvalue($media, $vsettings->{cross})); + + if (exists($pointed_media{$media})) { + exists($ml{$cmedia}) and next; + $ml{$cmedia} = 1; + } else { + exists($ml{$cmedia}) or next; + delete($ml{$cmedia}); + } + $distrib->setvalue( + $media, + $vsettings->{cross}, + join(" ", keys %ml), + ); + } + } } else { - $distrib->{cfg}->AddSection($media); + foreach my $media ($distrib->listmedia()) { + foreach my $val ($distrib->{cfg}->Parameters($media)) { + my $vsettings = MDV::Distribconf::MediaCFG::_value_info($val); + if ($vsettings->{cross}) { + if (grep { $_ eq $cmedia } + split(/\s/, $distrib->getvalue($media, $val))) { + my %ml = map { $_ => 1 } + split(/\s/, $distrib->getvalue($cmedia, $vsettings->{cross})); + exists($ml{$media}) and next; + $ml{$media} = 1; + $distrib->setvalue( + $cmedia, + $vsettings->{cross}, + join(" ", keys %ml), + ); + } + } + } + } } + 1; } =item $distrib->delvalue($media, $var) @@ -130,6 +189,44 @@ sub delvalue { } else { $distrib->{cfg}->DeleteSection($media); } + $distrib->_post_delvalue($media, $var); +} + +sub _post_delvalue { + my ($distrib, $cmedia, $cvar) = @_; + foreach my $media ($distrib->listmedia()) { + if ($cvar) { + my $vsettings = MDV::Distribconf::MediaCFG::_value_info($cvar); + if ($vsettings->{cross}) { + if($distrib->getvalue($media, $vsettings->{cross})) { + my %ml = map { $_ => 1 } split(/\s/, $distrib->getvalue($media, $vsettings->{cross})); + exists($ml{$cmedia}) or next; + delete($ml{$cmedia}); + + $distrib->setvalue( + $media, + $vsettings->{cross}, + join(" ", keys %ml) + ); + } + } + } else { + foreach my $val ($distrib->{cfg}->Parameters($media)) { + my $vsettings = MDV::Distribconf::MediaCFG::_value_info($val); + if ($vsettings->{ismedialist} && $distrib->getvalue($media, $val)) { + my %ml = map { $_ => 1 } split(/\s/, $distrib->getvalue($media, $val)); + exists($ml{$cmedia}) or next; + delete($ml{$cmedia}); + $distrib->setvalue( + $media, + $val, + join(" ", keys %ml) + ); + } + } + } + } + 1; } =item $distrib->write_hdlists($hdlists) |