From 375b524b3f466fb8cbd26f81007528b75283cc7c Mon Sep 17 00:00:00 2001 From: Olivier Thauvin Date: Fri, 1 Sep 2006 01:56:25 +0000 Subject: - add init() and create_media() --- lib/MDV/Distribconf/Build.pm | 64 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'lib/MDV') diff --git a/lib/MDV/Distribconf/Build.pm b/lib/MDV/Distribconf/Build.pm index 44a1ecb..dd71ff6 100644 --- a/lib/MDV/Distribconf/Build.pm +++ b/lib/MDV/Distribconf/Build.pm @@ -29,6 +29,70 @@ sub new { bless $self, $class; } +=item $distrib->init($flavour) + +Create initals directories in the distrib tree if missing. + +$flavour is either 'mandriva' or 'mandrake', depending the tree type +you want to create. + +See also L + +Return 1 on success, 0 otherwise. + +=cut + +sub init { + my ($self, $flavour) = @_; + $self->settree($flavour || 'mandriva') unless($self->{infodir}); + if (!-d $self->getfullpath(undef, 'root')) { + if (!mkdir($self->getfullpath(undef, 'root'))) { + warn 'Cannot create ' . $self->getfullpath(undef, 'root') .": $!\n"; + return 0; + } + } + foreach my $dir (map { $self->getfullpath(undef, $_) } qw(mediadir infodir)) { + if (!-d $dir) { + if (!mkdir($dir)) { + warn "Cannot create $dir: $!\n"; + return 0; + } + } + } + + foreach my $media ($self->listmedia()) { + $self->create_media($media) or return 0; + } + + 1; +} + +=item $distrib->create_media($media) + +Create a media $media if not exists and its directories if need. + +See also L + +Return 1 on success, 0 otherwise + +=cut + +sub create_media { + my ($self, $media) = @_; + foreach my $dir (map { $self->getfullmediapath($media, $_) } qw(path infodir)) { + if (!-d $dir) { + if (!mkdir($dir)) { + warn "Cannot create $dir: $!\n"; + return 0; + } + } + } + + $self->setvalue($media, undef, undef); + + 1; +} + =item $distrib->setvalue($media, $var, $val) Sets or adds $var parameter from $media to $val. If $media doesn't exist, -- cgit v1.2.1