1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/Patch.cc
13 #include "zypp/base/Logger.h"
14 #include "zypp/Patch.h"
15 #include "zypp/Message.h"
19 ///////////////////////////////////////////////////////////////////
21 { /////////////////////////////////////////////////////////////////
23 IMPL_PTR_TYPE( Patch );
25 ///////////////////////////////////////////////////////////////////
27 // METHOD NAME : Patch::Patch
30 Patch::Patch( const sat::Solvable & solvable_r )
31 : ResObject( solvable_r )
34 ///////////////////////////////////////////////////////////////////
36 // METHOD NAME : Patch::~Patch
42 ///////////////////////////////////////////////////////////////////
44 // Patch interface forwarded to implementation
46 ///////////////////////////////////////////////////////////////////
48 std::string Patch::category() const
49 { return lookupStrAttribute( sat::SolvAttr::patchcategory ); }
51 bool Patch::reboot_needed() const
52 { return lookupBoolAttribute( sat::SolvAttr::needReboot ); }
54 bool Patch::affects_pkg_manager() const
55 { return lookupBoolAttribute( sat::SolvAttr::needRestart ); }
57 bool Patch::interactive() const
60 || ! licenseToConfirm().empty() )
65 Patch::Contents c( contents() );
66 for_( it, c.begin(), c.end() )
68 if ( it->isKind( ResKind::message )
69 || ! licenseToConfirm().empty() )
79 Patch::Contents Patch::contents() const
82 sat::LookupAttr::iterator _col_name_it(sat::LookupAttr( sat::SolvAttr::updateCollectionName, *this ).begin());
83 sat::LookupAttr::iterator _col_evr_it(sat::LookupAttr( sat::SolvAttr::updateCollectionEvr, *this ).begin());
84 sat::LookupAttr::iterator _col_arch_it(sat::LookupAttr( sat::SolvAttr::updateCollectionArch, *this ).begin());
86 for (;_col_name_it != sat::LookupAttr( sat::SolvAttr::updateCollectionName, *this ).end(); ++_col_name_it, ++_col_evr_it, ++_col_arch_it)
88 /* safety checks, shouldn't happen (tm) */
89 if (_col_evr_it == sat::LookupAttr( sat::SolvAttr::updateCollectionEvr, *this ).end()
90 || _col_arch_it == sat::LookupAttr( sat::SolvAttr::updateCollectionArch, *this ).end())
92 /* FIXME: Raise exception ?! */
93 ERR << *this << " : The thing that should not happen, happened." << endl;
97 IdString nameid( _col_name_it.asString() ); /* IdString for fast compare */
98 Arch arch( _col_arch_it.asString() );
100 /* search providers of name */
101 sat::WhatProvides providers( Capability( _col_name_it.asString() ) );
102 MIL << *this << " providers: " << endl;
103 MIL << providers << endl;
105 if (providers.empty())
107 WAR << *this << " misses provider for '" << _col_name_it.asString() << "'" << endl;
111 bool is_relevant = false;
112 for_( it, providers.begin(), providers.end() )
114 if (it->ident() != nameid) /* package _name_ must match */
117 if (it->isSystem() /* only look at installed providers with same arch */
118 && it->arch() == arch)
125 MIL << *this << " is not relevant to the system" << endl;
127 continue; /* skip if name.arch is not installed */
131 /* find exact providers first (this matches the _real_ 'collection content' of the patch */
132 sat::WhatProvides exact_providers( Capability( _col_name_it.asString(), Rel::EQ, _col_evr_it.asString(), ResKind::package ) );
133 if (exact_providers.empty())
135 /* no exact providers: find 'best' providers */
136 sat::WhatProvides best_providers( Capability( _col_name_it.asString(), Rel::GT, _col_evr_it.asString(), ResKind::package ) );
137 if (best_providers.empty())
139 // Hmm, this patch is not installable, noone is providing the package in the collection
140 // raise execption ? fake a solvable ?
144 // FIXME ?! loop over providers and try to find installed ones ?
145 result.get().insert( *(best_providers.begin()) );
150 // FIXME ?! loop over providers and try to find installed ones ?
151 result.get().insert( *(exact_providers.begin()) );
153 } /* while (attribute array) */
159 ///////////////////////////////////////////////////////////////////
161 // CLASS NAME : Patch::ReferenceIterator
163 ///////////////////////////////////////////////////////////////////
165 Patch::ReferenceIterator::ReferenceIterator( const sat::Solvable & val_r )
167 base_reference() = sat::LookupAttr( sat::SolvAttr::updateReferenceId,
169 _hrefit = sat::LookupAttr( sat::SolvAttr::updateReferenceHref,
171 _titleit = sat::LookupAttr( sat::SolvAttr::updateReferenceTitle,
173 _typeit = sat::LookupAttr( sat::SolvAttr::updateReferenceType,
178 std::string Patch::ReferenceIterator::id() const
179 { return base_reference().asString(); }
180 std::string Patch::ReferenceIterator::href() const
181 { return _hrefit.asString(); }
182 std::string Patch::ReferenceIterator::title() const
183 { return _titleit.asString(); }
184 std::string Patch::ReferenceIterator::type() const
185 { return _typeit.asString(); }
188 void Patch::ReferenceIterator::increment()
196 /////////////////////////////////////////////////////////////////
198 ///////////////////////////////////////////////////////////////////