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_optional( "optional" );
55 static const IdString cat_document( "document" );
57 // patch category is not poolized in the solv file (i.e. an IdString) ;(
58 IdString cat( sat::LookupAttr( sat::SolvAttr::patchcategory, satSolvable() ).begin().c_str() );
60 if ( cat == cat_yast )
62 if ( cat == cat_security )
64 if ( cat == cat_recommended )
65 return CAT_RECOMMENDED;
66 if ( cat == cat_optional )
68 if ( cat == cat_document )
74 std::string Patch::message( const Locale & lang_r ) const
75 { return lookupStrAttribute( sat::SolvAttr::message, lang_r ); }
77 std::string Patch::category() const
78 { return lookupStrAttribute( sat::SolvAttr::patchcategory ); }
80 bool Patch::rebootSuggested() const
81 { return lookupBoolAttribute( sat::SolvAttr::rebootSuggested ); }
83 bool Patch::restartSuggested() const
84 { return lookupBoolAttribute( sat::SolvAttr::restartSuggested ); }
86 bool Patch::reloginSuggested() const
87 { return lookupBoolAttribute( sat::SolvAttr::reloginSuggested ); }
90 bool Patch::interactive() const
92 if ( rebootSuggested()
93 || ! message().empty()
94 || ! licenseToConfirm().empty() )
99 Patch::Contents c( contents() );
100 for_( it, c.begin(), c.end() )
102 if ( ! licenseToConfirm().empty() )
111 Patch::Contents Patch::contents() const
114 // DBG << *this << endl;
115 sat::LookupAttr updateCollection( sat::SolvAttr::updateCollection, satSolvable() );
116 for_( entry, updateCollection.begin(), updateCollection.end() )
118 IdString name ( entry.subFind( sat::SolvAttr::updateCollectionName ).idStr() );
119 Edition edition ( entry.subFind( sat::SolvAttr::updateCollectionEvr ).idStr() );
120 Arch arch ( entry.subFind( sat::SolvAttr::updateCollectionArch ).idStr() );
123 WAR << "Ignore malformed updateCollection entry: " << name << "-" << edition << "." << arch << endl;
127 // The entry is relevant if there is an installed
128 // package with the same name and arch.
129 bool relevant = false;
130 sat::WhatProvides providers( (Capability( name.id() )) );
131 for_( it, providers.begin(), providers.end() )
133 if ( it->isSystem() && it->ident() == name && it->arch() == arch )
141 // DBG << "Not relevant: " << name << "-" << edition << "." << arch << endl;
145 #warning definition of patch contents is poor - needs review
146 /* find exact providers first (this matches the _real_ 'collection content' of the patch */
147 providers = sat::WhatProvides( Capability( arch, name.c_str(), Rel::EQ, edition, ResKind::package ) );
148 if ( providers.empty() )
150 /* no exact providers: find 'best' providers: those with a larger evr */
151 providers = sat::WhatProvides( Capability( arch, name.c_str(), Rel::GT, edition, ResKind::package ) );
152 if ( providers.empty() )
154 // Hmm, this patch is not installable, no one is providing the package in the collection
155 // FIXME: raise execption ? fake a solvable ?
156 WAR << "Missing provider: " << name << "-" << edition << "." << arch << endl;
161 // FIXME ?! loop over providers and try to find installed ones ?
162 // DBG << "Found " << name << "-" << edition << "." << arch << ": " << *(providers.begin()) << endl;
163 result.get().insert( *(providers.begin()) );
169 ///////////////////////////////////////////////////////////////////
171 // CLASS NAME : Patch::ReferenceIterator
173 ///////////////////////////////////////////////////////////////////
175 Patch::ReferenceIterator::ReferenceIterator( const sat::Solvable & val_r )
176 { base_reference() = sat::LookupAttr( sat::SolvAttr::updateReference, val_r ).begin(); }
178 std::string Patch::ReferenceIterator::id() const
179 { return base_reference().subFind( sat::SolvAttr::updateReferenceId ).asString(); }
180 std::string Patch::ReferenceIterator::href() const
181 { return base_reference().subFind( sat::SolvAttr::updateReferenceHref ).asString(); }
182 std::string Patch::ReferenceIterator::title() const
183 { return base_reference().subFind( sat::SolvAttr::updateReferenceTitle ).asString(); }
184 std::string Patch::ReferenceIterator::type() const
185 { return base_reference().subFind( sat::SolvAttr::updateReferenceType ).asString(); }
187 /////////////////////////////////////////////////////////////////
189 ///////////////////////////////////////////////////////////////////