From 4ef65a442038caf7a1e310bc719e329b34dbdb67 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Tue, 21 Dec 2010 17:20:16 +0100 Subject: [PATCH] - split the gpgkey line and take the first one as url to avoid crash when creating an url from the line, as Fedora hat the *BRILLIANT* idea of using more than one url per line. --- tests/parser/CMakeLists.txt | 1 + tests/parser/RepoFileReader_test.cc | 58 +++++++++++++++++++++++++++++++++++++ zypp/parser/RepoFileReader.cc | 7 ++++- 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 tests/parser/RepoFileReader_test.cc diff --git a/tests/parser/CMakeLists.txt b/tests/parser/CMakeLists.txt index 62aba6c..3c36965 100644 --- a/tests/parser/CMakeLists.txt +++ b/tests/parser/CMakeLists.txt @@ -3,4 +3,5 @@ ADD_SUBDIRECTORY( inifile ) ADD_SUBDIRECTORY(ws) ADD_TESTS( ProductFileReader ) +ADD_TESTS( RepoFileReader ) diff --git a/tests/parser/RepoFileReader_test.cc b/tests/parser/RepoFileReader_test.cc new file mode 100644 index 0000000..8a5c4e4 --- /dev/null +++ b/tests/parser/RepoFileReader_test.cc @@ -0,0 +1,58 @@ +#include +#include +#include + +using std::stringstream; +using std::string; + +static string suse_repo = "[factory-oss]\n" +"name=factory-oss\n" +"enabled=1\n" +"autorefresh=0\n" +"baseurl=http://download.opensuse.org/factory-tested/repo/oss/\n" +"type=yast2\n" +"keeppackages=0\n"; + +static string fedora_repo = "[fedora]\n" +"name=Fedora $releasever - $basearch\n" +"failovermethod=priority\n" +"#baseurl=http://download.fedora.redhat.com/pub/fedora/linux/releases/$releasever/Everything/$basearch/os/\n" +"#mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-$releasever&arch=$basearch\n" +"mirrorlist=file:///etc/yum.repos.d/local.mirror\n" +"enabled=1\n" +"gpgcheck=1\n" +"gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora file:///etc/pki/rpm-gpg/RPM-GPG-KEY\n"; + +struct RepoCollector : private base::NonCopyable +{ + bool collect( const RepoInfo &repo ) + { + repos.push_back(repo); + return true; + } + + RepoInfoList repos; +}; + +// Must be the first test! +BOOST_AUTO_TEST_CASE(read_repo_file) +{ + { + stringstream input(suse_repo); + RepoCollector collector; + parser::RepoFileReader parser( input, bind( &RepoCollector::collect, &collector, _1 ) ); + BOOST_CHECK_EQUAL(1, collector.repos.size()); + } + // fedora + { + stringstream input(fedora_repo); + RepoCollector collector; + parser::RepoFileReader parser( input, bind( &RepoCollector::collect, &collector, _1 ) ); + BOOST_REQUIRE_EQUAL(1, collector.repos.size()); + + RepoInfo repo = *collector.repos.begin(); + // should have taken the first url if more are present + BOOST_CHECK_EQUAL(Url("file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora"), repo.gpgKeyUrl()); + } + +} diff --git a/zypp/parser/RepoFileReader.cc b/zypp/parser/RepoFileReader.cc index 9e6ae21..eefacc5 100644 --- a/zypp/parser/RepoFileReader.cc +++ b/zypp/parser/RepoFileReader.cc @@ -68,7 +68,12 @@ namespace zypp else if ( it->first == "mirrorlist" && !it->second.empty()) info.setMirrorListUrl(Url(it->second)); else if ( it->first == "gpgkey" && !it->second.empty()) - info.setGpgKeyUrl( Url(it->second) ); + { + std::vector keys; + str::split( it->second, std::back_inserter(keys) ); + if ( ! keys.empty() ) + info.setGpgKeyUrl( Url(*keys.begin()) ); + } else if ( it->first == "gpgcheck" ) info.setGpgCheck( str::strToTrue( it->second ) ); else if ( it->first == "keeppackages" ) -- 2.7.4