libzypp 17.31.23
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>
18
19using std::endl;
20
22namespace zypp
23{
24
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 //
42 {}
43
45
46 std::string Patch::category() const
48
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
141
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
216
219
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
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
260 {
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
277 {
278 Contents result;
279 // DBG << *this << endl;
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 */
312 if ( providers.empty() )
313 {
314 /* no exact providers: find 'best' providers: those with a larger evr */
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
340 { base_reference() = sat::LookupAttr( sat::SolvAttr::updateReference, val_r ).begin(); }
341
343 { return base_reference().subFind( sat::SolvAttr::updateReferenceId ).asString(); }
345 { return base_reference().subFind( sat::SolvAttr::updateReferenceHref ).asString(); }
347 { return base_reference().subFind( sat::SolvAttr::updateReferenceTitle ).asString(); }
349 { return base_reference().subFind( sat::SolvAttr::updateReferenceType ).asString(); }
350
352} // namespace zypp
Architecture.
Definition: Arch.h:37
A sat capability.
Definition: Capability.h:63
Edition represents [epoch:]version[-release]
Definition: Edition.h:61
Access to the sat-pools string space.
Definition: IdString.h:43
'Language[_Country]' codes.
Definition: Locale.h:50
std::string title() const
Title describing the issue.
Definition: Patch.cc:346
std::string id() const
The id of the reference.
Definition: Patch.cc:342
std::string href() const
Url or pointer where to find more information.
Definition: Patch.cc:344
std::string type() const
Type of the reference.
Definition: Patch.cc:348
Class representing a patch.
Definition: Patch.h:38
Category categoryEnum() const
This patch's category as enum of wellknown categories.
Definition: Patch.cc:49
bool isSeverity(const std::string &severity_r) const
Whether this patch's severity matches severity_r.
Definition: Patch.cc:145
bool interactive() const
Is the patch installation interactive? (does it need user input?)
Definition: Patch.cc:259
InteractiveFlag
Flags defining if and why this patch is interactive.
Definition: Patch.h:62
@ License
Definition: Patch.h:66
@ Message
Definition: Patch.h:65
@ Reboot
Definition: Patch.h:64
@ NoFlags
Definition: Patch.h:63
SeverityFlag
Possible severity levels for (security) patches.
Definition: Patch.h:76
@ SEV_CRITICAL
Critical.
Definition: Patch.h:82
@ SEV_LOW
Low.
Definition: Patch.h:79
@ SEV_MODERATE
Moderate.
Definition: Patch.h:80
@ SEV_NONE
no value specified
Definition: Patch.h:78
@ SEV_IMPORTANT
Important.
Definition: Patch.h:81
@ SEV_OTHER
unknown value specified
Definition: Patch.h:77
InteractiveFlags interactiveFlags() const
Get the InteractiveFlags of this Patch.
Definition: Patch.cc:223
std::string severity() const
Severity string as specified in metadata.
Definition: Patch.cc:139
std::string category() const
Patch category (recommended, security,...)
Definition: Patch.cc:46
bool rebootSuggested() const
Does the system need to reboot to finish the update process?
Definition: Patch.cc:214
bool reloginSuggested() const
Does the patch needs the user to relogin to take effect? relogin is suggested then.
Definition: Patch.cc:220
bool isCategory(const std::string &category_r) const
Whether this patch's category matches category_r.
Definition: Patch.cc:52
Contents contents() const
The collection of packages associated with this patch.
Definition: Patch.cc:276
@ CAT_DOCUMENT
Definition: Patch.h:54
@ CAT_YAST
Definition: Patch.h:50
@ CAT_RECOMMENDED
Definition: Patch.h:52
@ CAT_OTHER
unknown value specified
Definition: Patch.h:49
@ CAT_OPTIONAL
Definition: Patch.h:53
@ CAT_SECURITY
Definition: Patch.h:51
virtual ~Patch()
Dtor.
Definition: Patch.cc:41
std::string message(const Locale &lang_r=Locale()) const
Information or warning to be displayed to the user.
Definition: Patch.cc:211
SeverityFlag severityFlag() const
Severity string mapped to an enum.
Definition: Patch.cc:142
bool restartSuggested() const
Does the patch affect the package manager itself? restart is suggested then.
Definition: Patch.cc:217
Patch(const sat::Solvable &solvable_r)
Ctor.
Definition: Patch.cc:32
bool interactiveWhenIgnoring(InteractiveFlags flags_r=NoFlags) const
Is the patch still interactive when ignoring this flags?
Definition: Patch.cc:247
static const ResKind package
Definition: ResKind.h:40
Base for resolvable objects.
Definition: ResObject.h:38
friend ResObject::Ptr makeResObject(const sat::Solvable &solvable_r)
Create ResObject from sat::Solvable.
Definition: ResObject.cc:43
Lightweight attribute value lookup.
Definition: LookupAttr.h:108
iterator end() const
Iterator behind the end of query results.
Definition: LookupAttr.cc:239
iterator begin() const
Iterator to the begin of query results.
Definition: LookupAttr.cc:236
static const SolvAttr updateCollectionArch
Definition: SolvAttr.h:126
static const SolvAttr updateReferenceId
Definition: SolvAttr.h:132
static const SolvAttr updateReferenceType
Definition: SolvAttr.h:130
static const SolvAttr message
Definition: SolvAttr.h:120
static const SolvAttr updateCollectionEvr
Definition: SolvAttr.h:125
static const SolvAttr updateReferenceHref
Definition: SolvAttr.h:131
static const SolvAttr restartSuggested
Definition: SolvAttr.h:118
static const SolvAttr updateCollectionName
Definition: SolvAttr.h:124
static const SolvAttr updateCollection
Definition: SolvAttr.h:123
static const SolvAttr rebootSuggested
Definition: SolvAttr.h:117
static const SolvAttr updateReferenceTitle
Definition: SolvAttr.h:133
static const SolvAttr patchcategory
Definition: SolvAttr.h:116
static const SolvAttr updateReference
Definition: SolvAttr.h:129
static const SolvAttr severity
Definition: SolvAttr.h:121
static const SolvAttr reloginSuggested
Definition: SolvAttr.h:119
Solvable set wrapper to allow adding additional convenience iterators.
Definition: SolvableSet.h:36
Container & get()
The set.
Definition: SolvableSet.h:98
const_iterator end() const
Iterator pointing behind the last Solvable.
Definition: SolvableSet.h:76
const_iterator begin() const
Iterator pointing to the first Solvable.
Definition: SolvableSet.h:72
A Solvable object within the sat Pool.
Definition: Solvable.h:54
Container of Solvable providing a Capability (read only).
Definition: WhatProvides.h:89
const_iterator end() const
Iterator pointing behind the last Solvable.
Definition: WhatProvides.h:234
bool empty() const
Whether the container is empty.
const_iterator begin() const
Iterator pointing to the first Solvable.
std::string hexstring(char n, int w=4)
Definition: String.h:324
std::string toLower(const std::string &s)
Return lowercase version of s.
Definition: String.cc:177
int compareCI(const C_Str &lhs, const C_Str &rhs)
Definition: String.h:984
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
static const Rel GT
Definition: Rel.h:54
static const Rel EQ
Definition: Rel.h:50
bool lookupBoolAttribute(const SolvAttr &attr) const
Definition: SolvableType.h:142
std::string lookupStrAttribute(const SolvAttr &attr) const
Definition: SolvableType.h:140
Solvable satSolvable() const
Return the corresponding sat::Solvable.
Definition: SolvableType.h:57
std::string licenseToConfirm(const Locale &lang_r=Locale()) const
Definition: SolvableType.h:136
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:28
#define WAR
Definition: Logger.h:97
#define INT
Definition: Logger.h:100
#define IMPL_PTR_TYPE(NAME)