diff options
-rw-r--r-- | lib/MDV/Distribconf.pm | 43 | ||||
-rw-r--r-- | t/01distribconf.t | 28 | ||||
-rw-r--r-- | testdata/test/media/media_info/media.cfg | 1 |
3 files changed, 61 insertions, 11 deletions
diff --git a/lib/MDV/Distribconf.pm b/lib/MDV/Distribconf.pm index d8be727..a06bc3b 100644 --- a/lib/MDV/Distribconf.pm +++ b/lib/MDV/Distribconf.pm @@ -76,6 +76,18 @@ A human-readable name for the media. By default this is the media path (that is, the section name), where slashes have been replaced by underscores. +=item B<info> + +The xml file containing rpm informations. + +=item B<changelog> + +The xml file containing rpm changelogs. + +=item B<files> + +The xml file containing rpm files list. + =back =item global specific values: @@ -437,7 +449,11 @@ sub getvalue { my $default = ""; for ($var) { - /^synthesis$/ and $default = 'synthesis.' . lc($distrib->getvalue($media, 'hdlist', $level)); + /^path$/ and return $media; + /^root$/ and return $distrib->{root}; + /^(info|files|changelog)$/ and + return "$var." . lc($distrib->getvalue($media, 'name', $level)) . '.xml.lzma'; + /^synthesis$/ and $default = 'synthesis.' . lc($distrib->getvalue($media, 'hdlist', $level)); /^hdlist$/ and $default = 'hdlist_' . lc($distrib->getvalue($media, 'name', $level)) . '.cz'; /^pubkey$/ and $default = 'pubkey_' . lc($distrib->getvalue($media, 'name', $level)); /^(pubkey|hdlist|synthesis)$/ and do { @@ -452,8 +468,6 @@ sub getvalue { return join(',', map { "$_=" . ($distrib->getvalue(undef, $_) || '') } qw(vendor distribution type version branch release arch product)); }; - /^path$/ and return $media; - /^root$/ and return $distrib->{root}; /^mediacfg_version$/ and return $distrib->{cfg}->val('media_info', 'mediacfg_version') || 1; /^VERSION$/ and do { $default = 'VERSION'; last }; @@ -497,6 +511,10 @@ sub getpath { my ($distrib, $media, $var) = @_; $distrib->mediaexists($media) or return; $var ||= ""; # Avoid undef value + if ($var =~ /^(info|files|changelog)$/) { + $distrib->getvalue($media, 'xml-info') or return; + $distrib->getvalue($media, 'cdmode') or return; + } my $val = $distrib->getvalue($media, $var); $var =~ /^(?:root|VERSION|product\.id|(?:media|info)dir)$/ and return $val; my $thispath = $var eq 'path' ? $distrib->{mediadir} : $distrib->{infodir}; @@ -519,13 +537,20 @@ to the media for files having doble location (index for example). sub getmediapath { my ($distrib, $media, $var) = @_; my %files = ( - pubkey => 'pubkey', - hdlist => 'hdlist.cz', - synthesis => 'synthesis.hdlist.cz', - MD5SUM => 'MD5SUM', - infodir => '', + pubkey => 'pubkey', + hdlist => 'hdlist.cz', + synthesis => 'synthesis.hdlist.cz', + MD5SUM => 'MD5SUM', + infodir => '', + info => 'info.xml.lzma', + files => 'files.xml.lzma', + changelog => 'changelog.xml.lzma', ); $var eq 'path' and return $distrib->getpath($media, 'path'); + if ($var =~ /^(info|files|changelog)$/) { + $distrib->getvalue($media, 'xml-info') or return; + $distrib->getvalue($media, 'cdmode') and return; + } return $distrib->getpath($media, 'path') . $distrib->{mediainfodir} . "/$files{$var}"; } @@ -570,7 +595,7 @@ You may want to use this function to ensure you allways the good value. sub getdpath { my ($distrib, $media, $var) = @_; - if ($var =~ /^(hdlist|synthesis|pubkey|MD5SUM)$/) { + if ($var =~ /^(hdlist|synthesis|pubkey|MD5SUM|info|files|changelog)$/) { if ($distrib->getvalue($media, 'cdmode') || $distrib->{type} eq 'mandrake') { return $distrib->getpath($media, $var); diff --git a/t/01distribconf.t b/t/01distribconf.t index 94beb60..a6024a2 100644 --- a/t/01distribconf.t +++ b/t/01distribconf.t @@ -12,7 +12,7 @@ my %testdpath = ( 'http://server/path/' => 'testdata/test/media/media_info/media.cfg', ); -plan tests => 16 + 29 * scalar(keys %testdpath); +plan tests => 22 + 29 * scalar(keys %testdpath); use_ok('MDV::Distribconf'); @@ -117,16 +117,40 @@ like($dconf->getpath(undef, 'media_info'), qr!^/*infodir/?$!, "Can get media_inf } { - my $dc = MDV::Distribconf->new('testdata/test3'); + my $dc = MDV::Distribconf->new('testdata/test'); $dc->load(); is( $dc->getdpath('main', 'hdlist'), $dc->getmediapath('main', 'hdlist'), "Can get default path w/o cdmode" ); + is ( $dc->getdpath('main', 'info'), + 'media/main/media_info/info.xml.lzma', + 'Can get xml "info" path' + ); + is ( $dc->getdpath('main', 'files'), + 'media/main/media_info/files.xml.lzma', + 'Can get xml "files" path' + ); + is ( $dc->getdpath('main', 'changelog'), + 'media/main/media_info/changelog.xml.lzma', + 'Can get xml "changelog" path' + ); $dc->{cfg}->newval('media_info', 'cdmode', 1); is( $dc->getdpath('main', 'hdlist'), $dc->getpath('main', 'hdlist'), "Can get default path w/ cdmode" ); + is ( $dc->getdpath('main', 'info'), + 'media/media_info/info.main.xml.lzma', + 'Can get xml "info" path' + ); + is ( $dc->getdpath('main', 'files'), + 'media/media_info/files.main.xml.lzma', + 'Can get xml "files" path' + ); + is ( $dc->getdpath('main', 'changelog'), + 'media/media_info/changelog.main.xml.lzma', + 'Can get xml "changelog" path' + ); } diff --git a/testdata/test/media/media_info/media.cfg b/testdata/test/media/media_info/media.cfg index 635bb44..c162b9b 100644 --- a/testdata/test/media/media_info/media.cfg +++ b/testdata/test/media/media_info/media.cfg @@ -4,6 +4,7 @@ version=2006.0 branch=Cooker arch=i586 +xml-info=1 [main] hdlist=hdlist_main.cz |