1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/Product.cc
13 #include "zypp/base/LogTools.h"
15 #include "zypp/Product.h"
18 #include "zypp/sat/LookupAttr.h"
19 #include "zypp/sat/WhatProvides.h"
20 #include "zypp/sat/WhatObsoletes.h"
21 #include "zypp/PoolItem.h"
25 ///////////////////////////////////////////////////////////////////
27 { /////////////////////////////////////////////////////////////////
29 IMPL_PTR_TYPE(Product);
33 void fillList( std::list<Url> & ret_r, sat::Solvable solv_r, sat::SolvAttr attr_r )
35 sat::LookupAttr query( attr_r, solv_r );
36 for_( it, query.begin(), query.end() )
38 try // ignore malformed urls
40 ret_r.push_back( Url( it.asString() ) );
42 catch( const url::UrlException & )
47 void fillList( std::list<std::string> & ret_r, sat::Solvable solv_r, sat::SolvAttr attr_r )
49 sat::LookupAttr query( attr_r, solv_r );
50 for_( it, query.begin(), query.end() )
52 ret_r.push_back( it.asString() );
57 ///////////////////////////////////////////////////////////////////
59 // METHOD NAME : Product::Product
62 Product::Product( const sat::Solvable & solvable_r )
63 : ResObject( solvable_r )
66 ///////////////////////////////////////////////////////////////////
68 // METHOD NAME : Product::~Product
74 ///////////////////////////////////////////////////////////////////
76 sat::Solvable Product::referencePackage() const
78 // Look for a provider of 'product(name) = version' of same
79 // architecture and within the same repo.
81 // bnc #497696: Update repos may have multiple release package versions
82 // providing the same product. As a workaround we link to the one with
83 // the highest version.
84 Capability identCap( str::form( "product(%s) = %s", name().c_str(), edition().c_str() ) );
87 sat::WhatProvides providers( identCap );
88 for_( it, providers.begin(), providers.end() )
90 if ( it->repository() == repository()
91 && it->arch() == arch() )
93 if ( ! found || found.edition() < it->edition() )
98 WAR << *this << ": no reference package found: " << identCap << endl;
102 std::string Product::referenceFilename() const
103 { return lookupStrAttribute( sat::SolvAttr::productReferenceFile ); }
105 Product::ReplacedProducts Product::replacedProducts() const
107 std::vector<constPtr> ret;
108 // By now we simply collect what is obsoleted by the Product,
109 // or by the products buddy (release-package).
111 // Check our own dependencies. We should not have any,
112 // but just to be shure.
113 sat::WhatObsoletes obsoleting( satSolvable() );
114 for_( it, obsoleting.begin(), obsoleting.end() )
116 if ( it->isKind( ResKind::product ) )
117 ret.push_back( make<Product>( *it ) );
120 // If we have a buddy, we check what product buddies the
122 obsoleting = sat::WhatObsoletes( poolItem().buddy() );
123 for_( it, obsoleting.poolItemBegin(), obsoleting.poolItemEnd() )
125 if ( (*it).buddy().isKind( ResKind::product ) )
126 ret.push_back( make<Product>( (*it).buddy() ) );
131 std::string Product::productLine() const
132 { return lookupStrAttribute( sat::SolvAttr::productProductLine ); }
134 ///////////////////////////////////////////////////////////////////
136 std::string Product::shortName() const
137 { return lookupStrAttribute( sat::SolvAttr::productShortlabel ); }
139 std::string Product::flavor() const
141 // Look for a provider of 'product_flavor(name) = version'
142 // within the same repo. Unlike the reference package, we
143 // can be relaxed and ignore the architecture.
144 Capability identCap( str::form( "product_flavor(%s) = %s", name().c_str(), edition().c_str() ) );
146 sat::WhatProvides providers( identCap );
147 for_( it, providers.begin(), providers.end() )
149 if ( it->repository() == repository() )
151 // Got the package now try to get the provided 'flavor(...)'
152 Capabilities provides( it->provides() );
153 for_( cap, provides.begin(), provides.end() )
155 std::string capstr( cap->asString() );
156 if ( str::hasPrefix( capstr, "flavor(" ) )
158 capstr = str::stripPrefix( capstr, "flavor(" );
159 capstr.erase( capstr.size()-1 ); // trailing ')'
165 return std::string();
168 std::string Product::type() const
169 { return lookupStrAttribute( sat::SolvAttr::productType ); }
171 std::list<std::string> Product::flags() const
173 std::list<std::string> ret;
174 fillList( ret, satSolvable(), sat::SolvAttr::productFlags );
178 bool Product::isTargetDistribution() const
179 { return isSystem() && lookupStrAttribute( sat::SolvAttr::productType ) == "base"; }
181 std::string Product::registerTarget() const
182 { return lookupStrAttribute( sat::SolvAttr::productRegisterTarget ); }
184 std::string Product::registerRelease() const
185 { return lookupStrAttribute( sat::SolvAttr::productRegisterRelease ); }
187 /////////////////////////////////////////////////////////////////
189 Product::UrlList Product::urls( const std::string & key_r ) const
193 sat::LookupAttr url( sat::SolvAttr::productUrl, *this );
194 sat::LookupAttr url_type( sat::SolvAttr::productUrlType, *this );
196 sat::LookupAttr::iterator url_it(url.begin());
197 sat::LookupAttr::iterator url_type_it(url_type.begin());
199 for (;url_it != url.end(); ++url_it, ++url_type_it)
201 /* safety checks, shouldn't happen (tm) */
202 if (url_type_it == url_type.end())
204 ERR << *this << " : The thing that should not happen, happened." << endl;
208 if ( url_type_it.asString() == key_r )
210 ret._list.push_back(url_it.asString());
212 } /* while (attribute array) */
217 Product::UrlList Product::releaseNotesUrls() const { return urls( "releasenotes" ); }
218 Product::UrlList Product::registerUrls() const { return urls( "register" ); }
219 Product::UrlList Product::smoltUrls() const { return urls( "smolt" ); }
220 Product::UrlList Product::updateUrls() const { return urls( "update" ); }
221 Product::UrlList Product::extraUrls() const { return urls( "extra" ); }
222 Product::UrlList Product::optionalUrls() const { return urls( "optional" ); }
224 std::ostream & operator<<( std::ostream & str, const Product::UrlList & obj )
225 { return dumpRange( str << obj.key() << ' ', obj.begin(), obj.end() ); }
227 /////////////////////////////////////////////////////////////////
229 ///////////////////////////////////////////////////////////////////