1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/RepoManager.h
12 #ifndef ZYPP_REPOMANAGER_H
13 #define ZYPP_REPOMANAGER_H
18 #include "zypp/base/PtrTypes.h"
19 //#include "zypp/base/ReferenceCounted.h"
20 //#include "zypp/base/NonCopyable.h"
21 #include "zypp/Pathname.h"
22 #include "zypp/ZConfig.h"
23 #include "zypp/Repository.h"
24 #include "zypp/RepoInfo.h"
25 #include "zypp/repo/RepoException.h"
26 #include "zypp/repo/RepoType.h"
27 #include "zypp/RepoStatus.h"
28 #include "zypp/ProgressData.h"
30 ///////////////////////////////////////////////////////////////////
32 { /////////////////////////////////////////////////////////////////
35 * Parses \a repo_file and returns a list of \ref RepoInfo objects
36 * corresponding to repositories found within the file.
38 * \param repo_file Valid URL of the repo file.
39 * \return found list<RepoInfo>
41 * \throws MediaException If the access to the url fails
42 * \throws ParseException If the file parsing fails
43 * \throws Exception On other errors.
45 std::list<RepoInfo> readRepoFile(const Url & repo_file);
48 * Repo manager settings.
49 * Settings default to ZYpp global settings.
51 struct RepoManagerOptions
55 Pathname repoCachePath;
56 Pathname repoRawCachePath;
57 Pathname knownReposPath;
61 * \short creates and provides information about known sources.
66 friend std::ostream & operator<<( std::ostream & str, const RepoManager & obj );
73 RepoManager( const RepoManagerOptions &options = RepoManagerOptions() );
77 enum RawMetadataRefreshPolicy
95 * \short List known repositories.
97 * The known repositories are read from
98 * \ref RepoManagerOptions::knownReposPath passed on the Ctor.
99 * Which defaults to ZYpp global settings.
100 * \return found list<RepoInfo>
102 std::list<RepoInfo> knownRepositories() const;
105 * \short Status of local metadata
107 RepoStatus metadataStatus( const RepoInfo &info ) const;
110 * \short Refresh local raw cache
112 * Will try to download the metadata
114 * In case of falure the metadata remains
117 * \throws repo::RepoNoUrlException if no urls are available.
118 * \throws repo::RepoNoAliasException if can't figure an alias
119 * \throws repo::RepoUnknownTypeException if the metadata is unknown
120 * \throws repo::RepoException if the repository is invalid
121 * (no valid metadata found at any of baseurls)
122 * \throws Exception on unknown error.
124 void refreshMetadata( const RepoInfo &info,
125 RawMetadataRefreshPolicy policy = RefreshIfNeeded,
126 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
129 * \short Clean local metadata
131 * Empty local metadata.
133 * \throws repo::RepoNoAliasException if can't figure an alias
134 * \throws Exception on unknown error.
136 void cleanMetadata( const RepoInfo &info,
137 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
140 * \short Status of metadata cache
142 RepoStatus cacheStatus( const RepoInfo &info ) const;
145 * \short Refresh local cache
147 * Will try to build the cache from
150 * If the cache exists it will be overwriten.
152 * \note the local metadata must be valid.
154 * \throws repo::RepoNoAliasException if can't figure
155 * an alias to look in cache
157 * \throws repo::RepoMetadataException if the metadata
158 * is not enough to build a cache (empty, incorrect, or
160 * \throws Exception on unknown error.
162 void buildCache( const RepoInfo &info,
163 CacheBuildPolicy policy = BuildIfNeeded,
164 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
167 * \short clean local cache
169 * Clean the cached version of the metadata
171 * \note the local metadata must be valid.
173 * \throws repo::RepoNoAliasException if can't figure an alias to look in cache
174 * \throws Exception on unknown error.
176 void cleanCache( const RepoInfo &info,
177 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
180 * \short Whether a repository exists in cache
182 * \param RepoInfo to be checked.
184 bool isCached( const RepoInfo &info ) const;
187 * \short Create a repository object from the cache data
189 * Creating from cache requires that the repository is
190 * refreshed (metadata downloaded) and cached
192 * \throws repo::RepoNoAliasException if can't figure an alias to look in cache
193 * \throw RepoNotCachedException When the source is not cached.
195 Repository createFromCache( const RepoInfo &info,
196 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
199 * \short Create a repository object from raw metadata
201 * Creating from cache requires that the repository is
202 * refreshed (metadata downloaded)
204 * \throw Exception If there are errors parsing the
207 Repository createFromMetadata( const RepoInfo &info,
208 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
211 * \short Probe repo metadata type.
213 * \todo FIXME Should this be private?
215 repo::RepoType probe( const Url &url ) const;
219 * \short Adds a repository to the list of known repositories.
223 * \throws repo::RepoAlreadyExistsException If the repo clash some
224 * unique attribute like alias
225 * \throws MediaException If the access to the url fails
226 * \throws ParseException If the file parsing fails
227 * \throws RepoUnknownType If repository type can't be determined
228 * \throws RepoException ON other repository related errors
229 * \throws Exception On other errors.
231 void addRepository( const RepoInfo &info,
232 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
235 * \short Adds repositores from a repo file to the list of known repositories.
236 * \param url Url of the repo file
238 * \throws repo::RepoAlreadyExistsException If the repo clash some
239 * unique attribute like alias
241 * \throws RepoAlreadyExistsException
242 * \throws MediaException If the access to the url fails
243 * \throws ParseException If the file parsing fails
244 * \throws RepoUnknownType If repository type can't be determined
245 * \throws RepoException ON other repository related errors
246 * \throws Exception On other errors.
248 void addRepositories( const Url &url,
249 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
251 * \short Remove the best matching repository from known repos list
253 * \throws RepoNotFoundException If no repo match
255 void removeRepository( const RepoInfo & info,
256 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
259 * \short Modify repository attributes
261 * \throws RepoNotFoundException If no repo match
262 * \throws ParseException If the file parsing fails
263 * \throws Exception On other errors.
265 void modifyRepository( const std::string &alias,
266 const RepoInfo & newinfo,
267 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
270 * \short Find a matching repository info
272 * \note if multiple repositories incorrectly share the
273 * same alias, the first one found will be returned.
275 * \param alias Repository alias
276 * \param progressrcv Progress reporting function
277 * \return RepoInfo of the found repository
278 * \throws RepoNotFoundException If no repo match the alias
279 * \throws ParseException If the file parsing fails
280 * \throws Exception On other errors.
282 RepoInfo getRepositoryInfo( const std::string &alias,
283 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
286 * \short Find repository info by URL.
288 * \param url URL to find.
289 * \param urlview url::ViewOption to influence URL matching.
290 * \param progressrcv Progress receiver function.
291 * \return RepoInfo of the found repository.
293 * \note if multpile repositories incorrectly share the
294 * same URL, the first one found will be returned.
296 * \note the string representation of the URLs are compared.
297 * The \a urlview can be used to influence which
298 parts of the URL are to be compared.
300 * \throws RepoNotFoundException If no repo match
301 * \throws ParseException If the file parsing fails
302 * \throws Exception On other errors.
304 RepoInfo getRepositoryInfo( const Url & url,
305 const url::ViewOption & urlview = url::ViewOption::DEFAULTS,
306 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
309 RepoStatus rawMetadataStatus( const RepoInfo &info );
310 RepoStatus cacheStatus( const RepoInfo &info );
314 /** Pointer to implementation */
315 RWCOW_pointer<Impl> _pimpl;
317 ///////////////////////////////////////////////////////////////////
319 /** \relates RepoManager Stream output */
320 std::ostream & operator<<( std::ostream & str, const RepoManager & obj );
322 /////////////////////////////////////////////////////////////////
324 ///////////////////////////////////////////////////////////////////
325 #endif // ZYPP2_REPOMANAGER_H