libzypp: zypp/Patch.cc Source File

libzypp 17.36.6

Patch.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#include <iostream>
13
14#include <zypp/base/LogTools.h>
15#include <zypp/base/String.h>
16#include <zypp/Patch.h>
17#include <zypp/sat/WhatProvides.h>
18
19using std::endl;
20
22namespace zypp
23{
24
25 IMPL_PTR_TYPE( Patch );
26
28 //
29 // METHOD NAME : Patch::Patch
30 // METHOD TYPE : Ctor
31 //
32 Patch::Patch( const sat::Solvable & solvable_r )
33 : ResObject( solvable_r )
34 {}
35
37 //
38 // METHOD NAME : Patch::~Patch
39 // METHOD TYPE : Dtor
40 //
41 Patch::~Patch()
42 {}
43
45
46 std::string Patch::category() const
47 { return str::toLower(lookupStrAttribute( sat::SolvAttr::patchcategory )); }
48
49 Patch::Category Patch::categoryEnum() const
50 { return categoryEnum( category() ); }
51
52 bool Patch::isCategory( const std::string & category_r ) const
53 {
54 // bsc#1179847: identify the wellknown categories
55 Category catenum = categoryEnum( category_r );
56 return ( catenum == CAT_OTHER && str::compareCI( category_r, category() ) == 0 )
57 || ( catenum == categoryEnum() );
58 }
59
60 bool Patch::isCategory( Categories category_r ) const
61 { return category_r.testFlag( categoryEnum() ); }
62
63 Patch::Category Patch::categoryEnum( const std::string & category_r )
64 {
65 switch ( category_r[0] )
66 {
67 // CAT_YAST
68 case 'y':
69 case 'Y':
70 if ( str::compareCI( category_r, "yast" ) == 0 )
71 return CAT_YAST;
72 break;
73
74 // CAT_SECURITY
75 case 's':
76 case 'S':
77 if ( str::compareCI( category_r, "security" ) == 0 )
78 return CAT_SECURITY;
79 break;
80
81 // CAT_RECOMMENDED
82 case 'r':
83 case 'R':
84 if ( str::compareCI( category_r, "recommended" ) == 0 )
85 return CAT_RECOMMENDED;
86 break;
87 case 'b':
88 case 'B':
89 if ( str::compareCI( category_r, "bugfix" ) == 0 ) // rhn
90 return CAT_RECOMMENDED;
91 break;
92
93 // CAT_OPTIONAL
94 case 'o':
95 case 'O':
96 if ( str::compareCI( category_r, "optional" ) == 0 )
97 return CAT_OPTIONAL;
98 break;
99 case 'f':
100 case 'F':
101 if ( str::compareCI( category_r, "feature" ) == 0 )
102 return CAT_OPTIONAL;
103 break;
104 case 'e':
105 case 'E':
106 if ( str::compareCI( category_r, "enhancement" ) == 0 ) // rhn
107 return CAT_OPTIONAL;
108 break;
109
110 // CAT_DOCUMENT
111 case 'd':
112 case 'D':
113 if ( str::compareCI( category_r, "document" ) == 0 )
114 return CAT_DOCUMENT;
115 break;
116 }
117 // default:
118 INT << "Unrecognized Patch::Category string '" << category_r << "'" << endl;
119 return CAT_OTHER;
120 }
121
122 std::string asString( const Patch::Category & obj )
123 {
124 switch ( obj )
125 {
126 case Patch::CAT_OTHER: return std::string( "other" ); break;
127 case Patch::CAT_YAST: return std::string( "yast" ); break;
128 case Patch::CAT_SECURITY: return std::string( "security" ); break;
129 case Patch::CAT_RECOMMENDED: return std::string( "recommended" ); break;
130 case Patch::CAT_OPTIONAL: return std::string( "optional" ); break;
131 case Patch::CAT_DOCUMENT: return std::string( "document" ); break;
132 }
133 // make gcc happy:
134 return std::string( "other" );
135 }
136
138
139 std::string Patch::severity() const
140 { return str::toLower(lookupStrAttribute( sat::SolvAttr::severity )); }
141
142 Patch::SeverityFlag Patch::severityFlag() const
143 { return severityFlag( severity() ); }
144
145 bool Patch::isSeverity( const std::string & severity_r ) const
146 { return( str::compareCI( severity_r, severity() ) == 0 ); }
147
148 bool Patch::isSeverity( SeverityFlags severity_r ) const
149 { return severity_r.testFlag( severityFlag() ); }
150
151 Patch::SeverityFlag Patch::severityFlag( const std::string & severity_r )
152 {
153 switch ( severity_r[0] )
154 {
155 case 'l':
156 case 'L':
157 if ( str::compareCI( severity_r, "low" ) == 0 )
158 return SEV_LOW;
159 break;
160
161 case 'm':
162 case 'M':
163 if ( str::compareCI( severity_r, "moderate" ) == 0 )
164 return SEV_MODERATE;
165 break;
166
167 case 'i':
168 case 'I':
169 if ( str::compareCI( severity_r, "important" ) == 0 )
170 return SEV_IMPORTANT;
171 break;
172
173 case 'c':
174 case 'C':
175 if ( str::compareCI( severity_r, "critical" ) == 0 )
176 return SEV_CRITICAL;
177 break;
178
179 case 'u':
180 case 'U':
181 if ( str::compareCI( severity_r, "unspecified" ) == 0 )
182 return SEV_NONE;
183 break;
184
185 case '\0':
186 return SEV_NONE;
187 break;
188 }
189 // default:
190 INT << "Unrecognized Patch::Severity string '" << severity_r << "'" << endl;
191 return SEV_OTHER;
192 }
193
194 std::string asString( const Patch::SeverityFlag & obj )
195 {
196 switch ( obj )
197 {
198 case Patch::SEV_OTHER: return std::string( "unknown" ); break;
199 case Patch::SEV_NONE: return std::string( "unspecified" ); break;
200 case Patch::SEV_LOW: return std::string( "low" ); break;
201 case Patch::SEV_MODERATE: return std::string( "moderate" ); break;
202 case Patch::SEV_IMPORTANT:return std::string( "important" ); break;
203 case Patch::SEV_CRITICAL: return std::string( "critical" ); break;
204 }
205 // make gcc happy:
206 return std::string( "unknown" );
207 }
208
210 //
211std::string Patch::message( const Locale & lang_r ) const
212 { return lookupStrAttribute( sat::SolvAttr::message, lang_r ); }
213
214 bool Patch::rebootSuggested() const
215 { return lookupBoolAttribute( sat::SolvAttr::rebootSuggested ); }
216
217 bool Patch::restartSuggested() const
218 { return lookupBoolAttribute( sat::SolvAttr::restartSuggested ); }
219
220 bool Patch::reloginSuggested() const
221 { return lookupBoolAttribute( sat::SolvAttr::reloginSuggested ); }
222
223 Patch::InteractiveFlags Patch::interactiveFlags() const
224 {
225 InteractiveFlags patchFlags (NoFlags);
226 if ( rebootSuggested() )
227 patchFlags |= Reboot;
228
229 if ( ! message().empty() )
230 patchFlags |= Message;
231
232 if ( ! licenseToConfirm().empty() )
233 patchFlags |= License;
234
235 Patch::Contents c( contents() );
236 for_( it, c.begin(), c.end() )
237 {
238 if ( ! makeResObject(*it)->licenseToConfirm().empty() )
239 {
240 patchFlags |= License;
241 break;
242 }
243 }
244 return patchFlags;
245 }
246
247 bool Patch::interactiveWhenIgnoring( InteractiveFlags flags_r ) const
248 {
249 if ( interactiveFlags() & ( ~flags_r ) )
250 {
251 return true;
252 }
253 else
254 {
255 return false;
256 }
257 }
258
259 bool Patch::interactive() const
260 {
261 return interactiveWhenIgnoring();
262 }
263
264 std::string asString( const Patch::InteractiveFlag & obj )
265 {
266 switch ( obj )
267 {
268 case Patch::NoFlags: return ""; break;
269 case Patch::Reboot: return "reboot"; break;
270 case Patch::Message: return "message"; break;
271 case Patch::License: return "license"; break;
272 }
273 return str::hexstring(obj);
274 }
275
276 Patch::Contents Patch::contents() const
277 {
278 Contents result;
279 // DBG << *this << endl;
280 sat::LookupAttr updateCollection( sat::SolvAttr::updateCollection, satSolvable() );
281 for_( entry, updateCollection.begin(), updateCollection.end() )
282 {
283 IdString name ( entry.subFind( sat::SolvAttr::updateCollectionName ).idStr() );
284 Edition edition ( entry.subFind( sat::SolvAttr::updateCollectionEvr ).idStr() );
285 Arch arch ( entry.subFind( sat::SolvAttr::updateCollectionArch ).idStr() );
286 if ( name.empty() )
287 {
288 WAR << "Ignore malformed updateCollection entry: " << name << "-" << edition << "." << arch << endl;
289 continue;
290 }
291
292 // The entry is relevant if there is an installed
293 // package with the same name and arch.
294 bool relevant = false;
295 sat::WhatProvides providers( (Capability( name.id() )) );
296 for_( it, providers.begin(), providers.end() )
297 {
298 if ( it->isSystem() && it->ident() == name && it->arch() == arch )
299 {
300 relevant = true;
301 break;
302 }
303 }
304 if ( ! relevant )
305 {
306 // DBG << "Not relevant: " << name << "-" << edition << "." << arch << endl;
307 continue;
308 }
309
310 /* find exact providers first (this matches the _real_ 'collection content' of the patch */
311 providers = sat::WhatProvides( Capability( arch, name.c_str(), Rel::EQ, edition, ResKind::package ) );
312 if ( providers.empty() )
313 {
314 /* no exact providers: find 'best' providers: those with a larger evr */
315 providers = sat::WhatProvides( Capability( arch, name.c_str(), Rel::GT, edition, ResKind::package ) );
316 if ( providers.empty() )
317 {
318 // Hmm, this patch is not installable, no one is providing the package in the collection
319 // FIXME: raise execption ? fake a solvable ?
320 WAR << "Missing provider: " << name << "-" << edition << "." << arch << endl;
321 continue;
322 }
323 }
324
325 // FIXME ?! loop over providers and try to find installed ones ?
326 // DBG << "Found " << name << "-" << edition << "." << arch << ": " << *(providers.begin()) << endl;
327 result.get().insert( *(providers.begin()) );
328 }
329
330 return result;
331 }
332
334 //
335 // CLASS NAME : Patch::ReferenceIterator
336 //
338
339 Patch::ReferenceIterator::ReferenceIterator( const sat::Solvable & val_r )
340 { base_reference() = sat::LookupAttr( sat::SolvAttr::updateReference, val_r ).begin(); }
341
342 std::string Patch::ReferenceIterator::id() const
343 { return base_reference().subFind( sat::SolvAttr::updateReferenceId ).asString(); }
344 std::string Patch::ReferenceIterator::href() const
345 { return base_reference().subFind( sat::SolvAttr::updateReferenceHref ).asString(); }
346 std::string Patch::ReferenceIterator::title() const
347 { return base_reference().subFind( sat::SolvAttr::updateReferenceTitle ).asString(); }
348 std::string Patch::ReferenceIterator::type() const
349 { return base_reference().subFind( sat::SolvAttr::updateReferenceType ).asString(); }
350
352} // namespace zypp
Patch.h
WhatProvides.h
zypp::Arch
Architecture.
Definition Arch.h:37
zypp::Capability
A sat capability.
Definition Capability.h:63
zypp::Edition
Edition represents [epoch:]version[-release]
Definition Edition.h:61
zypp::IdString
Access to the sat-pools string space.
Definition IdString.h:44
zypp::Locale
'Language[_Country]' codes.
Definition Locale.h:51
zypp::Patch::ReferenceIterator::title
std::string title() const
Title describing the issue.
Definition Patch.cc:346
zypp::Patch::ReferenceIterator::ReferenceIterator
ReferenceIterator()
Definition Patch.h:278
zypp::Patch::ReferenceIterator::id
std::string id() const
The id of the reference.
Definition Patch.cc:342
zypp::Patch::ReferenceIterator::href
std::string href() const
Url or pointer where to find more information.
Definition Patch.cc:344
zypp::Patch::ReferenceIterator::type
std::string type() const
Type of the reference.
Definition Patch.cc:348
zypp::Patch
Class representing a patch.
Definition Patch.h:38
zypp::Patch::categoryEnum
Category categoryEnum() const
This patch's category as enum of wellknown categories.
Definition Patch.cc:49
zypp::Patch::isSeverity
bool isSeverity(const std::string &severity_r) const
Whether this patch's severity matches severity_r.
Definition Patch.cc:145
zypp::Patch::interactive
bool interactive() const
Is the patch installation interactive?
Definition Patch.cc:259
zypp::Patch::InteractiveFlag
InteractiveFlag
Flags defining if and why this patch is interactive.
Definition Patch.h:62
zypp::Patch::License
@ License
Definition Patch.h:66
zypp::Patch::Message
@ Message
Definition Patch.h:65
zypp::Patch::Reboot
@ Reboot
Definition Patch.h:64
zypp::Patch::NoFlags
@ NoFlags
Definition Patch.h:63
zypp::Patch::SeverityFlag
SeverityFlag
Possible severity levels for (security) patches.
Definition Patch.h:76
zypp::Patch::SEV_CRITICAL
@ SEV_CRITICAL
Critical.
Definition Patch.h:82
zypp::Patch::SEV_LOW
@ SEV_LOW
Low.
Definition Patch.h:79
zypp::Patch::SEV_MODERATE
@ SEV_MODERATE
Moderate.
Definition Patch.h:80
zypp::Patch::SEV_NONE
@ SEV_NONE
no value specified
Definition Patch.h:78
zypp::Patch::SEV_IMPORTANT
@ SEV_IMPORTANT
Important.
Definition Patch.h:81
zypp::Patch::SEV_OTHER
@ SEV_OTHER
unknown value specified
Definition Patch.h:77
zypp::Patch::interactiveFlags
InteractiveFlags interactiveFlags() const
Get the InteractiveFlags of this Patch.
Definition Patch.cc:223
zypp::Patch::severity
std::string severity() const
Severity string as specified in metadata.
Definition Patch.cc:139
zypp::Patch::category
std::string category() const
Patch category (recommended, security,...)
Definition Patch.cc:46
zypp::Patch::Contents
sat::SolvableSet Contents
Definition Patch.h:46
zypp::Patch::rebootSuggested
bool rebootSuggested() const
Does the system need to reboot to finish the update process?
Definition Patch.cc:214
zypp::Patch::reloginSuggested
bool reloginSuggested() const
Does the patch needs the user to relogin to take effect?
Definition Patch.cc:220
zypp::Patch::~Patch
~Patch() override
Dtor.
Definition Patch.cc:41
zypp::Patch::isCategory
bool isCategory(const std::string &category_r) const
Whether this patch's category matches category_r.
Definition Patch.cc:52
zypp::Patch::contents
Contents contents() const
The collection of packages associated with this patch.
Definition Patch.cc:276
zypp::Patch::Category
Category
Definition Patch.h:48
zypp::Patch::CAT_DOCUMENT
@ CAT_DOCUMENT
Definition Patch.h:54
zypp::Patch::CAT_YAST
@ CAT_YAST
Definition Patch.h:50
zypp::Patch::CAT_RECOMMENDED
@ CAT_RECOMMENDED
Definition Patch.h:52
zypp::Patch::CAT_OTHER
@ CAT_OTHER
unknown value specified
Definition Patch.h:49
zypp::Patch::CAT_OPTIONAL
@ CAT_OPTIONAL
Definition Patch.h:53
zypp::Patch::CAT_SECURITY
@ CAT_SECURITY
Definition Patch.h:51
zypp::Patch::message
std::string message(const Locale &lang_r=Locale()) const
Information or warning to be displayed to the user.
Definition Patch.cc:211
zypp::Patch::severityFlag
SeverityFlag severityFlag() const
Severity string mapped to an enum.
Definition Patch.cc:142
zypp::Patch::restartSuggested
bool restartSuggested() const
Does the patch affect the package manager itself?
Definition Patch.cc:217
zypp::Patch::Patch
Patch(const sat::Solvable &solvable_r)
Ctor.
Definition Patch.cc:32
zypp::Patch::interactiveWhenIgnoring
bool interactiveWhenIgnoring(InteractiveFlags flags_r=NoFlags) const
Is the patch still interactive when ignoring this flags?
Definition Patch.cc:247
zypp::ResKind::package
static const ResKind package
Definition ResKind.h:40
zypp::ResObject::makeResObject
friend ResObject::Ptr makeResObject(const sat::Solvable &solvable_r)
Create ResObject from sat::Solvable.
Definition ResObject.cc:43
zypp::ResObject::ResObject
ResObject(const sat::Solvable &solvable_r)
Ctor.
Definition ResObject.cc:23
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::subFind
iterator subFind(const SolvAttr &attr_r) const
Iterator pointing to the first occurance of SolvAttr attr_r in sub-structure.
Definition LookupAttr.cc:498
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::begin
iterator begin() const
Iterator to the begin of query results.
Definition LookupAttr.cc:237
zypp::sat::SolvAttr::updateCollectionArch
static const SolvAttr updateCollectionArch
Definition SolvAttr.h:138
zypp::sat::SolvAttr::updateReferenceId
static const SolvAttr updateReferenceId
Definition SolvAttr.h:144
zypp::sat::SolvAttr::updateReferenceType
static const SolvAttr updateReferenceType
Definition SolvAttr.h:142
zypp::sat::SolvAttr::message
static const SolvAttr message
Definition SolvAttr.h:132
zypp::sat::SolvAttr::updateCollectionEvr
static const SolvAttr updateCollectionEvr
Definition SolvAttr.h:137
zypp::sat::SolvAttr::updateReferenceHref
static const SolvAttr updateReferenceHref
Definition SolvAttr.h:143
zypp::sat::SolvAttr::restartSuggested
static const SolvAttr restartSuggested
Definition SolvAttr.h:130
zypp::sat::SolvAttr::updateCollectionName
static const SolvAttr updateCollectionName
Definition SolvAttr.h:136
zypp::sat::SolvAttr::updateCollection
static const SolvAttr updateCollection
Definition SolvAttr.h:135
zypp::sat::SolvAttr::rebootSuggested
static const SolvAttr rebootSuggested
Definition SolvAttr.h:129
zypp::sat::SolvAttr::updateReferenceTitle
static const SolvAttr updateReferenceTitle
Definition SolvAttr.h:145
zypp::sat::SolvAttr::patchcategory
static const SolvAttr patchcategory
Definition SolvAttr.h:128
zypp::sat::SolvAttr::updateReference
static const SolvAttr updateReference
Definition SolvAttr.h:141
zypp::sat::SolvAttr::severity
static const SolvAttr severity
Definition SolvAttr.h:133
zypp::sat::SolvAttr::reloginSuggested
static const SolvAttr reloginSuggested
Definition SolvAttr.h:131
zypp::sat::SolvableSet::get
Container & get()
The set.
Definition SolvableSet.h:98
zypp::sat::SolvableSet::end
const_iterator end() const
Iterator pointing behind the last Solvable.
Definition SolvableSet.h:76
zypp::sat::SolvableSet::begin
const_iterator begin() const
Iterator pointing to the first Solvable.
Definition SolvableSet.h:72
zypp::sat::Solvable
A Solvable object within the sat Pool.
Definition Solvable.h:54
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::empty
bool empty() const
Whether the container is empty.
Definition WhatProvides.cc:129
zypp::sat::WhatProvides::begin
const_iterator begin() const
Iterator pointing to the first Solvable.
Definition WhatProvides.cc:145
zypp::str::toLower
std::string toLower(const std::string &s)
Return lowercase version of s.
Definition String.cc:178
zypp::str::hexstring
std::string hexstring(char n, int w=4)
Definition String.h:324
zypp::str::compareCI
int compareCI(const C_Str &lhs, const C_Str &rhs)
Definition String.h:983
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition Application.cc:20
zypp::asString
std::string asString(const Patch::Category &obj)
Definition Patch.cc:122
zypp::Rel::GT
static const Rel GT
Definition Rel.h:56
zypp::Rel::EQ
static const Rel EQ
Definition Rel.h:52
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 >::lookupBoolAttribute
bool lookupBoolAttribute(const SolvAttr &attr) const
Definition SolvableType.h:155
zypp::sat::SolvableType< Resolvable >::lookupStrAttribute
std::string lookupStrAttribute(const SolvAttr &attr) const
Definition SolvableType.h:153
zypp::sat::SolvableType< Resolvable >::satSolvable
Solvable satSolvable() const
Definition SolvableType.h:57
zypp::sat::SolvableType< Resolvable >::licenseToConfirm
std::string licenseToConfirm(const Locale &lang_r=Locale()) const
Definition SolvableType.h:149
zypp::sat::SolvableType< Resolvable >::edition
Edition edition() const
Definition SolvableType.h:71
for_
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition Easy.h:27
WAR
#define WAR
Definition Logger.h:101
INT
#define INT
Definition Logger.h:104
IMPL_PTR_TYPE
#define IMPL_PTR_TYPE(NAME)
Definition ReferenceCounted.h:137
LogTools.h
String.h