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 = RefreshIfNeeded);
166 * \short Path where the metadata is downloaded and kept
168 * Given a repoinfo, tells where \ref RepoManager will download
169 * and keep the raw metadata.
171 * \param info Repository information
173 * \throws repo::RepoNoAliasException if can't figure an alias
175 Pathname metadataPath( const RepoInfo &info ) const;
178 * \short Refresh local raw cache
180 * Will try to download the metadata
182 * In case of falure the metadata remains
185 * \throws repo::RepoNoUrlException if no urls are available.
186 * \throws repo::RepoNoAliasException if can't figure an alias
187 * \throws repo::RepoUnknownTypeException if the metadata is unknown
188 * \throws repo::RepoException if the repository is invalid
189 * (no valid metadata found at any of baseurls)
191 void refreshMetadata( const RepoInfo &info,
192 RawMetadataRefreshPolicy policy = RefreshIfNeeded,
193 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
196 * \short Clean local metadata
198 * Empty local metadata.
200 * \throws repo::RepoNoAliasException if can't figure an alias
201 * \throws Exception on unknown error.
203 void cleanMetadata( const RepoInfo &info,
204 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
207 * \short Status of metadata cache
209 RepoStatus cacheStatus( const RepoInfo &info ) const;
212 * \short Refresh local cache
214 * Will try to build the cache from local metadata.
216 * If the cache exists it will be overwriten.
218 * \note the local metadata must be valid.
220 * \throws repo::RepoNoAliasException if can't figure
221 * an alias to look in cache
222 * \throws repo::RepoMetadataException if the metadata
223 * is not enough to build a cache (empty, incorrect, or
225 * \throws repo::RepoUnknownTypeException
226 * \throws parser::ParseException if parser encounters an error.
227 * \throws Exception on unknown error.
229 void buildCache( const RepoInfo &info,
230 CacheBuildPolicy policy = BuildIfNeeded,
231 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
234 * \short clean local cache
236 * Clean the cached version of the metadata
238 * \note the local metadata must be valid.
240 * \throws repo::RepoNoAliasException if can't figure an alias to look in cache
241 * \throws cache::CacheRecordNotFoundException if the cache could not be
242 * cleaned because of repository record not found.
243 * \throws Exception on unknown error.
245 void cleanCache( const RepoInfo &info,
246 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
249 * \short Whether a repository exists in cache
251 * \param RepoInfo to be checked.
253 bool isCached( const RepoInfo &info ) const;
257 * \short Load resolvables into the pool
259 * Creating from cache requires that the repository is
260 * refreshed (metadata downloaded) and cached
262 * \throws repo::RepoNoAliasException if can't figure an alias to look in cache
263 * \throw RepoNotCachedException When the source is not cached.
265 void loadFromCache( const RepoInfo &info,
266 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
268 void loadFromCache( const std::string &alias,
269 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
272 * \short Probe repo metadata type.
274 * \todo FIXME Should this be private?
276 repo::RepoType probe( const Url &url ) const;
280 * \short Adds a repository to the list of known repositories.
284 * \throws repo::RepoAlreadyExistsException If the repo clash some
285 * unique attribute like alias
286 * \throws RepoUnknownType If repository type can't be determined
287 * \throws RepoException If the access to the url fails (while probing).
288 * \throws Exception On other errors.
290 void addRepository( const RepoInfo &info,
291 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
294 * \short Adds repositores from a repo file to the list of known repositories.
295 * \param url Url of the repo file
297 * \throws repo::RepoAlreadyExistsException If the repo clash some
298 * unique attribute like alias
300 * \throws RepoAlreadyExistsException
301 * \throws MediaException If the access to the url fails
302 * \throws ParseException If the file parsing fails
303 * \throws RepoUnknownType If repository type can't be determined
304 * \throws RepoException ON other repository related errors
305 * \throws Exception On other errors.
307 void addRepositories( const Url &url,
308 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
310 * \short Remove the best matching repository from known repos list
312 * \throws RepoNotFoundException If no repo match
314 void removeRepository( const RepoInfo & info,
315 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
318 * \short Modify repository attributes
320 * \throws RepoNotFoundException If no repo match
321 * \throws ParseException If the file parsing fails
322 * \throws Exception On other errors.
324 void modifyRepository( const std::string &alias,
325 const RepoInfo & newinfo,
326 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
329 * \short Find a matching repository info
331 * \note if multiple repositories incorrectly share the
332 * same alias, the first one found will be returned.
334 * \param alias Repository alias
335 * \param progressrcv Progress reporting function
336 * \return RepoInfo of the found repository
337 * \throws RepoNotFoundException If no repo match the alias
338 * \throws ParseException If the file parsing fails
339 * \throws Exception On other errors.
341 RepoInfo getRepositoryInfo( const std::string &alias,
342 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
345 * \short Find repository info by URL.
347 * \param url URL to find.
348 * \param urlview url::ViewOption to influence URL matching.
349 * \param progressrcv Progress receiver function.
350 * \return RepoInfo of the found repository.
352 * \note if multpile repositories incorrectly share the
353 * same URL, the first one found will be returned.
355 * \note the string representation of the URLs are compared.
356 * The \a urlview can be used to influence which
357 parts of the URL are to be compared.
359 * \throws RepoNotFoundException If no repo match
360 * \throws ParseException If the file parsing fails
361 * \throws Exception On other errors.
363 RepoInfo getRepositoryInfo( const Url & url,
364 const url::ViewOption & urlview = url::ViewOption::DEFAULTS,
365 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
368 RepoStatus rawMetadataStatus( const RepoInfo &info );
369 void setCacheStatus( const std::string &alias, const RepoStatus &status );
372 * Update timestamp of repository index file for the specified repository \a info.
373 * Used in \ref checkIfToRefreshMetadata() for repo.refresh.delay feature.
375 void touchIndexFile(const RepoInfo & info);
380 /** Pointer to implementation */
381 RWCOW_pointer<Impl> _pimpl;
383 ///////////////////////////////////////////////////////////////////
385 /** \relates RepoManager Stream output */
386 std::ostream & operator<<( std::ostream & str, const RepoManager & obj );
388 /////////////////////////////////////////////////////////////////
390 ///////////////////////////////////////////////////////////////////
391 #endif // ZYPP2_REPOMANAGER_H