1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/Patch.cc
14 #include "zypp/base/LogTools.h"
15 #include "zypp/Patch.h"
16 #include "zypp/sat/WhatProvides.h"
20 ///////////////////////////////////////////////////////////////////
22 { /////////////////////////////////////////////////////////////////
24 IMPL_PTR_TYPE( Patch );
26 ///////////////////////////////////////////////////////////////////
28 // METHOD NAME : Patch::Patch
31 Patch::Patch( const sat::Solvable & solvable_r )
32 : ResObject( solvable_r )
35 ///////////////////////////////////////////////////////////////////
37 // METHOD NAME : Patch::~Patch
43 ///////////////////////////////////////////////////////////////////
45 // Patch interface forwarded to implementation
47 ///////////////////////////////////////////////////////////////////
49 Patch::Category Patch::categoryEnum() const
51 static const IdString cat_yast ( "yast" );
52 static const IdString cat_security ( "security" );
53 static const IdString cat_recommended ( "recommended" );
54 static const IdString cat_bugfix ( "bugfix" ); // rhn
55 static const IdString cat_optional ( "optional" );
56 static const IdString cat_feature ( "feature" );
57 static const IdString cat_enhancement ( "enhancement" ); // rnh
58 static const IdString cat_document ( "document" );
60 // patch category is not poolized in the solv file (i.e. an IdString) ;(
61 IdString cat( sat::LookupAttr( sat::SolvAttr::patchcategory, satSolvable() ).begin().c_str() );
63 if ( cat == cat_yast )
65 if ( cat == cat_security )
67 if ( cat == cat_recommended || cat == cat_bugfix )
68 return CAT_RECOMMENDED;
69 if ( cat == cat_optional || cat == cat_enhancement || cat == cat_feature )
71 if ( cat == cat_document )
77 std::string Patch::message( const Locale & lang_r ) const
78 { return lookupStrAttribute( sat::SolvAttr::message, lang_r ); }
80 std::string Patch::category() const
81 { return lookupStrAttribute( sat::SolvAttr::patchcategory ); }
83 bool Patch::rebootSuggested() const
84 { return lookupBoolAttribute( sat::SolvAttr::rebootSuggested ); }
86 bool Patch::restartSuggested() const
87 { return lookupBoolAttribute( sat::SolvAttr::restartSuggested ); }
89 bool Patch::reloginSuggested() const
90 { return lookupBoolAttribute( sat::SolvAttr::reloginSuggested ); }
93 bool Patch::interactive( bool ignoreRebootFlag_r ) const
95 if ( ( ! ignoreRebootFlag_r && rebootSuggested() )
96 || ! message().empty()
97 || ! licenseToConfirm().empty() )
102 Patch::Contents c( contents() );
103 for_( it, c.begin(), c.end() )
105 if ( ! makeResObject(*it)->licenseToConfirm().empty() )
114 Patch::Contents Patch::contents() const
117 // DBG << *this << endl;
118 sat::LookupAttr updateCollection( sat::SolvAttr::updateCollection, satSolvable() );
119 for_( entry, updateCollection.begin(), updateCollection.end() )
121 IdString name ( entry.subFind( sat::SolvAttr::updateCollectionName ).idStr() );
122 Edition edition ( entry.subFind( sat::SolvAttr::updateCollectionEvr ).idStr() );
123 Arch arch ( entry.subFind( sat::SolvAttr::updateCollectionArch ).idStr() );
126 WAR << "Ignore malformed updateCollection entry: " << name << "-" << edition << "." << arch << endl;
130 // The entry is relevant if there is an installed
131 // package with the same name and arch.
132 bool relevant = false;
133 sat::WhatProvides providers( (Capability( name.id() )) );
134 for_( it, providers.begin(), providers.end() )
136 if ( it->isSystem() && it->ident() == name && it->arch() == arch )
144 // DBG << "Not relevant: " << name << "-" << edition << "." << arch << endl;
148 #warning definition of patch contents is poor - needs review
149 /* find exact providers first (this matches the _real_ 'collection content' of the patch */
150 providers = sat::WhatProvides( Capability( arch, name.c_str(), Rel::EQ, edition, ResKind::package ) );
151 if ( providers.empty() )
153 /* no exact providers: find 'best' providers: those with a larger evr */
154 providers = sat::WhatProvides( Capability( arch, name.c_str(), Rel::GT, edition, ResKind::package ) );
155 if ( providers.empty() )
157 // Hmm, this patch is not installable, no one is providing the package in the collection
158 // FIXME: raise execption ? fake a solvable ?
159 WAR << "Missing provider: " << name << "-" << edition << "." << arch << endl;
164 // FIXME ?! loop over providers and try to find installed ones ?
165 // DBG << "Found " << name << "-" << edition << "." << arch << ": " << *(providers.begin()) << endl;
166 result.get().insert( *(providers.begin()) );
172 ///////////////////////////////////////////////////////////////////
174 // CLASS NAME : Patch::ReferenceIterator
176 ///////////////////////////////////////////////////////////////////
178 Patch::ReferenceIterator::ReferenceIterator( const sat::Solvable & val_r )
179 { base_reference() = sat::LookupAttr( sat::SolvAttr::updateReference, val_r ).begin(); }
181 std::string Patch::ReferenceIterator::id() const
182 { return base_reference().subFind( sat::SolvAttr::updateReferenceId ).asString(); }
183 std::string Patch::ReferenceIterator::href() const
184 { return base_reference().subFind( sat::SolvAttr::updateReferenceHref ).asString(); }
185 std::string Patch::ReferenceIterator::title() const
186 { return base_reference().subFind( sat::SolvAttr::updateReferenceTitle ).asString(); }
187 std::string Patch::ReferenceIterator::type() const
188 { return base_reference().subFind( sat::SolvAttr::updateReferenceType ).asString(); }
190 /////////////////////////////////////////////////////////////////
192 ///////////////////////////////////////////////////////////////////