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