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/RepoInfo.h"
22 #include "zypp/repo/RepoException.h"
23 #include "zypp/repo/RepoType.h"
24 #include "zypp/RepoStatus.h"
25 #include "zypp/ProgressData.h"
27 ///////////////////////////////////////////////////////////////////
29 { /////////////////////////////////////////////////////////////////
32 * Parses \a repo_file and returns a list of \ref RepoInfo objects
33 * corresponding to repositories found within the file.
35 * \param repo_file Valid URL of the repo file.
36 * \return found list<RepoInfo>
38 * \throws MediaException If the access to the url fails
39 * \throws ParseException If the file parsing fails
40 * \throws Exception On other errors.
42 std::list<RepoInfo> readRepoFile(const Url & repo_file);
45 * Repo manager settings.
46 * Settings default to ZYpp global settings.
48 struct RepoManagerOptions
52 Pathname repoCachePath;
53 Pathname repoRawCachePath;
54 Pathname repoPackagesCachePath;
55 Pathname knownReposPath;
60 * \short creates and provides information about known sources.
65 friend std::ostream & operator<<( std::ostream & str, const RepoManager & obj );
72 RepoManager( const RepoManagerOptions &options = RepoManagerOptions() );
76 enum RawMetadataRefreshPolicy
94 * \short List known repositories.
96 * The known repositories are read from
97 * \ref RepoManagerOptions::knownReposPath passed on the Ctor.
98 * Which defaults to ZYpp global settings.
99 * \return found list<RepoInfo>
101 std::list<RepoInfo> knownRepositories() const;
104 * \short Status of local metadata
106 RepoStatus metadataStatus( const RepoInfo &info ) const;
109 * Checks whether to refresh metadata for specified repository and url.
111 * The need for refresh is evaluated according to the following conditions,
114 * <li>the refresh policy (refresh may be forced)
115 * <li>the repo.refresh.delay ZConfig value compared to the difference between
116 * cached index file timestamp and actual time
117 * <li>the timestamp of cached repo index file compared to the remote
118 * index file timestamp.
121 * This method checks the status against the specified url only. If more
122 * baseurls are defined for in the RepoInfo, each one must be check
123 * individually. Example:
128 * // try urls one by one
129 * for ( RepoInfo::urls_const_iterator it = info.baseUrlsBegin();
130 * it != info.baseUrlsEnd(); ++it )
134 * // check whether to refresh metadata
135 * // if the check fails for this url, it throws, so another url will be checked
136 * if (!checkIfToRefreshMetadata(info, *it, policy))
139 * // do the actual refresh
141 * catch (const Exception & e)
144 * ERR << *it << " doesn't look good. Trying another url." << endl;
148 * handle("No more URLs.");
155 * \throws RepoUnknownTypeException
156 * \throws repo::RepoNoAliasException if can't figure an alias
157 * \throws Exception on unknown error
160 bool checkIfToRefreshMetadata( const RepoInfo &info,
162 RawMetadataRefreshPolicy policy = RefreshIfNeeded);
165 * \short Path where the metadata is downloaded and kept
167 * Given a repoinfo, tells where \ref RepoManager will download
168 * and keep the raw metadata.
170 * \param info Repository information
172 * \throws repo::RepoNoAliasException if can't figure an alias
174 Pathname metadataPath( const RepoInfo &info ) const;
177 * \short Refresh local raw cache
179 * Will try to download the metadata
181 * In case of falure the metadata remains
184 * \throws repo::RepoNoUrlException if no urls are available.
185 * \throws repo::RepoNoAliasException if can't figure an alias
186 * \throws repo::RepoUnknownTypeException if the metadata is unknown
187 * \throws repo::RepoException if the repository is invalid
188 * (no valid metadata found at any of baseurls)
190 void refreshMetadata( const RepoInfo &info,
191 RawMetadataRefreshPolicy policy = RefreshIfNeeded,
192 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
195 * \short Clean local metadata
197 * Empty local metadata.
199 * \throws repo::RepoNoAliasException if can't figure an alias
200 * \throws Exception on unknown error.
202 void cleanMetadata( const RepoInfo &info,
203 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
206 * \short Clean local package cache
208 * Empty local directory with downloaded packages
210 * \throws repo::RepoNoAliasException if can't figure an alias
211 * \throws Exception on unknown error.
213 void cleanPackages( const RepoInfo &info,
214 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
217 * \short Status of metadata cache
219 RepoStatus cacheStatus( const RepoInfo &info ) const;
222 * \short Refresh local cache
224 * Will try to build the cache from local metadata.
226 * If the cache exists it will be overwriten.
228 * \note the local metadata must be valid.
230 * \throws repo::RepoNoAliasException if can't figure
231 * an alias to look in cache
232 * \throws repo::RepoMetadataException if the metadata
233 * is not enough to build a cache (empty, incorrect, or
235 * \throws repo::RepoUnknownTypeException
236 * \throws parser::ParseException if parser encounters an error.
237 * \throws Exception on unknown error.
239 void buildCache( const RepoInfo &info,
240 CacheBuildPolicy policy = BuildIfNeeded,
241 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
244 * \short clean local cache
246 * Clean the cached version of the metadata
248 * \note the local metadata must be valid.
250 * \throws repo::RepoNoAliasException if can't figure an alias to look in cache
251 * \throws cache::CacheRecordNotFoundException if the cache could not be
252 * cleaned because of repository record not found.
253 * \throws Exception on unknown error.
255 void cleanCache( const RepoInfo &info,
256 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
259 * Clean target system (rpm db) cache.
261 void cleanTargetCache(const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc());
264 * \short Whether a repository exists in cache
266 * \param RepoInfo to be checked.
268 bool isCached( const RepoInfo &info ) const;
272 * \short Load resolvables into the pool
274 * Creating from cache requires that the repository is
275 * refreshed (metadata downloaded) and cached
277 * \throws repo::RepoNoAliasException if can't figure an alias to look in cache
278 * \throw RepoNotCachedException When the source is not cached.
280 void loadFromCache( const RepoInfo &info,
281 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
283 * \short Probe repo metadata type.
285 * \todo FIXME Should this be private?
287 repo::RepoType probe( const Url &url ) const;
291 * \short Adds a repository to the list of known repositories.
295 * \throws repo::RepoAlreadyExistsException If the repo clash some
296 * unique attribute like alias
297 * \throws RepoUnknownType If repository type can't be determined
298 * \throws RepoException If the access to the url fails (while probing).
299 * \throws Exception On other errors.
301 void addRepository( const RepoInfo &info,
302 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
305 * \short Adds repositores from a repo file to the list of known repositories.
306 * \param url Url of the repo file
308 * \throws repo::RepoAlreadyExistsException If the repo clash some
309 * unique attribute like alias
311 * \throws RepoAlreadyExistsException
312 * \throws MediaException If the access to the url fails
313 * \throws ParseException If the file parsing fails
314 * \throws RepoUnknownType If repository type can't be determined
315 * \throws RepoException ON other repository related errors
316 * \throws Exception On other errors.
318 void addRepositories( const Url &url,
319 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
321 * \short Remove the best matching repository from known repos list
323 * \throws RepoNotFoundException If no repo match
325 void removeRepository( const RepoInfo & info,
326 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
329 * \short Modify repository attributes
331 * \throws RepoAlreadyExistsException if the alias specified in newinfo
332 * is already used by another repository
333 * \throws RepoNotFoundException If no repo match
334 * \throws ParseException If the file parsing fails
335 * \throws Exception On other errors.
337 void modifyRepository( const std::string &alias,
338 const RepoInfo & newinfo,
339 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
342 * \short Find a matching repository info
344 * \note if multiple repositories incorrectly share the
345 * same alias, the first one found will be returned.
347 * \param alias Repository alias
348 * \param progressrcv Progress reporting function
349 * \return RepoInfo of the found repository
350 * \throws RepoNotFoundException If no repo match the alias
351 * \throws ParseException If the file parsing fails
352 * \throws Exception On other errors.
354 RepoInfo getRepositoryInfo( const std::string &alias,
355 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
358 * \short Find repository info by URL.
360 * \param url URL to find.
361 * \param urlview url::ViewOption to influence URL matching.
362 * \param progressrcv Progress receiver function.
363 * \return RepoInfo of the found repository.
365 * \note if multpile repositories incorrectly share the
366 * same URL, the first one found will be returned.
368 * \note the string representation of the URLs are compared.
369 * The \a urlview can be used to influence which
370 parts of the URL are to be compared.
372 * \throws RepoNotFoundException If no repo match
373 * \throws ParseException If the file parsing fails
374 * \throws Exception On other errors.
376 RepoInfo getRepositoryInfo( const Url & url,
377 const url::ViewOption & urlview = url::ViewOption::DEFAULTS,
378 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
381 RepoStatus rawMetadataStatus( const RepoInfo &info );
382 void setCacheStatus( const std::string &alias, const RepoStatus &status );
385 * Update timestamp of repository index file for the specified repository \a info.
386 * Used in \ref checkIfToRefreshMetadata() for repo.refresh.delay feature.
388 void touchIndexFile(const RepoInfo & info);
393 /** Pointer to implementation */
394 RWCOW_pointer<Impl> _pimpl;
396 ///////////////////////////////////////////////////////////////////
398 /** \relates RepoManager Stream output */
399 std::ostream & operator<<( std::ostream & str, const RepoManager & obj );
401 /////////////////////////////////////////////////////////////////
403 ///////////////////////////////////////////////////////////////////
404 #endif // ZYPP2_REPOMANAGER_H