1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
15 #include "zypp/base/Flags.h"
16 #include "zypp/sat/SolvAttr.h"
17 #include "zypp/ResObject.h"
19 ///////////////////////////////////////////////////////////////////
21 { /////////////////////////////////////////////////////////////////
24 DEFINE_PTR_TYPE(Patch);
28 * Class representing a patch.
30 * A patch represents a specific problem that
31 * can be fixed by pulling in the patch dependencies.
33 * Patches can be marked for installation but their
34 * installation is a no-op.
36 class Patch : public ResObject
40 typedef ResTraits<Self> TraitsType;
41 typedef TraitsType::PtrType Ptr;
42 typedef TraitsType::constPtrType constPtr;
45 typedef sat::SolvableSet Contents;
57 * Flags defining if and why this
58 * patch is interactive.
60 enum InteractiveFlag {
66 ZYPP_DECLARE_FLAGS(InteractiveFlags, InteractiveFlag);
69 * \brief Possible severity levels for (security) patches.
70 * Metadata string values are mapped to this enum to ease
71 * computations. For a string representation call
72 * \ref asSring( const Patch::SeverityFlag & ).
75 SEV_NONE = 0, //!< no value specified
76 SEV_OTHER = 1, //!< unknown value specified
77 SEV_LOW = 1<<1, //!< Low
78 SEV_MODERATE = 1<<2, //!< Moderate
79 SEV_IMPORTANT = 1<<3, //!< Important
80 SEV_CRITICAL = 1<<4 //!< Critical
82 ZYPP_DECLARE_FLAGS(SeverityFlags, SeverityFlag);
86 * Issue date time. For now it is the same as
89 Date timestamp() const
90 { return buildtime(); }
92 /** \name Patch Category */
95 * Patch category (recommended, security,...)
97 std::string category() const;
99 /** This patch's category as enum of wellknown categories.
100 * Unknown values are mapped to \ref CAT_OTHER.
102 Category categoryEnum() const;
104 /** Whether this patch's category matches \a category_r */
105 bool isCategory( const std::string & category_r ) const;
107 /** Patch category as enum of wellknown categories.
108 * Unknown values are mapped to \ref CAT_OTHER.
110 static Category categoryEnum( const std::string & category_r );
113 /** \name Patch Severity */
116 * Severity string as specified in metadata.
117 * For use in computaions see \ref severityFlag.
119 std::string severity() const;
122 * Severity string mapped to an enum.
123 * Unknown string values are mapped to \ref SEV_OTHER
125 SeverityFlag severityFlag() const;
127 /** Whether this patch's severity matches \a severity_r */
128 bool isSeverity( const std::string & severity_r ) const;
130 /** Severity string mapped to an enum.
131 * Unknown string values are mapped to \ref SEV_OTHER
133 static SeverityFlag severityFlag( const std::string & category_r );
137 * Does the system need to reboot to finish the update process?
139 bool rebootSuggested() const;
142 * Does the patch affect the package manager itself?
143 * restart is suggested then
145 bool restartSuggested() const;
148 * Does the patch needs the user to relogin to take effect?
149 * relogin is suggested then
151 bool reloginSuggested() const;
154 * \short Information or warning to be displayed to the user
156 std::string message( const Locale & lang_r = Locale() ) const;
159 * Get the InteractiveFlags of this Patch
161 InteractiveFlags interactiveFlags() const;
164 * Is the patch still interactive when ignoring this flags?
166 bool interactiveWhenIgnoring( InteractiveFlags flags_r = NoFlags ) const;
169 * Is the patch installation interactive? (does it need user input?)
171 * For security reasons patches requiring a reboot are not
172 * installed in an unattended mode. They are considered to be
173 * \c interactive so the user gets informed about the need for
174 * reboot. \a ignoreRebootFlag_r may be used to explicitly turn
175 * off this behavior and include those patches (unless they actually
176 * contain interactive components as well, like messages or licenses).
178 bool interactive() const;
182 * The collection of packages associated with this patch.
184 Contents contents() const;
188 /** Query class for Patch issue references */
189 class ReferenceIterator;
191 * Get an iterator to the beginning of the patch
192 * references. \see Patch::ReferenceIterator
194 ReferenceIterator referencesBegin() const;
196 * Get an iterator to the end of the patch
197 * references. \see Patch::ReferenceIterator
199 ReferenceIterator referencesEnd() const;
202 friend Ptr make<Self>( const sat::Solvable & solvable_r );
204 Patch( const sat::Solvable & solvable_r );
208 ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Patch::InteractiveFlags);
209 ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Patch::SeverityFlags);
211 /** \relates Patch::SeverityFlag string representation.*/
212 std::string asString( const Patch::SeverityFlag & obj );
215 * Query class for Patch issue references
216 * like bugzilla and security issues the
217 * patch is supposed to fix.
219 * The iterator does not provide a dereference
220 * operator so you can do * on it, but you can
221 * access the attributes of each patch issue reference
222 * directly from the iterator.
225 * for ( Patch::ReferenceIterator it = patch->referencesBegin();
226 * it != patch->referencesEnd();
229 * cout << it.href() << endl;
234 class Patch::ReferenceIterator : public boost::iterator_adaptor<
235 Patch::ReferenceIterator // Derived
236 , sat::LookupAttr::iterator // Base
238 , boost::forward_traversal_tag // CategoryOrTraversal
243 ReferenceIterator() {}
244 explicit ReferenceIterator( const sat::Solvable & val_r );
247 * The id of the reference. For bugzilla entries
248 * this is the bug number as a string.
250 std::string id() const;
252 * Url or pointer where to find more information
254 std::string href() const;
256 * Title describing the issue
258 std::string title() const;
260 * Type of the reference. For example
263 std::string type() const;
266 friend class boost::iterator_core_access;
267 int dereference() const { return 0; }
270 inline Patch::ReferenceIterator Patch::referencesBegin() const
271 { return ReferenceIterator(satSolvable()); }
273 inline Patch::ReferenceIterator Patch::referencesEnd() const
274 { return ReferenceIterator(); }
276 /////////////////////////////////////////////////////////////////
279 ///////////////////////////////////////////////////////////////////
280 #endif // ZYPP_PATCH_H