Provide product::updaterepoKey: Update repository indicator string.
[platform/upstream/libzypp.git] / zypp / Product.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/Product.cc
10  *
11 */
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
25 ///////////////////////////////////////////////////////////////////
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
57   ///////////////////////////////////////////////////////////////////
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
66   ///////////////////////////////////////////////////////////////////
67   //
68   //    METHOD NAME : Product::~Product
69   //    METHOD TYPE : Dtor
70   //
71   Product::~Product()
72   {}
73
74   ///////////////////////////////////////////////////////////////////
75
76   sat::Solvable Product::referencePackage() const
77   {
78     Capability identCap( lookupStrAttribute( sat::SolvAttr::productReferences ) );
79     if ( ! identCap )
80     {
81       // No 'references': fallback to provider of 'product(name) = version'
82       // Without this solver testcase won't work, as it does not remember
83       // 'references'.
84       identCap = Capability( str::form( "product(%s) = %s", name().c_str(), edition().c_str() )  );
85     }
86     if ( ! identCap )
87     {
88       return sat::Solvable::noSolvable;
89     }
90
91     // if there is productReferences defined, we expect
92     // a matching package within the same repo. And of
93     // same arch.
94     sat::WhatProvides providers( identCap );
95     for_( it, providers.begin(), providers.end() )
96     {
97       if ( it->repository() == repository()
98            && it->arch() == arch() )
99         return *it;
100     }
101
102     WAR << *this << ": no reference package found: " << identCap << endl;
103     return sat::Solvable::noSolvable;
104   }
105
106   Product::ReplacedProducts Product::replacedProducts() const
107   {
108     std::vector<constPtr> ret;
109     // By now we simply collect what is obsoleted by the Product,
110     // or by the products buddy (release-package).
111
112     // Check our own dependencies. We should not have any,
113     // but just to be shure.
114     sat::WhatObsoletes obsoleting( satSolvable() );
115     for_( it, obsoleting.begin(), obsoleting.end() )
116     {
117       if ( it->isKind( ResKind::product ) )
118         ret.push_back( make<Product>( *it ) );
119     }
120
121     // If we have a buddy, we check what product buddies the
122     // buddy replaces.
123     obsoleting = sat::WhatObsoletes( poolItem().buddy() );
124     for_( it, obsoleting.poolItemBegin(), obsoleting.poolItemEnd() )
125     {
126       if ( (*it).buddy().isKind( ResKind::product ) )
127         ret.push_back( make<Product>( (*it).buddy() ) );
128     }
129
130     return ret;
131   }
132
133   ///////////////////////////////////////////////////////////////////
134
135   std::string Product::shortName() const
136   { return lookupStrAttribute( sat::SolvAttr::productShortlabel ); }
137
138   std::string Product::flavor() const
139   { return lookupStrAttribute( sat::SolvAttr::productFlavor ); }
140
141   std::string Product::type() const
142   { return lookupStrAttribute( sat::SolvAttr::productType ); }
143
144   std::string Product::updaterepoKey() const
145   { return lookupStrAttribute( sat::SolvAttr::productUpdaterepoKey ); }
146
147   Url Product::releaseNotesUrl() const
148   {
149     std::list<Url> ret;
150     fillList( ret, satSolvable(), sat::SolvAttr::productRelnotesurl );
151     if ( ! ret.empty() )
152       return  ret.front();
153     return Url();
154   }
155
156   std::list<Url> Product::updateUrls() const
157   {
158     std::list<Url> ret;
159     fillList( ret, satSolvable(), sat::SolvAttr::productUpdateurls );
160     return ret;
161   }
162
163   std::list<Url> Product::extraUrls() const
164   {
165     std::list<Url> ret;
166     fillList( ret, satSolvable(), sat::SolvAttr::productExtraurls );
167     return ret;
168   }
169
170   std::list<Url> Product::optionalUrls() const
171   {
172     std::list<Url> ret;
173     fillList( ret, satSolvable(), sat::SolvAttr::productOptionalurls );
174     return ret;
175   }
176
177   std::list<std::string> Product::flags() const
178   {
179     std::list<std::string> ret;
180     fillList( ret, satSolvable(), sat::SolvAttr::productFlags );
181     return ret;
182   }
183
184   std::string Product::distributionName() const
185   { return lookupStrAttribute( sat::SolvAttr::productDistproduct ); }
186
187   Edition Product::distributionEdition() const
188   { return Edition( lookupStrAttribute( sat::SolvAttr::productDistversion ) ); }
189
190
191   /////////////////////////////////////////////////////////////////
192 } // namespace zypp
193 ///////////////////////////////////////////////////////////////////