1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/Source.h
18 #include "zypp/base/PtrTypes.h"
19 #include "zypp/base/SafeBool.h"
21 #include "zypp/Package.h"
22 #include "zypp/Pathname.h"
24 #include "zypp/Resolvable.h"
26 #include "zypp/media/MediaManager.h"
28 ///////////////////////////////////////////////////////////////////
30 { /////////////////////////////////////////////////////////////////
34 DEFINE_PTR_TYPE(SourceImpl);
36 ///////////////////////////////////////////////////////////////////
38 // CLASS NAME : SkipRequestedException
41 * A specialized exception to inform the caller that user
42 * specifically asked the file/directory providing to be skipped.
44 class SkipRequestedException : public Exception {
46 SkipRequestedException ( const std::string & msg_r ) : Exception( msg_r ) {}
49 ///////////////////////////////////////////////////////////////////
51 // CLASS NAME : SourceUserRejectedException
54 * A specialized exception to inform the caller that user
55 * specifically rejected the source
57 class SourceUserRejectedException : public Exception
60 SourceUserRejectedException ( const std::string & msg_r ) : Exception( msg_r ) {}
64 * A specialized exception to inform the caller that the metadata is invalid
66 class SourceMetadataException : public Exception
69 SourceMetadataException ( const std::string & msg_r ) : Exception( msg_r ) {}
73 * A specialized exception to inform the caller that there is an IO error
75 class SourceIOException : public Exception
78 SourceIOException ( const std::string & msg_r ) : Exception( msg_r ) {}
82 * A specialized exception to inform the caller that the source URL does not exist
84 class SourceNotFoundException : public Exception
87 SourceNotFoundException ( const std::string & msg_r ) : Exception( msg_r ) {}
91 * A specialized exception to inform the caller that the source is not known
93 class SourceUnknownTypeException : public Exception
96 SourceUnknownTypeException ( const std::string & msg_r ) : Exception( msg_r ) {}
101 ///////////////////////////////////////////////////////////////////
103 // CLASS NAME : Source
106 * \note Source is a reference to the implementation. No COW
109 class Source_Ref : protected base::SafeBool<Source_Ref> /* private, but gcc refuses */
111 friend std::ostream & operator<<( std::ostream & str, const Source_Ref & obj );
112 friend bool operator==( const Source_Ref & lhs, const Source_Ref & rhs );
113 friend bool operator<( const Source_Ref & lhs, const Source_Ref & rhs );
116 typedef source::SourceImpl Impl;
117 typedef source::SourceImpl_Ptr Impl_Ptr;
121 /** Default ctor: noSource.
122 * Real Sources are to be created via SourceFactory.
126 /** A dummy Source (Id \c 0) providing nothing, doing nothing.
127 * \todo provide a _constRef
129 static const Source_Ref noSource;
131 /** Validate Source_Ref in a boolean context.
132 * \c FALSE iff == noSource.
134 using base::SafeBool<Source_Ref>::operator bool_type;
137 typedef unsigned long NumericId;
139 /** Runtime unique numeric Source Id. */
140 NumericId numericId() const;
145 * an aproxmate checksum that should change
146 * when the source changes
147 * can be used to determine if
148 * the source needs to be read again or not.
149 * (read as parse its metadata, not about downloading)
151 std::string checksum() const;
154 * aproximate age of the source, can be used to determine if
155 * the source needs to be read again or not.
156 * (read as parse its metadata, not about downloading)
158 Date timestamp() const;
161 * wether this source provides or supports resolvables
164 bool hasResolvablesOfKind( const zypp::Resolvable::Kind &kind ) const;
167 * set of resolvable types the source can offer at this moment
169 std::set<zypp::Resolvable::Kind> resolvableKinds() const;
171 /** Whether the ResStore is initialized.
172 * If we know that noone has seen the resolvables yet, we can skip
173 * them too, eg. when deleting a source. (#174840)
175 bool resStoreInitialized() const;
177 /** All resolvables provided by this source. */
178 const ResStore & resolvables() const;
180 /** All resolvables of a given kind provided by this source. */
181 const ResStore resolvables(zypp::Resolvable::Kind kind) const;
183 const Pathname providePackage( Package::constPtr package );
185 /** Provide a file to local filesystem */
186 const Pathname provideFile(const Pathname & file_r, const unsigned media_nr = 1);
187 const Pathname provideDirTree(const Pathname & dir_r, const unsigned media_nr = 1);
189 const void releaseFile(const Pathname & file_r, const unsigned media_nr = 1);
190 const void releaseDir(const Pathname & dir_r, const unsigned media_nr = 1, bool recursive = false);
192 bool enabled() const;
198 bool autorefresh() const;
199 void setAutorefresh( bool enable_r );
202 void storeMetadata(const Pathname & cache_dir_r);
205 * User chosen identificaton, must be unique
207 std::string alias (void) const;
209 * User chosen identificaton, must be unique
211 void setAlias (const std::string & alias_r);
214 * Source type, like YaST or YUM
216 std::string type (void) const;
218 unsigned numberOfMedia(void) const;
220 //! from media.1/media
221 std::string vendor (void) const;
222 //! from media.1/media
223 std::string unique_id (void) const;
225 //! @name generic information get/set
227 //! runtime-unique, not persistent, a "handle" for Pkg::, string?!
228 std::string id (void) const;
229 void setId (const std::string id_r);
230 unsigned priority (void) const;
231 void setPriority (unsigned p);
232 unsigned priorityUnsubscribed (void) const;
233 void setPriorityUnsubscribed (unsigned p);
234 bool subscribed (void) const;
235 void setSubscribed (bool s);
236 const Pathname & cacheDir (void) const;
237 const std::list<Pathname> publicKeys();
242 std::string zmdName (void) const;
243 void setZmdName (const std::string name_r);
244 std::string zmdDescription (void) const;
245 void setZmdDescription (const std::string desc_r);
250 Url url (void) const;
252 * required for the parse-metadata helper of libzypp-zmd-backend
253 * which gets local files to parse but the source is really remote.
255 void setUrl( const Url & url );
257 const Pathname & path (void) const;
258 bool baseSource() const;
263 * Change the media of the source (in case original media is not available)
264 * The media must be ready-to-use (in the same form as when passing to SourceImpl constructor)
266 void changeMedia(const media::MediaId & media_r, const Pathname & path_r);
269 * Redirect the given media to the given URL instead of the standard one.
271 void redirect(unsigned media_nr, const Url & new_url);
274 * Release all medias attached by the source
279 * Reattach the source if it is not mounted, but downloaded,
280 * to different directory
284 void reattach(const Pathname &attach_point);
287 * Provide a media verifier suitable for the given media number
289 media::MediaVerifierRef verifier(unsigned media_nr);
292 friend base::SafeBool<Source_Ref>::operator bool_type() const;
293 /** \ref SafeBool test. */
294 bool boolTest() const
295 { return _pimpl != noSource._pimpl; }
299 friend class SourceFactory;
300 friend class source::SourceImpl;
305 Source_Ref( const Impl_Ptr & impl_r );
308 /** Pointer to implementation */
311 ///////////////////////////////////////////////////////////////////
313 /** \relates Source Stream output. */
314 std::ostream & operator<<( std::ostream & str, const Source_Ref & obj );
316 /** \relates Source_Ref Equal if same implementation class. */
317 inline bool operator==( const Source_Ref & lhs, const Source_Ref & rhs )
318 { return lhs._pimpl == rhs._pimpl; }
320 /** \relates Source_Ref */
321 inline bool operator!=( const Source_Ref & lhs, const Source_Ref & rhs )
322 { return ! (lhs == rhs); }
324 /** \relates Source_Ref Order in std::conainer based on _pimpl. */
325 inline bool operator<( const Source_Ref & lhs, const Source_Ref & rhs )
326 { return lhs._pimpl < rhs._pimpl; }
328 /////////////////////////////////////////////////////////////////
330 ///////////////////////////////////////////////////////////////////
331 #endif // ZYPP_SOURCE_H