commit bb77f5b1fa6aba872555ef6f7c877718466651c9
Author: Michael Andres
Date: Mon Jan 26 12:17:45 2009 +0100
Let vendor checks per default differ between 'openSUSE Build Service' and 'openSUSE' (bnc #467262).
---
tests/zypp/Vendor_test.cc | 7 +++-
zypp/VendorAttr.cc | 107 +++++++++++++++++++++++++--------------------
zypp/VendorAttr.h | 27 +++++++++++-
3 files changed, 92 insertions(+), 49 deletions(-)
diff --git a/tests/zypp/Vendor_test.cc b/tests/zypp/Vendor_test.cc
index 34337d8..4aad252 100644
--- a/tests/zypp/Vendor_test.cc
+++ b/tests/zypp/Vendor_test.cc
@@ -26,7 +26,7 @@ namespace zypp
BOOST_AUTO_TEST_CASE(vendor_test1)
{
reconfigureZConfig( DATADIR / "zypp1.conf" );
- // No vendor definition files has been readed. So only suse,opensuse vendors are
+ // No vendor definition files has been read. So only suse,opensuse vendors are
// equivalent
BOOST_REQUIRE( VendorAttr::instance().equivalent("suse", "suse") );
BOOST_REQUIRE( VendorAttr::instance().equivalent("equal", "equal") );
@@ -34,5 +34,10 @@ BOOST_AUTO_TEST_CASE(vendor_test1)
BOOST_REQUIRE( VendorAttr::instance().equivalent("opensuse", "SuSE") );
BOOST_REQUIRE( !VendorAttr::instance().equivalent("open", "SuSE") );
BOOST_REQUIRE( !VendorAttr::instance().equivalent("nothing", "SuSE") );
+
+ // but "opensuse build service" gets its own class:
+ BOOST_REQUIRE( !VendorAttr::instance().equivalent("opensuse build service", "suse") );
+ BOOST_REQUIRE( !VendorAttr::instance().equivalent("opensuse build service", "opensuse") );
+ BOOST_REQUIRE( VendorAttr::instance().equivalent("opensuse build service", "opensuse build service 2") );
}
diff --git a/zypp/VendorAttr.cc b/zypp/VendorAttr.cc
index ad93b6d..6e00e85 100644
--- a/zypp/VendorAttr.cc
+++ b/zypp/VendorAttr.cc
@@ -48,52 +48,11 @@ namespace zypp
{ /////////////////////////////////////////////////////////////////
typedef map VendorMap;
- typedef vector<string> VendorList;
VendorMap _vendorMap;
VendorMap _matchMap;
unsigned int vendorGroupCounter;
- void addEquivalentVendors( VendorList & vendorList )
- {
- unsigned int nextId = vendorGroupCounter + 1;
- // convert to lowercase and check if a vendor is already defined
- // in an existing group.
-
- for (VendorList::iterator it = vendorList.begin();
- it != vendorList.end();
- it++) {
- *it = str::toLower( *it );
- if (_vendorMap.find(*it) != _vendorMap.end()) {
- if (nextId != vendorGroupCounter + 1 &&
- nextId != _vendorMap[*it]) {
- // We have at least 3 groups which has to be mixed --> mix the third group to the first
- unsigned int moveID = _vendorMap[*it];
- for (VendorMap::iterator itMap = _vendorMap.begin();
- itMap != _vendorMap.end();
- ++itMap) {
- if (itMap->second == moveID)
- itMap->second = nextId;
- }
- } else {
- nextId = _vendorMap[*it];
- WAR << "Vendor " << *it << " is already used in another vendor group. --> mixing these groups"
- << endl;
- }
- }
- }
- // add new entries
- for (VendorList::iterator it = vendorList.begin();
- it != vendorList.end();
- ++it) {
- _vendorMap[*it] = nextId;
- }
-
- if (nextId == vendorGroupCounter + 1)
- ++vendorGroupCounter;
- }
-
-
/////////////////////////////////////////////////////////////////
} // namespace
///////////////////////////////////////////////////////////////////
@@ -147,12 +106,54 @@ namespace zypp
_vendorMap["opensuse"] = suseit->second;
}
- MIL << "Equivalent vendors:" << endl;
- for (VendorMap::iterator it = _vendorMap.begin();
- it != _vendorMap.end();
- it ++) {
- MIL << " " << it->first << " (group " << it->second << ")" << endl;
+ // Take care 'opensuse build service' gets it's own class.
+ VendorMap::const_iterator obsit( _vendorMap.find("opensuse build service") );
+ if ( obsit == _vendorMap.end() )
+ {
+ _vendorMap["opensuse build service"] = ++vendorGroupCounter;
}
+
+
+ MIL << *this << endl;
+ }
+
+ void VendorAttr::_addVendorList( VendorList & vendorList_r ) const
+ {
+ unsigned int nextId = vendorGroupCounter + 1;
+ // convert to lowercase and check if a vendor is already defined
+ // in an existing group.
+
+ for_( it, vendorList_r.begin(), vendorList_r.end() )
+ {
+ *it = str::toLower( *it );
+ if (_vendorMap.find(*it) != _vendorMap.end())
+ {
+ if (nextId != vendorGroupCounter + 1 &&
+ nextId != _vendorMap[*it])
+ {
+ // We have at least 3 groups which has to be mixed --> mix the third group to the first
+ unsigned int moveID = _vendorMap[*it];
+ for_( itMap, _vendorMap.begin(), _vendorMap.end() )
+ {
+ if (itMap->second == moveID)
+ itMap->second = nextId;
+ }
+ }
+ else
+ {
+ nextId = _vendorMap[*it];
+ WAR << "Vendor " << *it << " is already used in another vendor group. --> mixing these groups" << endl;
+ }
+ }
+ }
+ // add new entries
+ for_( it, vendorList_r.begin(), vendorList_r.end() )
+ {
+ _vendorMap[*it] = nextId;
+ }
+
+ if (nextId == vendorGroupCounter + 1)
+ ++vendorGroupCounter;
}
bool VendorAttr::addVendorFile( const Pathname & filename ) const
@@ -188,7 +189,7 @@ namespace zypp
{
VendorList vendorlist;
str::split( value, back_inserter(vendorlist), "," );
- addEquivalentVendors (vendorlist);
+ _addVendorList (vendorlist);
break;
}
}
@@ -236,6 +237,8 @@ namespace zypp
if ( lhs == rhs )
return true;
+ // NOTE: iterate reverse to get find longest prefix first!
+
if (_matchMap.find(lhs) != _matchMap.end()) {
lhsID = _matchMap[lhs];
} else {
@@ -268,6 +271,16 @@ namespace zypp
return( lhsID && rhsID && lhsID == rhsID );
}
+ std::ostream & operator<<( std::ostream & str, const VendorAttr & /*obj*/ )
+ {
+ str << "Equivalent vendors:";
+ for_( it, _vendorMap.begin(), _vendorMap.end() )
+ {
+ str << endl << " [" << it->second << "] " << it->first;
+ }
+ return str;
+ }
+
/////////////////////////////////////////////////////////////////
} // namespace zypp
///////////////////////////////////////////////////////////////////
diff --git a/zypp/VendorAttr.h b/zypp/VendorAttr.h
index 477f217..75528ff 100644
--- a/zypp/VendorAttr.h
+++ b/zypp/VendorAttr.h
@@ -14,6 +14,7 @@
#include <iosfwd>
#include <string>
+#include <vector>
#include "zypp/base/NonCopyable.h"
#include "zypp/PathInfo.h"
@@ -23,9 +24,22 @@
namespace zypp {
//////////////////////////////////////////////////////////////////
+/** Definition of vendor equivalence.
+ *
+ * Packages with equivalment vendor strings may replace themself without
+ * creating a solver error.
+ *
+ * Per default vendor strings starting with \c "suse' or \c 'opensuse"
+ * are treated equivalent. This may be changed by providing customized
+ * vendor description files in /etc/zypp/vendors.d.
+ *
+ * \todo remove superfluous base::NonCopyable
+*/
class VendorAttr : private base::NonCopyable
{
public:
+ typedef std::vectorstd::string VendorList;
+
/** Singleton */
static const VendorAttr & instance();
@@ -37,7 +51,14 @@ class VendorAttr : private base::NonCopyable
/**
* Adding new equivalent vendors described in a file
**/
- bool addVendorFile( const Pathname & filename) const;
+ bool addVendorFile( const Pathname & filename ) const;
+
+ /**
+ * Adding new equivalent vendor set from list
+ **/
+ template <class _Iterator>
+ void addVendorList( _Iterator begin, _Iterator end ) const
+ { VendorList tmp( begin, end ); _addVendorList( tmp ); }
/** Return whether two vendor strings shold be treated as the same vendor.
* Usually the solver is allowed to automatically select a package of an
@@ -48,8 +69,12 @@ class VendorAttr : private base::NonCopyable
private:
VendorAttr();
+ void _addVendorList( VendorList & ) const;
};
+/** \relates VendorAttr Stream output */
+std::ostream & operator<<( std::ostream & str, const VendorAttr & obj );
+
///////////////////////////////////////////////////////////////////
}; // namespace zypp
///////////////////////////////////////////////////////////////////
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org