1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/Patch.cc
14 #include "zypp/base/LogTools.h"
15 #include "zypp/base/String.h"
16 #include "zypp/Patch.h"
17 #include "zypp/sat/WhatProvides.h"
21 ///////////////////////////////////////////////////////////////////
23 { /////////////////////////////////////////////////////////////////
25 IMPL_PTR_TYPE( Patch );
27 ///////////////////////////////////////////////////////////////////
29 // METHOD NAME : Patch::Patch
32 Patch::Patch( const sat::Solvable & solvable_r )
33 : ResObject( solvable_r )
36 ///////////////////////////////////////////////////////////////////
38 // METHOD NAME : Patch::~Patch
44 ///////////////////////////////////////////////////////////////////
46 // Patch interface forwarded to implementation
48 ///////////////////////////////////////////////////////////////////
50 Patch::Category Patch::categoryEnum() const
52 std::string cat( category() );
58 if ( str::compareCI( cat, "yast" ) == 0 )
65 if ( str::compareCI( cat, "security" ) == 0 )
72 if ( str::compareCI( cat, "recommended" ) == 0 )
73 return CAT_RECOMMENDED;
77 if ( str::compareCI( cat, "bugfix" ) == 0 ) // rhn
78 return CAT_RECOMMENDED;
84 if ( str::compareCI( cat, "optional" ) == 0 )
89 if ( str::compareCI( cat, "feature" ) == 0 )
94 if ( str::compareCI( cat, "enhancement" ) == 0 ) // rhn
101 if ( str::compareCI( cat, "document" ) == 0 )
109 std::string Patch::severity() const
110 { return lookupStrAttribute( sat::SolvAttr::severity ); }
112 Patch::SeverityFlag Patch::severityFlag() const
114 std::string sev( severity() );
119 if ( str::compareCI( sev, "low" ) == 0 )
125 if ( str::compareCI( sev, "moderate" ) == 0 )
131 if ( str::compareCI( sev, "important" ) == 0 )
132 return SEV_IMPORTANT;
137 if ( str::compareCI( sev, "critical" ) == 0 )
149 std::string asString( const Patch::SeverityFlag & obj )
153 case Patch::SEV_NONE: return std::string( "unspecified" ); break;
154 case Patch::SEV_OTHER: return std::string( "unknown" ); break;
155 case Patch::SEV_LOW: return std::string( "low" ); break;
156 case Patch::SEV_MODERATE: return std::string( "moderate" ); break;
157 case Patch::SEV_IMPORTANT:return std::string( "important" ); break;
158 case Patch::SEV_CRITICAL: return std::string( "critical" ); break;
161 return std::string( "unknown" );
164 std::string Patch::message( const Locale & lang_r ) const
165 { return lookupStrAttribute( sat::SolvAttr::message, lang_r ); }
167 std::string Patch::category() const
168 { return lookupStrAttribute( sat::SolvAttr::patchcategory ); }
170 bool Patch::rebootSuggested() const
171 { return lookupBoolAttribute( sat::SolvAttr::rebootSuggested ); }
173 bool Patch::restartSuggested() const
174 { return lookupBoolAttribute( sat::SolvAttr::restartSuggested ); }
176 bool Patch::reloginSuggested() const
177 { return lookupBoolAttribute( sat::SolvAttr::reloginSuggested ); }
179 Patch::InteractiveFlags Patch::interactiveFlags() const
181 InteractiveFlags patchFlags (NoFlags);
182 if ( rebootSuggested() )
183 patchFlags |= Reboot;
185 if ( ! message().empty() )
186 patchFlags |= Message;
188 if ( ! licenseToConfirm().empty() )
189 patchFlags |= License;
191 Patch::Contents c( contents() );
192 for_( it, c.begin(), c.end() )
194 if ( ! makeResObject(*it)->licenseToConfirm().empty() )
196 patchFlags |= License;
203 bool Patch::interactiveWhenIgnoring( InteractiveFlags flags_r ) const
205 if ( interactiveFlags() & ( ~flags_r ) )
215 bool Patch::interactive() const
217 return interactiveWhenIgnoring();
220 Patch::Contents Patch::contents() const
223 // DBG << *this << endl;
224 sat::LookupAttr updateCollection( sat::SolvAttr::updateCollection, satSolvable() );
225 for_( entry, updateCollection.begin(), updateCollection.end() )
227 IdString name ( entry.subFind( sat::SolvAttr::updateCollectionName ).idStr() );
228 Edition edition ( entry.subFind( sat::SolvAttr::updateCollectionEvr ).idStr() );
229 Arch arch ( entry.subFind( sat::SolvAttr::updateCollectionArch ).idStr() );
232 WAR << "Ignore malformed updateCollection entry: " << name << "-" << edition << "." << arch << endl;
236 // The entry is relevant if there is an installed
237 // package with the same name and arch.
238 bool relevant = false;
239 sat::WhatProvides providers( (Capability( name.id() )) );
240 for_( it, providers.begin(), providers.end() )
242 if ( it->isSystem() && it->ident() == name && it->arch() == arch )
250 // DBG << "Not relevant: " << name << "-" << edition << "." << arch << endl;
254 /* find exact providers first (this matches the _real_ 'collection content' of the patch */
255 providers = sat::WhatProvides( Capability( arch, name.c_str(), Rel::EQ, edition, ResKind::package ) );
256 if ( providers.empty() )
258 /* no exact providers: find 'best' providers: those with a larger evr */
259 providers = sat::WhatProvides( Capability( arch, name.c_str(), Rel::GT, edition, ResKind::package ) );
260 if ( providers.empty() )
262 // Hmm, this patch is not installable, no one is providing the package in the collection
263 // FIXME: raise execption ? fake a solvable ?
264 WAR << "Missing provider: " << name << "-" << edition << "." << arch << endl;
269 // FIXME ?! loop over providers and try to find installed ones ?
270 // DBG << "Found " << name << "-" << edition << "." << arch << ": " << *(providers.begin()) << endl;
271 result.get().insert( *(providers.begin()) );
277 ///////////////////////////////////////////////////////////////////
279 // CLASS NAME : Patch::ReferenceIterator
281 ///////////////////////////////////////////////////////////////////
283 Patch::ReferenceIterator::ReferenceIterator( const sat::Solvable & val_r )
284 { base_reference() = sat::LookupAttr( sat::SolvAttr::updateReference, val_r ).begin(); }
286 std::string Patch::ReferenceIterator::id() const
287 { return base_reference().subFind( sat::SolvAttr::updateReferenceId ).asString(); }
288 std::string Patch::ReferenceIterator::href() const
289 { return base_reference().subFind( sat::SolvAttr::updateReferenceHref ).asString(); }
290 std::string Patch::ReferenceIterator::title() const
291 { return base_reference().subFind( sat::SolvAttr::updateReferenceTitle ).asString(); }
292 std::string Patch::ReferenceIterator::type() const
293 { return base_reference().subFind( sat::SolvAttr::updateReferenceType ).asString(); }
295 /////////////////////////////////////////////////////////////////
297 ///////////////////////////////////////////////////////////////////