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/Pathname.h"
20 #include "zypp/ZConfig.h"
21 #include "zypp/Repository.h"
22 #include "zypp/RepoInfo.h"
23 #include "zypp/repo/RepoException.h"
24 #include "zypp/repo/RepoType.h"
25 #include "zypp/RepoStatus.h"
26 #include "zypp/ProgressData.h"
28 ///////////////////////////////////////////////////////////////////
30 { /////////////////////////////////////////////////////////////////
33 * Parses \a repo_file and returns a list of \ref RepoInfo objects
34 * corresponding to repositories found within the file.
36 * \param repo_file Valid URL of the repo file.
37 * \return found list<RepoInfo>
39 * \throws MediaException If the access to the url fails
40 * \throws ParseException If the file parsing fails
41 * \throws Exception On other errors.
43 std::list<RepoInfo> readRepoFile(const Url & repo_file);
46 * Repo manager settings.
47 * Settings default to ZYpp global settings.
49 struct RepoManagerOptions
53 Pathname repoCachePath;
54 Pathname repoRawCachePath;
55 Pathname knownReposPath;
59 * \short creates and provides information about known sources.
64 friend std::ostream & operator<<( std::ostream & str, const RepoManager & obj );
71 RepoManager( const RepoManagerOptions &options = RepoManagerOptions() );
75 enum RawMetadataRefreshPolicy
93 * \short List known repositories.
95 * The known repositories are read from
96 * \ref RepoManagerOptions::knownReposPath passed on the Ctor.
97 * Which defaults to ZYpp global settings.
98 * \return found list<RepoInfo>
100 std::list<RepoInfo> knownRepositories() const;
103 * \short Status of local metadata
105 RepoStatus metadataStatus( const RepoInfo &info ) const;
108 * Checks whether to refresh metadata for specified repository and url.
110 * The need for refresh is evaluated according to the following conditions,
113 * <li>the refresh policy (refresh may be forced)
114 * <li>the repo.refresh.delay ZConfig value compared to the difference between
115 * cached index file timestamp and actual time
116 * <li>the timestamp of cached repo index file compared to the remote
117 * index file timestamp.
120 * This method checks the status against the specified url only. If more
121 * baseurls are defined for in the RepoInfo, each one must be check
122 * individually. Example:
127 * // try urls one by one
128 * for ( RepoInfo::urls_const_iterator it = info.baseUrlsBegin();
129 * it != info.baseUrlsEnd(); ++it )
133 * // check whether to refresh metadata
134 * // if the check fails for this url, it throws, so another url will be checked
135 * if (!checkIfToRefreshMetadata(info, *it, policy))
138 * // do the actual refresh
140 * catch (const Exception & e)
143 * ERR << *it << " doesn't look good. Trying another url." << endl;
147 * handle("No more URLs.");
154 * \throws RepoUnknownTypeException
155 * \throws repo::RepoNoAliasException if can't figure an alias
156 * \throws Exception on unknown error
159 bool checkIfToRefreshMetadata( const RepoInfo &info,
161 RawMetadataRefreshPolicy policy = RefreshIfNeeded);
164 * \short Path where the metadata is downloaded and kept
166 * Given a repoinfo, tells where \ref RepoManager will download
167 * and keep the raw metadata.
169 * \param info Repository information
171 * \throws repo::RepoNoAliasException if can't figure an alias
173 Pathname metadataPath( const RepoInfo &info ) const;
176 * \short Refresh local raw cache
178 * Will try to download the metadata
180 * In case of falure the metadata remains
183 * \throws repo::RepoNoUrlException if no urls are available.
184 * \throws repo::RepoNoAliasException if can't figure an alias
185 * \throws repo::RepoUnknownTypeException if the metadata is unknown
186 * \throws repo::RepoException if the repository is invalid
187 * (no valid metadata found at any of baseurls)
189 void refreshMetadata( const RepoInfo &info,
190 RawMetadataRefreshPolicy policy = RefreshIfNeeded,
191 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
194 * \short Clean local metadata
196 * Empty local metadata.
198 * \throws repo::RepoNoAliasException if can't figure an alias
199 * \throws Exception on unknown error.
201 void cleanMetadata( const RepoInfo &info,
202 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
205 * \short Status of metadata cache
207 RepoStatus cacheStatus( const RepoInfo &info ) const;
210 * \short Refresh local cache
212 * Will try to build the cache from local metadata.
214 * If the cache exists it will be overwriten.
216 * \note the local metadata must be valid.
218 * \throws repo::RepoNoAliasException if can't figure
219 * an alias to look in cache
220 * \throws repo::RepoMetadataException if the metadata
221 * is not enough to build a cache (empty, incorrect, or
223 * \throws repo::RepoUnknownTypeException
224 * \throws parser::ParseException if parser encounters an error.
225 * \throws Exception on unknown error.
227 void buildCache( const RepoInfo &info,
228 CacheBuildPolicy policy = BuildIfNeeded,
229 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
232 * \short clean local cache
234 * Clean the cached version of the metadata
236 * \note the local metadata must be valid.
238 * \throws repo::RepoNoAliasException if can't figure an alias to look in cache
239 * \throws cache::CacheRecordNotFoundException if the cache could not be
240 * cleaned because of repository record not found.
241 * \throws Exception on unknown error.
243 void cleanCache( const RepoInfo &info,
244 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
247 * \short Whether a repository exists in cache
249 * \param RepoInfo to be checked.
251 bool isCached( const RepoInfo &info ) const;
255 * \short Load resolvables into the pool
257 * Creating from cache requires that the repository is
258 * refreshed (metadata downloaded) and cached
260 * \throws repo::RepoNoAliasException if can't figure an alias to look in cache
261 * \throw RepoNotCachedException When the source is not cached.
263 void loadFromCache( const RepoInfo &info,
264 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
266 * \short Probe repo metadata type.
268 * \todo FIXME Should this be private?
270 repo::RepoType probe( const Url &url ) const;
274 * \short Adds a repository to the list of known repositories.
278 * \throws repo::RepoAlreadyExistsException If the repo clash some
279 * unique attribute like alias
280 * \throws RepoUnknownType If repository type can't be determined
281 * \throws RepoException If the access to the url fails (while probing).
282 * \throws Exception On other errors.
284 void addRepository( const RepoInfo &info,
285 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
288 * \short Adds repositores from a repo file to the list of known repositories.
289 * \param url Url of the repo file
291 * \throws repo::RepoAlreadyExistsException If the repo clash some
292 * unique attribute like alias
294 * \throws RepoAlreadyExistsException
295 * \throws MediaException If the access to the url fails
296 * \throws ParseException If the file parsing fails
297 * \throws RepoUnknownType If repository type can't be determined
298 * \throws RepoException ON other repository related errors
299 * \throws Exception On other errors.
301 void addRepositories( const Url &url,
302 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
304 * \short Remove the best matching repository from known repos list
306 * \throws RepoNotFoundException If no repo match
308 void removeRepository( const RepoInfo & info,
309 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
312 * \short Modify repository attributes
314 * \throws RepoNotFoundException If no repo match
315 * \throws ParseException If the file parsing fails
316 * \throws Exception On other errors.
318 void modifyRepository( const std::string &alias,
319 const RepoInfo & newinfo,
320 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
323 * \short Find a matching repository info
325 * \note if multiple repositories incorrectly share the
326 * same alias, the first one found will be returned.
328 * \param alias Repository alias
329 * \param progressrcv Progress reporting function
330 * \return RepoInfo of the found repository
331 * \throws RepoNotFoundException If no repo match the alias
332 * \throws ParseException If the file parsing fails
333 * \throws Exception On other errors.
335 RepoInfo getRepositoryInfo( const std::string &alias,
336 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
339 * \short Find repository info by URL.
341 * \param url URL to find.
342 * \param urlview url::ViewOption to influence URL matching.
343 * \param progressrcv Progress receiver function.
344 * \return RepoInfo of the found repository.
346 * \note if multpile repositories incorrectly share the
347 * same URL, the first one found will be returned.
349 * \note the string representation of the URLs are compared.
350 * The \a urlview can be used to influence which
351 parts of the URL are to be compared.
353 * \throws RepoNotFoundException If no repo match
354 * \throws ParseException If the file parsing fails
355 * \throws Exception On other errors.
357 RepoInfo getRepositoryInfo( const Url & url,
358 const url::ViewOption & urlview = url::ViewOption::DEFAULTS,
359 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
362 RepoStatus rawMetadataStatus( const RepoInfo &info );
363 void setCacheStatus( const std::string &alias, const RepoStatus &status );
366 * Update timestamp of repository index file for the specified repository \a info.
367 * Used in \ref checkIfToRefreshMetadata() for repo.refresh.delay feature.
369 void touchIndexFile(const RepoInfo & info);
374 /** Pointer to implementation */
375 RWCOW_pointer<Impl> _pimpl;
377 ///////////////////////////////////////////////////////////////////
379 /** \relates RepoManager Stream output */
380 std::ostream & operator<<( std::ostream & str, const RepoManager & obj );
382 /////////////////////////////////////////////////////////////////
384 ///////////////////////////////////////////////////////////////////
385 #endif // ZYPP2_REPOMANAGER_H