1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
15 #include <zypp/base/Flags.h>
16 #include <zypp/sat/SolvAttr.h>
17 #include <zypp/ResObject.h>
18 #include <zypp/sat/SolvableSet.h>
20 ///////////////////////////////////////////////////////////////////
22 { /////////////////////////////////////////////////////////////////
25 DEFINE_PTR_TYPE(Patch);
29 * Class representing a patch.
31 * A patch represents a specific problem that
32 * can be fixed by pulling in the patch dependencies.
34 * Patches can be marked for installation but their
35 * installation is a no-op.
37 class Patch : public ResObject
41 typedef ResTraits<Self> TraitsType;
42 typedef TraitsType::PtrType Ptr;
43 typedef TraitsType::constPtrType constPtr;
46 typedef sat::SolvableSet Contents;
49 CAT_OTHER = 1, //!< unknown value specified
51 CAT_SECURITY = 1<<2, //!<
52 CAT_RECOMMENDED = 1<<3, //!<
53 CAT_OPTIONAL = 1<<4, //!<
54 CAT_DOCUMENT = 1<<5 //!<
56 ZYPP_DECLARE_FLAGS(Categories, Category);
59 * Flags defining if and why this
60 * patch is interactive.
62 enum InteractiveFlag {
68 ZYPP_DECLARE_FLAGS(InteractiveFlags, InteractiveFlag);
71 * \brief Possible severity levels for (security) patches.
72 * Metadata string values are mapped to this enum to ease
73 * computations. For a string representation call
74 * \ref asSring( const Patch::SeverityFlag & ).
77 SEV_OTHER = 1, //!< unknown value specified
78 SEV_NONE = 1<<1, //!< no value specified
79 SEV_LOW = 1<<2, //!< Low
80 SEV_MODERATE = 1<<3, //!< Moderate
81 SEV_IMPORTANT = 1<<4, //!< Important
82 SEV_CRITICAL = 1<<5 //!< Critical
84 ZYPP_DECLARE_FLAGS(SeverityFlags, SeverityFlag);
88 * Issue date time. For now it is the same as
91 Date timestamp() const
92 { return buildtime(); }
94 /** \name Patch Category */
97 * Patch category (recommended, security,...)
99 std::string category() const;
101 /** This patch's category as enum of wellknown categories.
102 * Unknown values are mapped to \ref CAT_OTHER.
104 Category categoryEnum() const;
106 /** Whether this patch's category matches \a category_r */
107 bool isCategory( const std::string & category_r ) const;
108 /** \overload taking OR'ed \ref Categories */
109 bool isCategory( Categories category_r ) const;
111 /** \overload taking container of category strings
112 * 2nd template arg just to prevent instantiation for Category
114 template <class TContainer, typename = typename TContainer::value_type>
115 bool isCategory( const TContainer & categories_r ) const
117 for ( const std::string & el : categories_r )
118 { if ( isCategory( el ) ) return true; }
122 /** Patch category as enum of wellknown categories.
123 * Unknown values are mapped to \ref CAT_OTHER.
125 static Category categoryEnum( const std::string & category_r );
128 /** \name Patch Severity */
131 * Severity string as specified in metadata.
132 * For use in computaions see \ref severityFlag.
134 std::string severity() const;
137 * Severity string mapped to an enum.
138 * Unknown string values are mapped to \ref SEV_OTHER
140 SeverityFlag severityFlag() const;
142 /** Whether this patch's severity matches \a severity_r */
143 bool isSeverity( const std::string & severity_r ) const;
144 /** \overload taking OR'ed \ref SeverityFlags */
145 bool isSeverity( SeverityFlags severity_r ) const;
147 /** \overload taking container of severity strings
148 * 2nd template arg just to prevent instantiation for SeverityFlag
150 template <class TContainer, typename = typename TContainer::value_type>
151 bool isSeverity( const TContainer & severities_r ) const
153 for ( const std::string & el : severities_r )
154 { if ( isSeverity( el ) ) return true; }
158 /** Severity string mapped to an enum.
159 * Unknown string values are mapped to \ref SEV_OTHER
161 static SeverityFlag severityFlag( const std::string & category_r );
165 * Does the system need to reboot to finish the update process?
167 bool rebootSuggested() const;
170 * Does the patch affect the package manager itself?
171 * restart is suggested then
173 bool restartSuggested() const;
176 * Does the patch needs the user to relogin to take effect?
177 * relogin is suggested then
179 bool reloginSuggested() const;
182 * \short Information or warning to be displayed to the user
184 std::string message( const Locale & lang_r = Locale() ) const;
187 * Get the InteractiveFlags of this Patch
189 InteractiveFlags interactiveFlags() const;
192 * Is the patch still interactive when ignoring this flags?
194 bool interactiveWhenIgnoring( InteractiveFlags flags_r = NoFlags ) const;
197 * Is the patch installation interactive? (does it need user input?)
199 * For security reasons patches requiring a reboot are not
200 * installed in an unattended mode. They are considered to be
201 * \c interactive so the user gets informed about the need for
202 * reboot. \a ignoreRebootFlag_r may be used to explicitly turn
203 * off this behavior and include those patches (unless they actually
204 * contain interactive components as well, like messages or licenses).
206 bool interactive() const;
210 * The collection of packages associated with this patch.
212 Contents contents() const;
216 /** Query class for Patch issue references */
217 class ReferenceIterator;
219 * Get an iterator to the beginning of the patch
220 * references. \see Patch::ReferenceIterator
222 ReferenceIterator referencesBegin() const;
224 * Get an iterator to the end of the patch
225 * references. \see Patch::ReferenceIterator
227 ReferenceIterator referencesEnd() const;
230 friend Ptr make<Self>( const sat::Solvable & solvable_r );
232 Patch( const sat::Solvable & solvable_r );
236 ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Patch::Categories);
237 ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Patch::InteractiveFlags);
238 ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Patch::SeverityFlags);
240 /** \relates Patch::Category string representation.*/
241 std::string asString( const Patch::Category & obj );
243 /** \relates Patch::InteractiveFlag string representation.*/
244 std::string asString( const Patch::InteractiveFlag & obj );
246 /** \relates Patch::SeverityFlag string representation.*/
247 std::string asString( const Patch::SeverityFlag & obj );
250 * Query class for Patch issue references
251 * like bugzilla and security issues the
252 * patch is supposed to fix.
254 * The iterator does not provide a dereference
255 * operator so you can do * on it, but you can
256 * access the attributes of each patch issue reference
257 * directly from the iterator.
260 * for ( Patch::ReferenceIterator it = patch->referencesBegin();
261 * it != patch->referencesEnd();
264 * cout << it.href() << endl;
269 class Patch::ReferenceIterator : public boost::iterator_adaptor<
270 Patch::ReferenceIterator // Derived
271 , sat::LookupAttr::iterator // Base
273 , boost::forward_traversal_tag // CategoryOrTraversal
278 ReferenceIterator() {}
279 explicit ReferenceIterator( const sat::Solvable & val_r );
282 * The id of the reference. For bugzilla entries
283 * this is the bug number as a string.
285 std::string id() const;
287 * Url or pointer where to find more information
289 std::string href() const;
291 * Title describing the issue
293 std::string title() const;
295 * Type of the reference. For example
298 std::string type() const;
301 friend class boost::iterator_core_access;
302 int dereference() const { return 0; }
305 inline Patch::ReferenceIterator Patch::referencesBegin() const
306 { return ReferenceIterator(satSolvable()); }
308 inline Patch::ReferenceIterator Patch::referencesEnd() const
309 { return ReferenceIterator(); }
311 /////////////////////////////////////////////////////////////////
314 ///////////////////////////////////////////////////////////////////
315 #endif // ZYPP_PATCH_H