libzypp 8.13.6
|
00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00012 #include <iostream> 00013 00014 #include "zypp/base/LogTools.h" 00015 #include "zypp/Patch.h" 00016 #include "zypp/sat/WhatProvides.h" 00017 00018 using std::endl; 00019 00021 namespace zypp 00022 { 00023 00024 IMPL_PTR_TYPE( Patch ); 00025 00027 // 00028 // METHOD NAME : Patch::Patch 00029 // METHOD TYPE : Ctor 00030 // 00031 Patch::Patch( const sat::Solvable & solvable_r ) 00032 : ResObject( solvable_r ) 00033 {} 00034 00036 // 00037 // METHOD NAME : Patch::~Patch 00038 // METHOD TYPE : Dtor 00039 // 00040 Patch::~Patch() 00041 {} 00042 00044 // 00045 // Patch interface forwarded to implementation 00046 // 00048 00049 Patch::Category Patch::categoryEnum() const 00050 { 00051 static const IdString cat_yast ( "yast" ); 00052 static const IdString cat_security ( "security" ); 00053 static const IdString cat_recommended ( "recommended" ); 00054 static const IdString cat_bugfix ( "bugfix" ); // rhn 00055 static const IdString cat_optional ( "optional" ); 00056 static const IdString cat_feature ( "feature" ); 00057 static const IdString cat_enhancement ( "enhancement" ); // rnh 00058 static const IdString cat_document ( "document" ); 00059 00060 // patch category is not poolized in the solv file (i.e. an IdString) ;( 00061 IdString cat( sat::LookupAttr( sat::SolvAttr::patchcategory, satSolvable() ).begin().c_str() ); 00062 00063 if ( cat == cat_yast ) 00064 return CAT_YAST; 00065 if ( cat == cat_security ) 00066 return CAT_SECURITY; 00067 if ( cat == cat_recommended || cat == cat_bugfix ) 00068 return CAT_RECOMMENDED; 00069 if ( cat == cat_optional || cat == cat_enhancement || cat == cat_feature ) 00070 return CAT_OPTIONAL; 00071 if ( cat == cat_document ) 00072 return CAT_DOCUMENT; 00073 00074 return CAT_OTHER; 00075 } 00076 00077 std::string Patch::message( const Locale & lang_r ) const 00078 { return lookupStrAttribute( sat::SolvAttr::message, lang_r ); } 00079 00080 std::string Patch::category() const 00081 { return lookupStrAttribute( sat::SolvAttr::patchcategory ); } 00082 00083 bool Patch::rebootSuggested() const 00084 { return lookupBoolAttribute( sat::SolvAttr::rebootSuggested ); } 00085 00086 bool Patch::restartSuggested() const 00087 { return lookupBoolAttribute( sat::SolvAttr::restartSuggested ); } 00088 00089 bool Patch::reloginSuggested() const 00090 { return lookupBoolAttribute( sat::SolvAttr::reloginSuggested ); } 00091 00092 00093 bool Patch::interactive() const 00094 { 00095 if ( rebootSuggested() 00096 || ! message().empty() 00097 || ! licenseToConfirm().empty() ) 00098 { 00099 return true; 00100 } 00101 00102 Patch::Contents c( contents() ); 00103 for_( it, c.begin(), c.end() ) 00104 { 00105 if ( ! makeResObject(*it)->licenseToConfirm().empty() ) 00106 { 00107 return true; 00108 } 00109 } 00110 00111 return false; 00112 } 00113 00114 Patch::Contents Patch::contents() const 00115 { 00116 Contents result; 00117 // DBG << *this << endl; 00118 sat::LookupAttr updateCollection( sat::SolvAttr::updateCollection, satSolvable() ); 00119 for_( entry, updateCollection.begin(), updateCollection.end() ) 00120 { 00121 IdString name ( entry.subFind( sat::SolvAttr::updateCollectionName ).idStr() ); 00122 Edition edition ( entry.subFind( sat::SolvAttr::updateCollectionEvr ).idStr() ); 00123 Arch arch ( entry.subFind( sat::SolvAttr::updateCollectionArch ).idStr() ); 00124 if ( name.empty() ) 00125 { 00126 WAR << "Ignore malformed updateCollection entry: " << name << "-" << edition << "." << arch << endl; 00127 continue; 00128 } 00129 00130 // The entry is relevant if there is an installed 00131 // package with the same name and arch. 00132 bool relevant = false; 00133 sat::WhatProvides providers( (Capability( name.id() )) ); 00134 for_( it, providers.begin(), providers.end() ) 00135 { 00136 if ( it->isSystem() && it->ident() == name && it->arch() == arch ) 00137 { 00138 relevant = true; 00139 break; 00140 } 00141 } 00142 if ( ! relevant ) 00143 { 00144 // DBG << "Not relevant: " << name << "-" << edition << "." << arch << endl; 00145 continue; 00146 } 00147 00148 #warning definition of patch contents is poor - needs review 00149 /* find exact providers first (this matches the _real_ 'collection content' of the patch */ 00150 providers = sat::WhatProvides( Capability( arch, name.c_str(), Rel::EQ, edition, ResKind::package ) ); 00151 if ( providers.empty() ) 00152 { 00153 /* no exact providers: find 'best' providers: those with a larger evr */ 00154 providers = sat::WhatProvides( Capability( arch, name.c_str(), Rel::GT, edition, ResKind::package ) ); 00155 if ( providers.empty() ) 00156 { 00157 // Hmm, this patch is not installable, no one is providing the package in the collection 00158 // FIXME: raise execption ? fake a solvable ? 00159 WAR << "Missing provider: " << name << "-" << edition << "." << arch << endl; 00160 continue; 00161 } 00162 } 00163 00164 // FIXME ?! loop over providers and try to find installed ones ? 00165 // DBG << "Found " << name << "-" << edition << "." << arch << ": " << *(providers.begin()) << endl; 00166 result.get().insert( *(providers.begin()) ); 00167 } 00168 00169 return result; 00170 } 00171 00173 // 00174 // CLASS NAME : Patch::ReferenceIterator 00175 // 00177 00178 Patch::ReferenceIterator::ReferenceIterator( const sat::Solvable & val_r ) 00179 { base_reference() = sat::LookupAttr( sat::SolvAttr::updateReference, val_r ).begin(); } 00180 00181 std::string Patch::ReferenceIterator::id() const 00182 { return base_reference().subFind( sat::SolvAttr::updateReferenceId ).asString(); } 00183 std::string Patch::ReferenceIterator::href() const 00184 { return base_reference().subFind( sat::SolvAttr::updateReferenceHref ).asString(); } 00185 std::string Patch::ReferenceIterator::title() const 00186 { return base_reference().subFind( sat::SolvAttr::updateReferenceTitle ).asString(); } 00187 std::string Patch::ReferenceIterator::type() const 00188 { return base_reference().subFind( sat::SolvAttr::updateReferenceType ).asString(); } 00189 00191 } // namespace zypp