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 Refresh local raw cache
107 * Will try to download the metadata
109 * In case of falure the metadata remains
112 * \throws repo::RepoNoUrlException if no urls are available.
113 * \throws repo::RepoNoAliasException if can't figure an alias
114 * \throws repo::RepoUnknownTypeException if the metadata is unknown
115 * \throws Exception on unknown error.
117 void refreshMetadata( const RepoInfo &info,
118 RawMetadataRefreshPolicy policy = RefreshIfNeeded,
119 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
122 * \short Clean local metadata
124 * Empty local metadata.
126 * \throws repo::RepoNoAliasException if can't figure an alias
127 * \throws Exception on unknown error.
129 void cleanMetadata( const RepoInfo &info,
130 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
133 * \short Refresh local cache
135 * Will try to build the cache from
138 * If the cache exists it will be overwriten.
140 * \note the local metadata must be valid.
142 * \throws repo::RepoNoAliasException if can't figure an alias to look in cache
143 * \throws Exception on unknown error.
145 void buildCache( const RepoInfo &info,
146 CacheBuildPolicy policy = BuildIfNeeded,
147 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
150 * \short clean local cache
152 * Clean the cached version of the metadata
154 * \note the local metadata must be valid.
156 * \throws repo::RepoNoAliasException if can't figure an alias to look in cache
157 * \throws Exception on unknown error.
159 void cleanCache( const RepoInfo &info,
160 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
163 * \short Whether a repository exists in cache
165 * \param RepoInfo to be checked.
167 bool isCached( const RepoInfo &info ) const;
170 * \short Create a repository object from the cache data
172 * Creating from cache requires that the repository is
173 * refreshed (metadata downloaded) and cached
175 * \throws repo::RepoNoAliasException if can't figure an alias to look in cache
176 * \throw RepoNotCachedException When the source is not cached.
178 Repository createFromCache( const RepoInfo &info,
179 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
182 * \short Create a repository object from raw metadata
184 * Creating from cache requires that the repository is
185 * refreshed (metadata downloaded)
187 * \throw Exception If there are errors parsing the
190 Repository createFromMetadata( const RepoInfo &info,
191 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
194 * \short Probe repo metadata type.
196 * \todo FIXME Should this be private?
198 repo::RepoType probe( const Url &url );
202 * \short Adds a repository to the list of known repositories.
206 * \throws repo::RepoAlreadyExistsException If the repo clash some
207 * unique attribute like alias
209 * \throws RepoAlreadyExistsException
211 void addRepository( const RepoInfo &info,
212 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
215 * \short Adds repositores from a repo file to the list of known repositories.
216 * \param url Url of the repo file
218 * \throws repo::RepoAlreadyExistsException If the repo clash some
219 * unique attribute like alias
221 * \throws RepoAlreadyExistsException
222 * \throws MediaException If the access to the url fails
223 * \throws ParseException If the file parsing fails
224 * \throws Exception On other errors.
226 void addRepositories( const Url &url,
227 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
229 * \short Remove the best matching repository from known repos list
231 * \throws RepoNotFoundException If no repo match
233 void removeRepository( const RepoInfo & info,
234 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
237 * \short Modify repository attributes
239 * \throws RepoNotFoundException If no repo match
240 * \throws ParseException If the file parsing fails
241 * \throws Exception On other errors.
243 void modifyRepository( const std::string &alias,
244 const RepoInfo & newinfo,
245 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
248 * \short Find a matching repository info
250 * \note if multple repositories incorrectly share the
251 * same alias, the first one found will be returned.
253 * \throws RepoNotFoundException If no repo match
254 * \throws ParseException If the file parsing fails
255 * \throws Exception On other errors.
257 RepoInfo getRepositoryInfo( const std::string &alias,
258 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
261 RepoStatus rawMetadataStatus( const RepoInfo &info );
262 RepoStatus cacheStatus( const RepoInfo &info );
266 /** Pointer to implementation */
267 RWCOW_pointer<Impl> _pimpl;
269 ///////////////////////////////////////////////////////////////////
271 /** \relates RepoManager Stream output */
272 std::ostream & operator<<( std::ostream & str, const RepoManager & obj );
274 /////////////////////////////////////////////////////////////////
276 ///////////////////////////////////////////////////////////////////
277 #endif // ZYPP2_REPOMANAGER_H