Skip to content
Browse files

Let vendor checks per default differ between 'openSUSE Build Service'…

… and 'openSUSE' (bnc #467262).
  • Loading branch information...
1 parent b4e65f3 commit bb77f5b1fa6aba872555ef6f7c877718466651c9 @mlandres mlandres committed Jan 26, 2009
Showing with 92 additions and 49 deletions.
  1. +6 −1 tests/zypp/Vendor_test.cc
  2. +60 −47 zypp/VendorAttr.cc
  3. +26 −1 zypp/VendorAttr.h
View
7 tests/zypp/Vendor_test.cc
@@ -26,13 +26,18 @@ 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") );
BOOST_REQUIRE( VendorAttr::instance().equivalent("suse", "SuSE") );
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") );
}
View
107 zypp/VendorAttr.cc
@@ -48,52 +48,11 @@ namespace zypp
{ /////////////////////////////////////////////////////////////////
typedef map<Vendor,unsigned int> 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
///////////////////////////////////////////////////////////////////
View
27 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::vector<std::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
///////////////////////////////////////////////////////////////////

0 comments on commit bb77f5b

Please sign in to comment.
Something went wrong with that request. Please try again.