libzypp  11.13.5
Product.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #include <iostream>
13 #include "zypp/base/LogTools.h"
14 
15 #include "zypp/Product.h"
16 #include "zypp/Url.h"
17 
18 #include "zypp/sat/LookupAttr.h"
19 #include "zypp/sat/WhatProvides.h"
20 #include "zypp/sat/WhatObsoletes.h"
21 #include "zypp/PoolItem.h"
22 
23 using std::endl;
24 
26 namespace zypp
27 {
28 
29  IMPL_PTR_TYPE(Product);
30 
31  namespace
32  {
33  void fillList( std::list<Url> & ret_r, sat::Solvable solv_r, sat::SolvAttr attr_r )
34  {
35  sat::LookupAttr query( attr_r, solv_r );
36  for_( it, query.begin(), query.end() )
37  {
38  try // ignore malformed urls
39  {
40  ret_r.push_back( Url( it.asString() ) );
41  }
42  catch( const url::UrlException & )
43  {}
44  }
45  }
46 
47  void fillList( std::list<std::string> & ret_r, sat::Solvable solv_r, sat::SolvAttr attr_r )
48  {
49  sat::LookupAttr query( attr_r, solv_r );
50  for_( it, query.begin(), query.end() )
51  {
52  ret_r.push_back( it.asString() );
53  }
54  }
55  }
56 
58  //
59  // METHOD NAME : Product::Product
60  // METHOD TYPE : Ctor
61  //
62  Product::Product( const sat::Solvable & solvable_r )
63  : ResObject( solvable_r )
64  {}
65 
67  //
68  // METHOD NAME : Product::~Product
69  // METHOD TYPE : Dtor
70  //
72  {}
73 
75 
77  {
78  // Look for a provider of 'product(name) = version' of same
79  // architecture and within the same repo.
80  //
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() ) );
85 
86  sat::Solvable found;
87  sat::WhatProvides providers( identCap );
88  for_( it, providers.begin(), providers.end() )
89  {
90  if ( it->repository() == repository()
91  && it->arch() == arch() )
92  {
93  if ( ! found || found.edition() < it->edition() )
94  found = *it;
95  }
96  }
97  if ( ! found )
98  WAR << *this << ": no reference package found: " << identCap << endl;
99  return found;
100  }
101 
102  std::string Product::referenceFilename() const
104 
106  {
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).
110 
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() )
115  {
116  if ( it->isKind( ResKind::product ) )
117  ret.push_back( make<Product>( *it ) );
118  }
119 
120  // If we have a buddy, we check what product buddies the
121  // buddy replaces.
122  obsoleting = sat::WhatObsoletes( poolItem().buddy() );
123  for_( it, obsoleting.poolItemBegin(), obsoleting.poolItemEnd() )
124  {
125  if ( (*it).buddy().isKind( ResKind::product ) )
126  ret.push_back( make<Product>( (*it).buddy() ) );
127  }
128  return ret;
129  }
130 
132  { return poolItem().buddy().valuesOfNamespace( "weakremover" ); }
133 
134  std::string Product::productLine() const
136 
138 
139  std::string Product::shortName() const
141 
142  std::string Product::flavor() const
143  {
144  // Look for a provider of 'product_flavor(name) = version'
145  // within the same repo. Unlike the reference package, we
146  // can be relaxed and ignore the architecture.
147  Capability identCap( str::form( "product_flavor(%s) = %s", name().c_str(), edition().c_str() ) );
148 
149  sat::WhatProvides providers( identCap );
150  for_( it, providers.begin(), providers.end() )
151  {
152  if ( it->repository() == repository() )
153  {
154  // Got the package now try to get the provided 'flavor(...)'
155  Capabilities provides( it->provides() );
156  for_( cap, provides.begin(), provides.end() )
157  {
158  std::string capstr( cap->asString() );
159  if ( str::hasPrefix( capstr, "flavor(" ) )
160  {
161  capstr = str::stripPrefix( capstr, "flavor(" );
162  capstr.erase( capstr.size()-1 ); // trailing ')'
163  return capstr;
164  }
165  }
166  }
167  }
168  return std::string();
169  }
170 
171  std::string Product::type() const
173 
174  std::list<std::string> Product::flags() const
175  {
176  std::list<std::string> ret;
177  fillList( ret, satSolvable(), sat::SolvAttr::productFlags );
178  return ret;
179  }
180 
182  { return isSystem() && lookupStrAttribute( sat::SolvAttr::productType ) == "base"; }
183 
184  std::string Product::registerTarget() const
186 
187  std::string Product::registerRelease() const
189 
191 
192  Product::UrlList Product::urls( const std::string & key_r ) const
193  {
194  UrlList ret;
195 
198 
199  sat::LookupAttr::iterator url_it(url.begin());
200  sat::LookupAttr::iterator url_type_it(url_type.begin());
201 
202  for (;url_it != url.end(); ++url_it, ++url_type_it)
203  {
204  /* safety checks, shouldn't happen (tm) */
205  if (url_type_it == url_type.end())
206  {
207  ERR << *this << " : The thing that should not happen, happened." << endl;
208  break;
209  }
210 
211  if ( url_type_it.asString() == key_r )
212  {
213  ret._list.push_back(url_it.asString());
214  }
215  } /* while (attribute array) */
216 
217  return ret;
218  }
219 
220  Product::UrlList Product::releaseNotesUrls() const { return urls( "releasenotes" ); }
221  Product::UrlList Product::registerUrls() const { return urls( "register" ); }
222  Product::UrlList Product::smoltUrls() const { return urls( "smolt" ); }
223  Product::UrlList Product::updateUrls() const { return urls( "update" ); }
224  Product::UrlList Product::extraUrls() const { return urls( "extra" ); }
225  Product::UrlList Product::optionalUrls() const { return urls( "optional" ); }
226 
227  std::ostream & operator<<( std::ostream & str, const Product::UrlList & obj )
228  { return dumpRange( str << obj.key() << ' ', obj.begin(), obj.end() ); }
229 
231 } // namespace zypp