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 std::string Patch::category() const
47 { return lookupStrAttribute( sat::SolvAttr::patchcategory ); }
49 Patch::Category Patch::categoryEnum() const
50 { return categoryEnum( category() ); }
52 bool Patch::isCategory( const std::string & category_r ) const
53 { return( str::compareCI( category_r, category() ) == 0 ); }
55 Patch::Category Patch::categoryEnum( const std::string & category_r )
57 switch ( category_r[0] )
62 if ( str::compareCI( category_r, "yast" ) == 0 )
69 if ( str::compareCI( category_r, "security" ) == 0 )
76 if ( str::compareCI( category_r, "recommended" ) == 0 )
77 return CAT_RECOMMENDED;
81 if ( str::compareCI( category_r, "bugfix" ) == 0 ) // rhn
82 return CAT_RECOMMENDED;
88 if ( str::compareCI( category_r, "optional" ) == 0 )
93 if ( str::compareCI( category_r, "feature" ) == 0 )
98 if ( str::compareCI( category_r, "enhancement" ) == 0 ) // rhn
105 if ( str::compareCI( category_r, "document" ) == 0 )
113 ///////////////////////////////////////////////////////////////////
115 std::string Patch::severity() const
116 { return lookupStrAttribute( sat::SolvAttr::severity ); }
118 Patch::SeverityFlag Patch::severityFlag() const
119 { return severityFlag( severity() ); }
121 bool Patch::isSeverity( const std::string & severity_r ) const
122 { return( str::compareCI( severity_r, severity() ) == 0 ); }
124 Patch::SeverityFlag Patch::severityFlag( const std::string & severity_r )
126 switch ( severity_r[0] )
130 if ( str::compareCI( severity_r, "low" ) == 0 )
136 if ( str::compareCI( severity_r, "moderate" ) == 0 )
142 if ( str::compareCI( severity_r, "important" ) == 0 )
143 return SEV_IMPORTANT;
148 if ( str::compareCI( severity_r, "critical" ) == 0 )
154 if ( str::compareCI( severity_r, "unspecified" ) == 0 )
166 std::string asString( const Patch::SeverityFlag & obj )
170 case Patch::SEV_NONE: return std::string( "unspecified" ); break;
171 case Patch::SEV_OTHER: return std::string( "unknown" ); break;
172 case Patch::SEV_LOW: return std::string( "low" ); break;
173 case Patch::SEV_MODERATE: return std::string( "moderate" ); break;
174 case Patch::SEV_IMPORTANT:return std::string( "important" ); break;
175 case Patch::SEV_CRITICAL: return std::string( "critical" ); break;
178 return std::string( "unknown" );
181 ///////////////////////////////////////////////////////////////////
183 std::string Patch::message( const Locale & lang_r ) const
184 { return lookupStrAttribute( sat::SolvAttr::message, lang_r ); }
186 bool Patch::rebootSuggested() const
187 { return lookupBoolAttribute( sat::SolvAttr::rebootSuggested ); }
189 bool Patch::restartSuggested() const
190 { return lookupBoolAttribute( sat::SolvAttr::restartSuggested ); }
192 bool Patch::reloginSuggested() const
193 { return lookupBoolAttribute( sat::SolvAttr::reloginSuggested ); }
195 Patch::InteractiveFlags Patch::interactiveFlags() const
197 InteractiveFlags patchFlags (NoFlags);
198 if ( rebootSuggested() )
199 patchFlags |= Reboot;
201 if ( ! message().empty() )
202 patchFlags |= Message;
204 if ( ! licenseToConfirm().empty() )
205 patchFlags |= License;
207 Patch::Contents c( contents() );
208 for_( it, c.begin(), c.end() )
210 if ( ! makeResObject(*it)->licenseToConfirm().empty() )
212 patchFlags |= License;
219 bool Patch::interactiveWhenIgnoring( InteractiveFlags flags_r ) const
221 if ( interactiveFlags() & ( ~flags_r ) )
231 bool Patch::interactive() const
233 return interactiveWhenIgnoring();
236 Patch::Contents Patch::contents() const
239 // DBG << *this << endl;
240 sat::LookupAttr updateCollection( sat::SolvAttr::updateCollection, satSolvable() );
241 for_( entry, updateCollection.begin(), updateCollection.end() )
243 IdString name ( entry.subFind( sat::SolvAttr::updateCollectionName ).idStr() );
244 Edition edition ( entry.subFind( sat::SolvAttr::updateCollectionEvr ).idStr() );
245 Arch arch ( entry.subFind( sat::SolvAttr::updateCollectionArch ).idStr() );
248 WAR << "Ignore malformed updateCollection entry: " << name << "-" << edition << "." << arch << endl;
252 // The entry is relevant if there is an installed
253 // package with the same name and arch.
254 bool relevant = false;
255 sat::WhatProvides providers( (Capability( name.id() )) );
256 for_( it, providers.begin(), providers.end() )
258 if ( it->isSystem() && it->ident() == name && it->arch() == arch )
266 // DBG << "Not relevant: " << name << "-" << edition << "." << arch << endl;
270 /* find exact providers first (this matches the _real_ 'collection content' of the patch */
271 providers = sat::WhatProvides( Capability( arch, name.c_str(), Rel::EQ, edition, ResKind::package ) );
272 if ( providers.empty() )
274 /* no exact providers: find 'best' providers: those with a larger evr */
275 providers = sat::WhatProvides( Capability( arch, name.c_str(), Rel::GT, edition, ResKind::package ) );
276 if ( providers.empty() )
278 // Hmm, this patch is not installable, no one is providing the package in the collection
279 // FIXME: raise execption ? fake a solvable ?
280 WAR << "Missing provider: " << name << "-" << edition << "." << arch << endl;
285 // FIXME ?! loop over providers and try to find installed ones ?
286 // DBG << "Found " << name << "-" << edition << "." << arch << ": " << *(providers.begin()) << endl;
287 result.get().insert( *(providers.begin()) );
293 ///////////////////////////////////////////////////////////////////
295 // CLASS NAME : Patch::ReferenceIterator
297 ///////////////////////////////////////////////////////////////////
299 Patch::ReferenceIterator::ReferenceIterator( const sat::Solvable & val_r )
300 { base_reference() = sat::LookupAttr( sat::SolvAttr::updateReference, val_r ).begin(); }
302 std::string Patch::ReferenceIterator::id() const
303 { return base_reference().subFind( sat::SolvAttr::updateReferenceId ).asString(); }
304 std::string Patch::ReferenceIterator::href() const
305 { return base_reference().subFind( sat::SolvAttr::updateReferenceHref ).asString(); }
306 std::string Patch::ReferenceIterator::title() const
307 { return base_reference().subFind( sat::SolvAttr::updateReferenceTitle ).asString(); }
308 std::string Patch::ReferenceIterator::type() const
309 { return base_reference().subFind( sat::SolvAttr::updateReferenceType ).asString(); }
311 /////////////////////////////////////////////////////////////////
313 ///////////////////////////////////////////////////////////////////