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 * Checks whether to refresh metadata for specified repository and url.
112 * The need for refresh is evaluated according to the following conditions,
115 * <li>the refresh policy (refresh may be forced)
116 * <li>the repo.refresh.delay ZConfig value compared to the difference between
117 * cached index file timestamp and actual time
118 * <li>the timestamp of cached repo index file compared to the remote
119 * index file timestamp.
122 * This method checks the status against the specified url only. If more
123 * baseurls are defined for in the RepoInfo, each one must be check
124 * individually. Example:
129 * // try urls one by one
130 * for ( RepoInfo::urls_const_iterator it = info.baseUrlsBegin();
131 * it != info.baseUrlsEnd(); ++it )
135 * // check whether to refresh metadata
136 * // if the check fails for this url, it throws, so another url will be checked
137 * if (!checkIfToRefreshMetadata(info, *it, policy))
140 * // do the actual refresh
142 * catch (const Exception & e)
145 * ERR << *it << " doesn't look good. Trying another url." << endl;
149 * handle("No more URLs.");
156 * \throws RepoUnknownTypeException
157 * \throws repo::RepoNoAliasException if can't figure an alias
158 * \throws Exception on unknown error
161 bool checkIfToRefreshMetadata( const RepoInfo &info,
163 RawMetadataRefreshPolicy policy );
165 * \short Refresh local raw cache
167 * Will try to download the metadata
169 * In case of falure the metadata remains
172 * \throws repo::RepoNoUrlException if no urls are available.
173 * \throws repo::RepoNoAliasException if can't figure an alias
174 * \throws repo::RepoUnknownTypeException if the metadata is unknown
175 * \throws repo::RepoException if the repository is invalid
176 * (no valid metadata found at any of baseurls)
178 void refreshMetadata( const RepoInfo &info,
179 RawMetadataRefreshPolicy policy = RefreshIfNeeded,
180 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
183 * \short Clean local metadata
185 * Empty local metadata.
187 * \throws repo::RepoNoAliasException if can't figure an alias
188 * \throws Exception on unknown error.
190 void cleanMetadata( const RepoInfo &info,
191 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
194 * \short Status of metadata cache
196 RepoStatus cacheStatus( const RepoInfo &info ) const;
199 * \short Refresh local cache
201 * Will try to build the cache from local metadata.
203 * If the cache exists it will be overwriten.
205 * \note the local metadata must be valid.
207 * \throws repo::RepoNoAliasException if can't figure
208 * an alias to look in cache
209 * \throws repo::RepoMetadataException if the metadata
210 * is not enough to build a cache (empty, incorrect, or
212 * \throws repo::RepoUnknownTypeException
213 * \throws parser::ParseException if parser encounters an error.
214 * \throws Exception on unknown error.
216 void buildCache( const RepoInfo &info,
217 CacheBuildPolicy policy = BuildIfNeeded,
218 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
221 * \short clean local cache
223 * Clean the cached version of the metadata
225 * \note the local metadata must be valid.
227 * \throws repo::RepoNoAliasException if can't figure an alias to look in cache
228 * \throws cache::CacheRecordNotFoundException if the cache could not be
229 * cleaned because of repository record not found.
230 * \throws Exception on unknown error.
232 void cleanCache( const RepoInfo &info,
233 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
236 * \short Whether a repository exists in cache
238 * \param RepoInfo to be checked.
240 bool isCached( const RepoInfo &info ) const;
243 * \short Create a repository object from the cache data
245 * Creating from cache requires that the repository is
246 * refreshed (metadata downloaded) and cached
248 * \throws repo::RepoNoAliasException if can't figure an alias to look in cache
249 * \throw RepoNotCachedException When the source is not cached.
251 Repository createFromCache( const RepoInfo &info,
252 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
255 * \short Create a repository object from raw metadata
257 * Creating from cache requires that the repository is
258 * refreshed (metadata downloaded)
260 * \throw Exception If there are errors parsing the
263 Repository createFromMetadata( const RepoInfo &info,
264 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
267 * \short Probe repo metadata type.
269 * \todo FIXME Should this be private?
271 repo::RepoType probe( const Url &url ) const;
275 * \short Adds a repository to the list of known repositories.
279 * \throws repo::RepoAlreadyExistsException If the repo clash some
280 * unique attribute like alias
281 * \throws RepoUnknownType If repository type can't be determined
282 * \throws RepoException If the access to the url fails (while probing).
283 * \throws Exception On other errors.
285 void addRepository( const RepoInfo &info,
286 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
289 * \short Adds repositores from a repo file to the list of known repositories.
290 * \param url Url of the repo file
292 * \throws repo::RepoAlreadyExistsException If the repo clash some
293 * unique attribute like alias
295 * \throws RepoAlreadyExistsException
296 * \throws MediaException If the access to the url fails
297 * \throws ParseException If the file parsing fails
298 * \throws RepoUnknownType If repository type can't be determined
299 * \throws RepoException ON other repository related errors
300 * \throws Exception On other errors.
302 void addRepositories( const Url &url,
303 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
305 * \short Remove the best matching repository from known repos list
307 * \throws RepoNotFoundException If no repo match
309 void removeRepository( const RepoInfo & info,
310 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
313 * \short Modify repository attributes
315 * \throws RepoNotFoundException If no repo match
316 * \throws ParseException If the file parsing fails
317 * \throws Exception On other errors.
319 void modifyRepository( const std::string &alias,
320 const RepoInfo & newinfo,
321 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
324 * \short Find a matching repository info
326 * \note if multiple repositories incorrectly share the
327 * same alias, the first one found will be returned.
329 * \param alias Repository alias
330 * \param progressrcv Progress reporting function
331 * \return RepoInfo of the found repository
332 * \throws RepoNotFoundException If no repo match the alias
333 * \throws ParseException If the file parsing fails
334 * \throws Exception On other errors.
336 RepoInfo getRepositoryInfo( const std::string &alias,
337 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
340 * \short Find repository info by URL.
342 * \param url URL to find.
343 * \param urlview url::ViewOption to influence URL matching.
344 * \param progressrcv Progress receiver function.
345 * \return RepoInfo of the found repository.
347 * \note if multpile repositories incorrectly share the
348 * same URL, the first one found will be returned.
350 * \note the string representation of the URLs are compared.
351 * The \a urlview can be used to influence which
352 parts of the URL are to be compared.
354 * \throws RepoNotFoundException If no repo match
355 * \throws ParseException If the file parsing fails
356 * \throws Exception On other errors.
358 RepoInfo getRepositoryInfo( const Url & url,
359 const url::ViewOption & urlview = url::ViewOption::DEFAULTS,
360 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
363 RepoStatus rawMetadataStatus( const RepoInfo &info );
364 RepoStatus cacheStatus( const RepoInfo &info );
367 * Update timestamp of repository index file for the specified repository \a info.
368 * Used in \ref checkIfToRefreshMetadata() for repo.refresh.delay feature.
370 void touchIndexFile(const RepoInfo & info);
375 /** Pointer to implementation */
376 RWCOW_pointer<Impl> _pimpl;
378 ///////////////////////////////////////////////////////////////////
380 /** \relates RepoManager Stream output */
381 std::ostream & operator<<( std::ostream & str, const RepoManager & obj );
383 /////////////////////////////////////////////////////////////////
385 ///////////////////////////////////////////////////////////////////
386 #endif // ZYPP2_REPOMANAGER_H