libzypp 17.32.2
repomanagerbase_p.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#ifndef ZYPP_ZYPP_DETAIL_REPOMANAGERIMPL_H
13#define ZYPP_ZYPP_DETAIL_REPOMANAGERIMPL_H
14
16#include <zypp/RepoStatus.h>
17
19
20#include <zypp-core/base/Gettext.h>
21#include <utility>
22#include <zypp-core/base/DefaultIntegral>
23#include <zypp-core/base/NonCopyable.h>
24#include <zypp-core/fs/PathInfo.h>
26
27namespace zypp {
28
29 #define OPT_PROGRESS const ProgressData::ReceiverFnc & = ProgressData::ReceiverFnc()
30
32 inline bool isTmpRepo( const RepoInfo & info_r )
33 { return( info_r.filepath().empty() && info_r.usesAutoMetadataPaths() ); }
34
35 void assert_alias( const RepoInfo & info );
36
37 inline void assert_alias( const ServiceInfo & info )
38 {
39 if ( info.alias().empty() )
41 // bnc #473834. Maybe we can match the alias against a regex to define
42 // and check for valid aliases
43 if ( info.alias()[0] == '.')
45 info, _("Service alias cannot start with dot.")));
46 }
47
49 template <class Iterator>
50 inline bool foundAliasIn( const std::string & alias_r, Iterator begin_r, Iterator end_r )
51 {
52 for_( it, begin_r, end_r )
53 if ( it->alias() == alias_r )
54 return true;
55 return false;
56 }
58 template <class Container>
59 inline bool foundAliasIn( const std::string & alias_r, const Container & cont_r )
60 { return foundAliasIn( alias_r, cont_r.begin(), cont_r.end() ); }
61
63 template <class Iterator>
64 inline Iterator findAlias( const std::string & alias_r, Iterator begin_r, Iterator end_r )
65 {
66 for_( it, begin_r, end_r )
67 if ( it->alias() == alias_r )
68 return it;
69 return end_r;
70 }
72 template <class Container>
73 inline typename Container::iterator findAlias( const std::string & alias_r, Container & cont_r )
74 { return findAlias( alias_r, cont_r.begin(), cont_r.end() ); }
76 template <class Container>
77 inline typename Container::const_iterator findAlias( const std::string & alias_r, const Container & cont_r )
78 { return findAlias( alias_r, cont_r.begin(), cont_r.end() ); }
79
80
82 std::string filenameFromAlias( const std::string & alias_r, const std::string & stem_r );
83
100 {
103
106 {}
107
108 bool collect( const RepoInfo &repo );
109
110 RepoInfoList repos;
111 std::string targetDistro;
112 };
114
120 std::list<RepoInfo> repositories_in_file( const Pathname & file );
121
123
132 std::list<RepoInfo> repositories_in_dir( const Pathname &dir );
133
134 void assert_urls( const RepoInfo & info );
135
136 inline void assert_url( const ServiceInfo & info )
137 {
138 if ( ! info.url().isValid() )
140 }
141
147 {
148 assert_alias(info);
149 return isTmpRepo( info ) ? info.metadataPath() : opt.repoRawCachePath / info.escaped_alias();
150 }
151
161 { return rawcache_path_for_repoinfo( opt, info ) / info.path(); }
162
167 {
168 assert_alias(info);
169 return isTmpRepo( info ) ? info.packagesPath() : opt.repoPackagesCachePath / info.escaped_alias();
170 }
171
176 {
177 assert_alias(info);
178 return isTmpRepo( info ) ? info.metadataPath().dirname() / "%SLV%" : opt.repoSolvCachePath / info.escaped_alias();
179 }
180
182
185 {
186 public:
187 using ServiceSet = std::set<ServiceInfo>;
188
192
193 bool operator()( const ServiceInfo & service_r ) const
194 {
195 _services.insert( service_r );
196 return true;
197 }
198
199 private:
201 };
203
205 bool autoPruneInDir( const Pathname & path_r );
206
207
214 {
215 public:
216
221 {
222 public:
223 MatchServiceAlias( std::string alias_ ) : alias(std::move(alias_)) {}
224 bool operator()( const RepoInfo & info ) const
225 { return info.service() == alias; }
226 private:
227 std::string alias;
228 };
229
231 using ServiceSet = std::set<ServiceInfo>;
232 using ServiceConstIterator = ServiceSet::const_iterator;
233 using ServiceSizeType = ServiceSet::size_type;
234
236 using RepoSet = std::set<RepoInfo>;
237 using RepoConstIterator = RepoSet::const_iterator;
238 using RepoSizeType = RepoSet::size_type;
239
240
242 virtual ~RepoManagerBaseImpl();
243
244 public:
245
246 bool repoEmpty() const { return repos().empty(); }
247 RepoSizeType repoSize() const { return repos().size(); }
248 RepoConstIterator repoBegin() const { return repos().begin(); }
249 RepoConstIterator repoEnd() const { return repos().end(); }
250
251 bool hasRepo( const std::string & alias ) const
252 { return foundAliasIn( alias, repos() ); }
253
254 RepoInfo getRepo( const std::string & alias ) const
255 {
256 RepoConstIterator it( findAlias( alias, repos() ) );
257 return it == repos().end() ? RepoInfo::noRepo : *it;
258 }
259
260 public:
261 Pathname metadataPath( const RepoInfo & info ) const
262 { return rawcache_path_for_repoinfo( _options, info ); }
263
264 Pathname packagesPath( const RepoInfo & info ) const
265 { return packagescache_path_for_repoinfo( _options, info ); }
266
267 static RepoStatus metadataStatus( const RepoInfo & info, const RepoManagerOptions &options );
268 RepoStatus metadataStatus( const RepoInfo & info ) const;
269
270 void cleanMetadata( const RepoInfo & info, OPT_PROGRESS );
271
272 void cleanPackages(const RepoInfo & info, OPT_PROGRESS , bool isAutoClean = false);
273
274 static repo::RepoType probeCache( const Pathname & path_r );
275
276 void cleanCacheDirGarbage( OPT_PROGRESS );
277
278 void cleanCache( const RepoInfo & info, OPT_PROGRESS );
279
280 bool isCached( const RepoInfo & info ) const
281 { return PathInfo(solv_path_for_repoinfo( _options, info ) / "solv").isExist(); }
282
283 RepoStatus cacheStatus( const RepoInfo & info ) const
284 { return cacheStatus( info, _options ); }
285
286 static RepoStatus cacheStatus( const RepoInfo & info, const RepoManagerOptions &options )
287 { return RepoStatus::fromCookieFile(solv_path_for_repoinfo(options, info) / "cookie"); }
288
289 void loadFromCache( const RepoInfo & info, OPT_PROGRESS );
290
291 void addProbedRepository( const RepoInfo & info, repo::RepoType probedType );
292
293 virtual void removeRepository ( const RepoInfo & info, OPT_PROGRESS ) = 0;
294
295 void modifyRepository( const std::string & alias, const RepoInfo & newinfo_r, OPT_PROGRESS );
296
297 RepoInfo getRepositoryInfo( const std::string & alias );
298 RepoInfo getRepositoryInfo( const Url & url, const url::ViewOption & urlview );
299
300 public:
301 bool serviceEmpty() const { return _services.empty(); }
302 ServiceSizeType serviceSize() const { return _services.size(); }
303 ServiceConstIterator serviceBegin() const { return _services.begin(); }
304 ServiceConstIterator serviceEnd() const { return _services.end(); }
305
306 bool hasService( const std::string & alias ) const
307 { return foundAliasIn( alias, _services ); }
308
309 ServiceInfo getService( const std::string & alias ) const
310 {
311 ServiceConstIterator it( findAlias( alias, _services ) );
312 return it == _services.end() ? ServiceInfo::noService : *it;
313 }
314
315 public:
316 void addService( const ServiceInfo & service );
317 void addService( const std::string & alias, const Url & url )
318 { addService( ServiceInfo( alias, url ) ); }
319
320 void removeService( const std::string & alias );
321 void removeService( const ServiceInfo & service )
322 { removeService( service.alias() ); }
323
324 void modifyService( const std::string & oldAlias, const ServiceInfo & newService );
325
326 static void touchIndexFile( const RepoInfo & info, const RepoManagerOptions &options );
327
328 protected:
329 void removeRepositoryImpl( const RepoInfo & info, OPT_PROGRESS );
330 void saveService( ServiceInfo & service ) const;
331
332 Pathname generateNonExistingName( const Pathname & dir, const std::string & basefilename ) const;
333
334 std::string generateFilename( const RepoInfo & info ) const
335 { return filenameFromAlias( info.alias(), "repo" ); }
336
337 std::string generateFilename( const ServiceInfo & info ) const
338 { return filenameFromAlias( info.alias(), "service" ); }
339
340 void setCacheStatus( const RepoInfo & info, const RepoStatus & status )
341 {
342 Pathname base = solv_path_for_repoinfo( _options, info );
343 filesystem::assert_dir(base);
344 status.saveToCookieFile( base / "cookie" );
345 }
346
347 void touchIndexFile( const RepoInfo & info );
348
349 template<typename OutputIterator>
350 void getRepositoriesInService( const std::string & alias, OutputIterator out ) const
351 {
352 MatchServiceAlias filter( alias );
353 std::copy( boost::make_filter_iterator( filter, repos().begin(), repos().end() ),
354 boost::make_filter_iterator( filter, repos().end(), repos().end() ),
355 out);
356 }
357
358 protected:
359 void init_knownServices();
360 void init_knownRepositories();
361
362 const RepoSet & repos() const { return _reposX; }
363 RepoSet & reposManip() { if ( ! _reposDirty ) _reposDirty = true; return _reposX; }
364
365 protected:
369
371 };
372
373}
374
375#endif
#define OPT_PROGRESS
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
Definition AutoDispose.h:95
What is known about a repository.
Definition RepoInfo.h:72
Pathname metadataPath() const
Path where this repo metadata was read from.
Definition RepoInfo.cc:593
Pathname path() const
Repository path.
Definition RepoInfo.cc:635
std::string service() const
Gets name of the service to which this repository belongs or empty string if it has been added manual...
Definition RepoInfo.cc:638
Pathname packagesPath() const
Path where this repo packages are cached.
Definition RepoInfo.cc:596
Track changing files or directories.
Definition RepoStatus.h:41
void saveToCookieFile(const Pathname &path_r) const
Save the status information to a cookie file.
Functor collecting ServiceInfos into a ServiceSet.
std::set< ServiceInfo > ServiceSet
ServiceCollector(ServiceSet &services_r)
bool operator()(const ServiceInfo &service_r) const
Service data.
Definition ServiceInfo.h:37
Url url() const
The service url.
Url manipulation class.
Definition Url.h:92
bool isValid() const
Verifies the Url.
Definition Url.cc:493
Wrapper class for stat/lstat.
Definition PathInfo.h:222
bool isExist() const
Return whether valid stat info exists.
Definition PathInfo.h:282
Pathname dirname() const
Return all but the last component od this path.
Definition Pathname.h:124
std::string escaped_alias() const
Same as alias(), just escaped in a way to be a valid file name.
std::string alias() const
unique identifier for this source.
Thrown when the repo alias is found to be invalid.
Service without alias was used in an operation.
Service has no or invalid url defined.
Definition Arch.h:364
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition NonCopyable.h:26
Easy-to use interface to the ZYPP dependency resolver.
Pathname rawcache_path_for_repoinfo(const RepoManagerOptions &opt, const RepoInfo &info)
Calculates the raw cache path for a repository, this is usually /var/cache/zypp/alias.
bool isTmpRepo(const RepoInfo &info_r)
Whether repo is not under RM control and provides its own methadata paths.
void assert_alias(const RepoInfo &info)
Pathname solv_path_for_repoinfo(const RepoManagerOptions &opt, const RepoInfo &info)
Calculates the solv cache path for a repository.
std::list< RepoInfo > repositories_in_file(const Pathname &file)
Reads RepoInfo's from a repo file.
bool autoPruneInDir(const Pathname &path_r)
bsc#1204956: Tweak to prevent auto pruning package caches.
Pathname packagescache_path_for_repoinfo(const RepoManagerOptions &opt, const RepoInfo &info)
Calculates the packages cache path for a repository.
std::list< RepoInfo > repositories_in_dir(const Pathname &dir)
List of RepoInfo's from a directory.
Pathname rawproductdata_path_for_repoinfo(const RepoManagerOptions &opt, const RepoInfo &info)
Calculates the raw product metadata path for a repository, this is inside the raw cache dir,...
void assert_url(const ServiceInfo &info)
void assert_urls(const RepoInfo &info)
bool foundAliasIn(const std::string &alias_r, Iterator begin_r, Iterator end_r)
Check if alias_r is present in repo/service container.
std::string filenameFromAlias(const std::string &alias_r, const std::string &stem_r)
Generate a related filename from a repo/service infos alias.
Iterator findAlias(const std::string &alias_r, Iterator begin_r, Iterator end_r)
Find alias_r in repo/service container.
Simple callback to collect the results.
RepoCollector(std::string targetDistro_)
bool collect(const RepoInfo &repo)
Functor thats filter RepoInfo by service which it belongs to.
bool operator()(const RepoInfo &info) const
RepoSet::const_iterator RepoConstIterator
RepoInfo getRepo(const std::string &alias) const
ServiceConstIterator serviceEnd() const
static RepoStatus cacheStatus(const RepoInfo &info, const RepoManagerOptions &options)
RepoSet::size_type RepoSizeType
RepoConstIterator repoEnd() const
ServiceSet::const_iterator ServiceConstIterator
bool hasService(const std::string &alias) const
void removeService(const ServiceInfo &service)
ServiceSet::size_type ServiceSizeType
RepoStatus cacheStatus(const RepoInfo &info) const
virtual void removeRepository(const RepoInfo &info, OPT_PROGRESS)=0
bool hasRepo(const std::string &alias) const
std::set< RepoInfo > RepoSet
RepoInfo typedefs.
void getRepositoriesInService(const std::string &alias, OutputIterator out) const
std::set< ServiceInfo > ServiceSet
ServiceInfo typedefs.
Pathname packagesPath(const RepoInfo &info) const
void setCacheStatus(const RepoInfo &info, const RepoStatus &status)
RepoSizeType repoSize() const
ServiceInfo getService(const std::string &alias) const
DefaultIntegral< bool, false > _reposDirty
RepoConstIterator repoBegin() const
void addService(const std::string &alias, const Url &url)
bool isCached(const RepoInfo &info) const
ServiceSizeType serviceSize() const
const RepoSet & repos() const
std::string generateFilename(const ServiceInfo &info) const
std::string generateFilename(const RepoInfo &info) const
ServiceConstIterator serviceBegin() const
Pathname metadataPath(const RepoInfo &info) const
Repo manager settings.
Repository type enumeration.
Definition RepoType.h:28
Url::asString() view options.
Definition UrlBase.h:40
#define ZYPP_LOCAL
Definition Globals.h:59
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition Easy.h:28
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition Exception.h:429
#define _(MSG)
Definition Gettext.h:37