libzypp: zypp/Product.cc Source File

libzypp 17.38.9

Product.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#include <iostream>
13#include <utility>
14#include <zypp-core/base/LogTools.h>
15#include <zypp/base/StrMatcher.h>
16
17#include <zypp/Product.h>
18#include <zypp-core/Url.h>
19
20#include <zypp/sat/LookupAttr.h>
21#include <zypp/sat/WhatProvides.h>
22#include <zypp/sat/WhatObsoletes.h>
23#include <zypp/PoolItem.h>
24
25using std::endl;
26
28namespace zypp
29{
30
31 IMPL_PTR_TYPE(Product);
32
33 namespace
34 {
35 void fillList( std::list<std::string> & ret_r, sat::Solvable solv_r, sat::SolvAttr attr_r )
36 {
37 sat::LookupAttr query( std::move(attr_r), solv_r );
38 for_( it, query.begin(), query.end() )
39 {
40 ret_r.push_back( it.asString() );
41 }
42 }
43
44 // The name of the reference package if provided as 'autoproduct() = someproducts-release'
45 inline IdString autoCapReference( const Capabilities & provides_r )
46 {
47 static const Capability autoproduct( "autoproduct()" );
48 for ( const auto & cap : provides_r ) {
49 if ( cap.matches( autoproduct ) == CapMatch::yes ) {
50 const CapDetail & detail { cap.detail() };
51 if ( detail.isVersioned() )
52 return detail.ed().idStr();
53 }
54 }
55 return IdString::Null;
56 }
57 }
58
60 //
61 // METHOD NAME : Product::Product
62 // METHOD TYPE : Ctor
63 //
64 Product::Product( const sat::Solvable & solvable_r )
65 : ResObject( solvable_r )
66 {}
67
69 //
70 // METHOD NAME : Product::~Product
71 // METHOD TYPE : Dtor
72 //
73 Product::~Product()
74 {}
75
77
78 sat::Solvable Product::referencePackage() const
79 {
80 // Look for a provider of 'product(name) = version' of same
81 // architecture and within the same repo.
82 //
83 // bsc#1259311: Use a provided autoproduct() as hint to the package name.
84 //
85 // Note: Update repos may have multiple release package versions
86 // providing the same product. Prefer the one matching the buildtime,
87 // as the product buildtime is derived from the -release package.
88 Capability identCap( str::form( "product(%s) = %s", name().c_str(), edition().c_str() ) );
89 IdString autoReference { autoCapReference( dep_provides() ) };
90
91 sat::Solvable found;
92 bool foundBuildTime = false;
93 for ( const sat::Solvable & slv : sat::WhatProvides( identCap ) )
94 {
95 if ( autoReference && autoReference != slv.ident() )
96 continue;
97 if ( slv.repository() == repository() && slv.arch() == arch() )
98 {
99 bool fitsBuildtime = ( slv.buildtime() == buildtime() );
100 if ( found )
101 {
102 bool lowerEdition = ( slv.edition() <= found.edition() );
103 if ( ( foundBuildTime && ( !fitsBuildtime || lowerEdition ) )
104 || ( !foundBuildTime && ( !fitsBuildtime && lowerEdition ) ) )
105 continue;
106 }
107 found = slv;
108 if ( fitsBuildtime )
109 foundBuildTime = true;
110 }
111 }
112
113 if ( ! found && isSystem() )
114 {
115 // bnc#784900: for installed products check whether the file is owned by
116 // some package. If so, use this as buddy.
117 sat::LookupAttr q( sat::SolvAttr::filelist, repository() );
118 std::string refFile( referenceFilename() ); // the basename only!
119 if ( ! refFile.empty() )
120 {
121 StrMatcher matcher( "/etc/products.d/"+refFile, Match::STRING | Match::FILES );
122 q.setStrMatcher( matcher );
123 if ( ! q.empty() )
124 found = q.begin().inSolvable();
125 }
126 else
127 INT << "Product referenceFilename unexpectedly empty!" << endl;
128 }
129
130 if ( ! found )
131 WAR << *this << ": no reference package found: " << identCap << endl;
132 return found;
133 }
134
135 std::string Product::referenceFilename() const
136 { return lookupStrAttribute( sat::SolvAttr::productReferenceFile ); }
137
138 Product::ReplacedProducts Product::replacedProducts() const
139 {
140 std::vector<constPtr> ret;
141 // By now we simply collect what is obsoleted by the Product,
142 // or by the products buddy (release-package).
143
144 // Check our own dependencies. We should not have any,
145 // but just to be shure.
146 sat::WhatObsoletes obsoleting( satSolvable() );
147 for_( it, obsoleting.begin(), obsoleting.end() )
148 {
149 if ( it->isKind( ResKind::product ) )
150 ret.push_back( make<Product>( *it ) );
151 }
152
153 // If we have a buddy, we check what product buddies the
154 // buddy replaces.
155 obsoleting = sat::WhatObsoletes( poolItem().buddy() );
156 for_( it, obsoleting.poolItemBegin(), obsoleting.poolItemEnd() )
157 {
158 if ( (*it).buddy().isKind( ResKind::product ) )
159 ret.push_back( make<Product>( (*it).buddy() ) );
160 }
161 return ret;
162 }
163
164 CapabilitySet Product::droplist() const
165 { return poolItem().buddy().valuesOfNamespace( "weakremover" ); }
166
167 std::string Product::productLine() const
168 { return lookupStrAttribute( sat::SolvAttr::productProductLine ); }
169
171
172 std::string Product::shortName() const
173 {
174 std::string ret( lookupStrAttribute( sat::SolvAttr::productShortlabel ) );
175 if ( ret.empty() ) ret = name();
176 return ret;
177
178 }
179
180 std::string Product::flavor() const
181 {
182 // Look for a provider of 'product_flavor(name) = version'
183 // within the same repo. Unlike the reference package, we
184 // can be relaxed and ignore the architecture.
185 Capability identCap( str::form( "product_flavor(%s) = %s", name().c_str(), edition().c_str() ) );
186
187 sat::WhatProvides providers( identCap );
188 for_( it, providers.begin(), providers.end() )
189 {
190 if ( it->repository() == repository() )
191 {
192 // Got the package now try to get the provided 'flavor(...)'
193 Capabilities provides( it->dep_provides() );
194 for_( cap, provides.begin(), provides.end() )
195 {
196 std::string capstr( cap->asString() );
197 if ( str::hasPrefix( capstr, "flavor(" ) )
198 {
199 capstr = str::stripPrefix( capstr, "flavor(" );
200 capstr.erase( capstr.size()-1 ); // trailing ')'
201 return capstr;
202 }
203 }
204 }
205 }
206 return std::string();
207 }
208
209 std::string Product::type() const
210 { return lookupStrAttribute( sat::SolvAttr::productType ); }
211
212 std::list<std::string> Product::flags() const
213 {
214 std::list<std::string> ret;
215 fillList( ret, satSolvable(), sat::SolvAttr::productFlags );
216 return ret;
217 }
218
219 Date Product::endOfLife() const
220 { return Date( lookupNumAttribute( sat::SolvAttr::productEndOfLife ) );}
221
222 bool Product::hasEndOfLife() const
223 { return( lookupNumAttribute( sat::SolvAttr::productEndOfLife, -1 ) != (unsigned long long)(-1) ); }
224
225 bool Product::hasEndOfLife( Date & value ) const
226 {
227 Date res( lookupNumAttribute( sat::SolvAttr::productEndOfLife, -1 ) );
228 if ( res == -1 )
229 return false;
230 // else:
231 value = res;
232 return true;
233 }
234
235 std::vector<Repository::ContentIdentifier> Product::updateContentIdentifier() const
236 {
237 std::vector<Repository::ContentIdentifier> ret;
238 sat::LookupAttr q( sat::SolvAttr::productUpdatesRepoid, sat::SolvAttr::productUpdates, *this );
239 if ( ! q.empty() )
240 {
241 ret.reserve( 2 );
242 for_( it, q.begin(), q.end() )
243 ret.push_back( it.asString() );
244 }
245 return ret;
246 }
247
248 bool Product::hasUpdateContentIdentifier( const Repository::ContentIdentifier & cident_r ) const
249 {
250 sat::LookupAttr q( sat::SolvAttr::productUpdatesRepoid, sat::SolvAttr::productUpdates, *this );
251 for_( it, q.begin(), q.end() )
252 {
253 if ( it.asString() == cident_r )
254 return true;
255 }
256 return false;
257 }
258
259 bool Product::isTargetDistribution() const
260 { return isSystem() && lookupStrAttribute( sat::SolvAttr::productType ) == "base"; }
261
262 std::string Product::registerTarget() const
263 { return lookupStrAttribute( sat::SolvAttr::productRegisterTarget ); }
264
265 std::string Product::registerRelease() const
266 { return lookupStrAttribute( sat::SolvAttr::productRegisterRelease ); }
267
268 std::string Product::registerFlavor() const
269 { return lookupStrAttribute( sat::SolvAttr::productRegisterFlavor ); }
270
272
273 Product::UrlList Product::urls( const std::string & key_r ) const
274 {
275 UrlList ret;
276
277 sat::LookupAttr url( sat::SolvAttr::productUrl, *this );
278 sat::LookupAttr url_type( sat::SolvAttr::productUrlType, *this );
279
280 sat::LookupAttr::iterator url_it(url.begin());
281 sat::LookupAttr::iterator url_type_it(url_type.begin());
282
283 for (;url_it != url.end(); ++url_it, ++url_type_it)
284 {
285 /* safety checks, shouldn't happen (tm) */
286 if (url_type_it == url_type.end())
287 {
288 ERR << *this << " : The thing that should not happen, happened." << endl;
289 break;
290 }
291
292 if ( url_type_it.asString() == key_r )
293 {
294 ret._list.push_back(url_it.asString());
295 }
296 } /* while (attribute array) */
297
298 return ret;
299 }
300
301 Product::UrlList Product::releaseNotesUrls() const { return urls( "releasenotes" ); }
302 Product::UrlList Product::registerUrls() const { return urls( "register" ); }
303 Product::UrlList Product::smoltUrls() const { return urls( "smolt" ); }
304 Product::UrlList Product::updateUrls() const { return urls( "update" ); }
305 Product::UrlList Product::extraUrls() const { return urls( "extra" ); }
306 Product::UrlList Product::optionalUrls() const { return urls( "optional" ); }
307
308 std::ostream & operator<<( std::ostream & str, const Product::UrlList & obj )
309 { return dumpRange( str << obj.key() << ' ', obj.begin(), obj.end() ); }
310
312} // namespace zypp
for_
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition Easy.h:27
LogTools.h
ERR
#define ERR
Definition Logger.h:105
WAR
#define WAR
Definition Logger.h:104
INT
#define INT
Definition Logger.h:107
LookupAttr.h
PoolItem.h
Product.h
StrMatcher.h
Url.h
WhatObsoletes.h
WhatProvides.h
zypp::CapDetail
Helper providing more detailed information about a Capability.
Definition Capability.h:366
zypp::CapMatch::yes
static const CapMatch yes
Definition CapMatch.h:52
zypp::Capabilities
Container of Capability (currently read only).
Definition Capabilities.h:35
zypp::Capability
A sat capability.
Definition Capability.h:63
zypp::Date
Store and operate on date (time_t).
Definition Date.h:33
zypp::IdString
Access to the sat-pools string space.
Definition IdString.h:55
zypp::IdString::Null
static const IdString Null
No or Null string ( Id 0 ).
Definition IdString.h:86
zypp::Match::STRING
@ STRING
Excat matching.
Definition StrMatcher.h:43
zypp::Match::FILES
static const Match FILES
LookupAttr: match full path when matching in filelists, otherwise just the basenames.
Definition StrMatcher.h:75
zypp::PoolItem::buddy
sat::Solvable buddy() const
Return the buddy we share our status object with.
Definition PoolItem.cc:215
zypp::Product::UrlList
Helper to iterate a products URL lists.
Definition Product.h:210
zypp::Product::UrlList::end
const_iterator end() const
Definition Product.h:229
zypp::Product::UrlList::_list
ListType _list
Definition Product.h:245
zypp::Product::UrlList::key
std::string key() const
The key used to retrieve this list (for debug).
Definition Product.h:238
zypp::Product::UrlList::begin
const_iterator begin() const
Definition Product.h:226
zypp::Product
Product interface.
Definition Product.h:34
zypp::Product::replacedProducts
ReplacedProducts replacedProducts() const
Array of installed Products that would be replaced by installing this one.
Definition Product.cc:138
zypp::Product::flags
std::list< std::string > flags() const
The product flags.
Definition Product.cc:212
zypp::Product::extraUrls
UrlList extraUrls() const
Additional software for the product They are complementary, not alternatives.
Definition Product.cc:305
zypp::Product::flavor
std::string flavor() const
The product flavor (LiveCD Demo, FTP edition,...).
Definition Product.cc:180
zypp::Product::isTargetDistribution
bool isTargetDistribution() const
This is the installed product that is also targeted by the /etc/products.d/baseproduct symlink.
Definition Product.cc:259
zypp::Product::releaseNotesUrls
UrlList releaseNotesUrls() const
The URL to download the release notes for this product.
Definition Product.cc:301
zypp::Product::shortName
std::string shortName() const
Untranslated short name like SLES 10 (fallback: name).
Definition Product.cc:172
zypp::Product::referenceFilename
std::string referenceFilename() const
For installed products the name of the corresponding /etc/products.d entry.
Definition Product.cc:135
zypp::Product::make
friend Ptr make(const sat::Solvable &solvable_r)
Directly create a certain kind of ResObject from sat::Solvable.
Definition ResObject.h:118
zypp::Product::registerUrls
UrlList registerUrls() const
The URL for registration.
Definition Product.cc:302
zypp::Product::registerTarget
std::string registerTarget() const
This is register.target attribute of a product.
Definition Product.cc:262
zypp::Product::Product
Product(const sat::Solvable &solvable_r)
Ctor.
Definition Product.cc:64
zypp::Product::~Product
~Product() override
Dtor.
Definition Product.cc:73
zypp::Product::hasEndOfLife
bool hasEndOfLife() const
Return whether an EndOfLife value is actually defined in the metadata.
Definition Product.cc:222
zypp::Product::droplist
CapabilitySet droplist() const
List of packages included in older versions of this product and now dropped.
Definition Product.cc:164
zypp::Product::hasUpdateContentIdentifier
bool hasUpdateContentIdentifier(const Repository::ContentIdentifier &cident_r) const
Whether cident_r is listed as required update repository.
Definition Product.cc:248
zypp::Product::endOfLife
Date endOfLife() const
The date when this Product goes out of support as indicated by its medadata.
Definition Product.cc:219
zypp::Product::updateUrls
UrlList updateUrls() const
Online updates for the product.
Definition Product.cc:304
zypp::Product::referencePackage
sat::Solvable referencePackage() const
The reference package providing the product metadata, if such a package exists.
Definition Product.cc:78
zypp::Product::urls
UrlList urls(const std::string &key_r) const
Retrieve URLs flagged with key_r for this product.
Definition Product.cc:273
zypp::Product::type
std::string type() const
Get the product type Well, in an ideal world there is only one base product.
Definition Product.cc:209
zypp::Product::updateContentIdentifier
std::vector< Repository::ContentIdentifier > updateContentIdentifier() const
ContentIdentifier of required update repositories.
Definition Product.cc:235
zypp::Product::ReplacedProducts
std::vector< constPtr > ReplacedProducts
Definition Product.h:74
zypp::Product::registerFlavor
std::string registerFlavor() const
This is register.flavor attribute of a product.
Definition Product.cc:268
zypp::Product::registerRelease
std::string registerRelease() const
This is register.release attribute of an installed product.
Definition Product.cc:265
zypp::Product::smoltUrls
UrlList smoltUrls() const
The URL for SMOLT.
Definition Product.cc:303
zypp::Product::productLine
std::string productLine() const
Vendor specific string denoting the product line.
Definition Product.cc:167
zypp::Product::optionalUrls
UrlList optionalUrls() const
Optional software for the product.
Definition Product.cc:306
zypp::Repository::ContentIdentifier
std::string ContentIdentifier
Definition Repository.h:49
zypp::ResKind::product
static const ResKind product
Definition ResKind.h:43
zypp::ResObject::ResObject
ResObject(const sat::Solvable &solvable_r)
Ctor.
Definition ResObject.cc:23
zypp::Resolvable::poolItem
PoolItem poolItem() const
Access the corresponding PoolItem.
Definition Resolvable.cc:28
zypp::StrMatcher
String matching (STRING|SUBSTRING|GLOB|REGEX).
Definition StrMatcher.h:298
zypp::sat::LookupAttr::iterator
Result iterator.
Definition LookupAttr.h:364
zypp::sat::LookupAttr::iterator::asString
std::string asString() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition LookupAttr.cc:611
zypp::sat::LookupAttr::iterator::inSolvable
Solvable inSolvable() const
The current Solvable.
Definition LookupAttr.cc:355
zypp::sat::LookupAttr
Lightweight attribute value lookup.
Definition LookupAttr.h:110
zypp::sat::LookupAttr::end
iterator end() const
Iterator behind the end of query results.
Definition LookupAttr.cc:240
zypp::sat::LookupAttr::empty
bool empty() const
Whether the query is empty.
Definition LookupAttr.cc:243
zypp::sat::LookupAttr::setStrMatcher
void setStrMatcher(const StrMatcher &matcher_r)
Set the pattern to match.
Definition LookupAttr.cc:206
zypp::sat::LookupAttr::begin
iterator begin() const
Iterator to the begin of query results.
Definition LookupAttr.cc:237
zypp::sat::SolvAttr
Solvable attribute keys.
Definition SolvAttr.h:41
zypp::sat::SolvAttr::productRegisterRelease
static const SolvAttr productRegisterRelease
Definition SolvAttr.h:171
zypp::sat::SolvAttr::filelist
static const SolvAttr filelist
Definition SolvAttr.h:118
zypp::sat::SolvAttr::productUpdatesRepoid
static const SolvAttr productUpdatesRepoid
Definition SolvAttr.h:176
zypp::sat::SolvAttr::productProductLine
static const SolvAttr productProductLine
Definition SolvAttr.h:163
zypp::sat::SolvAttr::productReferenceFile
static const SolvAttr productReferenceFile
Definition SolvAttr.h:162
zypp::sat::SolvAttr::productRegisterFlavor
static const SolvAttr productRegisterFlavor
Definition SolvAttr.h:172
zypp::sat::SolvAttr::productType
static const SolvAttr productType
Definition SolvAttr.h:167
zypp::sat::SolvAttr::productRegisterTarget
static const SolvAttr productRegisterTarget
Definition SolvAttr.h:170
zypp::sat::SolvAttr::productUrl
static const SolvAttr productUrl
Definition SolvAttr.h:173
zypp::sat::SolvAttr::productUpdates
static const SolvAttr productUpdates
array of repoids, hopefully label s too
Definition SolvAttr.h:175
zypp::sat::SolvAttr::productEndOfLife
static const SolvAttr productEndOfLife
Definition SolvAttr.h:169
zypp::sat::SolvAttr::productFlags
static const SolvAttr productFlags
Definition SolvAttr.h:168
zypp::sat::SolvAttr::productShortlabel
static const SolvAttr productShortlabel
Definition SolvAttr.h:164
zypp::sat::SolvAttr::productUrlType
static const SolvAttr productUrlType
Definition SolvAttr.h:174
zypp::sat::SolvIterMixin::poolItemEnd
PoolItem_iterator poolItemEnd() const
Definition SolvIterMixin.h:178
zypp::sat::SolvIterMixin::poolItemBegin
PoolItem_iterator poolItemBegin() const
Definition SolvIterMixin.h:176
zypp::sat::Solvable
A Solvable object within the sat Pool.
Definition Solvable.h:54
zypp::sat::Solvable::edition
Edition edition() const
The edition (version-release).
Definition Solvable.cc:341
zypp::sat::Solvable::valuesOfNamespace
CapabilitySet valuesOfNamespace(const std::string &namespace_r) const
Return 'value[ op edition]' for namespaced provides 'namespace(value)[ op edition]'.
Definition Solvable.cc:568
zypp::sat::WhatObsoletes
Container of installed Solvable which would be obsoleted by the Solvable passed to the ctor.
Definition WhatObsoletes.h:38
zypp::sat::WhatObsoletes::end
const_iterator end() const
Iterator pointing behind the last Solvable.
Definition WhatObsoletes.h:87
zypp::sat::WhatObsoletes::begin
const_iterator begin() const
Iterator pointing to the first Solvable.
Definition WhatObsoletes.h:83
zypp::sat::WhatProvides
Container of Solvable providing a Capability (read only).
Definition WhatProvides.h:89
zypp::sat::WhatProvides::end
const_iterator end() const
Iterator pointing behind the last Solvable.
Definition WhatProvides.h:234
zypp::sat::WhatProvides::begin
const_iterator begin() const
Iterator pointing to the first Solvable.
Definition WhatProvides.cc:145
str
String related utilities and Regular expression matching.
zypp::detail
Definition PoolQuery.cc:1509
zypp::str::hasPrefix
bool hasPrefix(const C_Str &str_r, const C_Str &prefix_r)
Return whether str_r has prefix prefix_r.
Definition String.h:1097
zypp::str::form
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Definition String.cc:39
zypp::str::stripPrefix
std::string stripPrefix(const C_Str &str_r, const C_Str &prefix_r)
Strip a prefix_r from str_r and return the resulting string.
Definition String.h:1104
zypp::url
Url details namespace.
Definition UrlBase.cc:58
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
zypp::dumpRange
std::ostream & dumpRange(std::ostream &str, TIterator begin, TIterator end, const std::string &intro="{", const std::string &pfx="\n ", const std::string &sep="\n ", const std::string &sfx="\n", const std::string &extro="}")
Print range defined by iterators (multiline style).
Definition LogTools.h:419
zypp::CapabilitySet
std::unordered_set< Capability > CapabilitySet
Definition Capability.h:35
zypp::operator<<
std::ostream & operator<<(std::ostream &str, const Capabilities &obj)
relates: Capabilities Stream output
Definition Capabilities.cc:65
zypp::sat::SolvableType< Resolvable >::provides
Capabilities provides() const
Definition SolvableType.h:123
zypp::sat::SolvableType< Resolvable >::isSystem
bool isSystem() const
Definition SolvableType.h:78
zypp::sat::SolvableType< Resolvable >::arch
Arch arch() const
Definition SolvableType.h:72
zypp::sat::SolvableType< Resolvable >::name
std::string name() const
Definition SolvableType.h:70
zypp::sat::SolvableType< Resolvable >::dep_provides
Capabilities dep_provides() const
Definition SolvableType.h:110
zypp::sat::SolvableType< Resolvable >::lookupStrAttribute
std::string lookupStrAttribute(const SolvAttr &attr) const
Definition SolvableType.h:158
zypp::sat::SolvableType< Resolvable >::satSolvable
Solvable satSolvable() const
Definition SolvableType.h:57
zypp::sat::SolvableType< Resolvable >::lookupNumAttribute
unsigned long long lookupNumAttribute(const SolvAttr &attr) const
Definition SolvableType.h:162
zypp::sat::SolvableType< Resolvable >::repository
Repository repository() const
Definition SolvableType.h:75
zypp::sat::SolvableType< Resolvable >::edition
Edition edition() const
Definition SolvableType.h:71
zypp::sat::SolvableType< Resolvable >::buildtime
Date buildtime() const
Definition SolvableType.h:96
IMPL_PTR_TYPE
#define IMPL_PTR_TYPE(NAME)
Definition ReferenceCounted.h:137