libzypp  17.38.7
RepoManager.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
13 #include "RepoManager.h"
14 
15 #include <iostream>
16 #include <zypp-core/Digest.h>
17 #include <zypp-core/ng/pipelines/Lift>
19 #include <zypp/ng/context.h>
20 #include <zypp/ng/repo/refresh.h>
22 
23 #undef ZYPP_BASE_LOGGER_LOGGROUP
24 #define ZYPP_BASE_LOGGER_LOGGROUP "zypp::repomanager"
25 
26 using std::endl;
27 using std::string;
28 using namespace zypp::repo;
29 
30 #define OPT_PROGRESS const ProgressData::ReceiverFnc & = ProgressData::ReceiverFnc()
31 
33 namespace zypp
34 {
41  {
42  public:
43  Impl( zyppng::ContextRef &&ctx, RepoManagerOptions &&opt) {
44  _ngMgr = zyppng::RepoManager::create( std::move(ctx), std::move(opt) ).unwrap();
45  }
46 
47  Impl(const Impl &) = delete;
48  Impl(Impl &&) = delete;
49  Impl &operator=(const Impl &) = delete;
50  Impl &operator=(Impl &&) = delete;
51 
52  public:
53  const zyppng::RepoManager &ngMgr() const {
54  return *_ngMgr;
55  }
56 
58  return *_ngMgr;
59  }
60 
61  private:
62  zyppng::RepoManagerRef _ngMgr;
63 
64  private:
65  friend Impl * rwcowClone<Impl>( const Impl * rhs );
67  Impl * clone() const
68  { return new Impl( zyppng::ContextRef(_ngMgr->zyppContext()), RepoManagerOptions(_ngMgr->options()) ); }
69  };
71 
73  inline std::ostream & operator<<( std::ostream & str, const RepoManager::Impl & obj )
74  { return str << "RepoManager::Impl"; }
75 
77  //
78  // CLASS NAME : RepoManager
79  //
81 
83  : _pimpl( new Impl( zyppng::Context::defaultContext(), std::move(opt)) )
84  {}
85 
86  RepoManager::~RepoManager()
87  {}
88 
89  bool RepoManager::repoEmpty() const
90  { return _pimpl->ngMgr().repoEmpty(); }
91 
92  RepoManager::RepoSizeType RepoManager::repoSize() const
93  { return _pimpl->ngMgr().repoSize(); }
94 
95  RepoManager::RepoConstIterator RepoManager::repoBegin() const
96  { return _pimpl->ngMgr().repoBegin(); }
97 
98  RepoManager::RepoConstIterator RepoManager::repoEnd() const
99  { return _pimpl->ngMgr().repoEnd(); }
100 
101  RepoInfo RepoManager::getRepo( const std::string & alias ) const
102  { return _pimpl->ngMgr().getRepo( alias ); }
103 
104  bool RepoManager::hasRepo( const std::string & alias ) const
105  { return _pimpl->ngMgr().hasRepo( alias ); }
106 
107  std::string RepoManager::makeStupidAlias( const Url & url_r )
108  {
109  std::string ret( url_r.getScheme() );
110  if ( ret.empty() )
111  ret = "repo-";
112  else
113  ret += "-";
114 
115  std::string host( url_r.getHost() );
116  if ( ! host.empty() )
117  {
118  ret += host;
119  ret += "-";
120  }
121 
122  static Date::ValueType serial = Date::now();
123  ret += Digest::digest( Digest::sha1(), str::hexstring( ++serial ) +url_r.asCompleteString() ).substr(0,8);
124  return ret;
125  }
126 
127  RepoStatus RepoManager::metadataStatus( const RepoInfo & info ) const
128  { return _pimpl->ngMgr().metadataStatus( info ).unwrap(); }
129 
131  { return _pimpl->ngMgr().checkIfToRefreshMetadata( info, origin, policy ).unwrap(); }
132 
134  { return _pimpl->ngMgr().checkIfToRefreshMetadata( info, url, policy ).unwrap(); }
135 
136  Pathname RepoManager::metadataPath( const RepoInfo &info ) const
137  { return _pimpl->ngMgr().metadataPath( info ).unwrap(); }
138 
139  Pathname RepoManager::packagesPath( const RepoInfo &info ) const
140  { return _pimpl->ngMgr().packagesPath( info ).unwrap(); }
141 
143  {
144  // Suppress (interactive) media::MediaChangeReport if we have fallback URLs
146  return _pimpl->ngMgr().refreshMetadata( info, policy, nullptr ).unwrap();
147  }
148 
149  void RepoManager::cleanMetadata( const RepoInfo &info, const ProgressData::ReceiverFnc & progressrcv )
150  { return _pimpl->ngMgr().cleanMetadata( info, nullptr ).unwrap(); }
151 
152  void RepoManager::cleanPackages( const RepoInfo &info, const ProgressData::ReceiverFnc & progressrcv )
153  { return _pimpl->ngMgr().cleanPackages( info, nullptr ).unwrap(); }
154 
155  RepoStatus RepoManager::cacheStatus( const RepoInfo &info ) const
156  { return _pimpl->ngMgr().cacheStatus( info ).unwrap(); }
157 
158  void RepoManager::buildCache( const RepoInfo &info, CacheBuildPolicy policy, const ProgressData::ReceiverFnc & progressrcv )
159  {
161  auto adapt = zyppng::ProgressObserverAdaptor( progressrcv, report );
162  return _pimpl->ngMgr().buildCache( info, policy, adapt.observer() ).unwrap();
163  }
164 
165  void RepoManager::cleanCache( const RepoInfo &info, const ProgressData::ReceiverFnc & progressrcv )
166  { return _pimpl->ngMgr().cleanCache( info, nullptr ).unwrap(); }
167 
168  bool RepoManager::isCached( const RepoInfo &info ) const
169  { return _pimpl->ngMgr().isCached( info ).unwrap(); }
170 
171  void RepoManager::loadFromCache( const RepoInfo &info, const ProgressData::ReceiverFnc & progressrcv )
172  { return _pimpl->ngMgr().loadFromCache( info, nullptr ).unwrap(); }
173 
174  void RepoManager::cleanCacheDirGarbage( const ProgressData::ReceiverFnc & progressrcv )
175  { return _pimpl->ngMgr().cleanCacheDirGarbage( nullptr ).unwrap(); }
176 
177  repo::RepoType RepoManager::probe( const Url & url, const Pathname & path ) const
178  { return _pimpl->ngMgr().probe( {url}, path ).unwrap(); }
179 
180  repo::RepoType RepoManager::probe( const Url & url ) const
181  { return _pimpl->ngMgr().probe( {url} ).unwrap(); }
182 
183  void RepoManager::addRepository( const RepoInfo &info, const TriBool & forcedProbe, const ProgressData::ReceiverFnc & progressrcv )
184  {
186  auto adapt = zyppng::ProgressObserverAdaptor( progressrcv, report );
187  RepoInfo updatedRepo = _pimpl->ngMgr().addRepository( info, adapt.observer(), forcedProbe ).unwrap();
188 
189  // We should fix the API as we must inject those paths
190  // into the repoinfo in order to keep it usable.
191  RepoInfo & oinfo( const_cast<RepoInfo &>(info) );
192  oinfo.setFilepath( updatedRepo.filepath() );
193  oinfo.setMetadataPath( zyppng::rawcache_path_for_repoinfo( _pimpl->ngMgr().options(), updatedRepo ).unwrap() );
194  oinfo.setPackagesPath( zyppng::packagescache_path_for_repoinfo( _pimpl->ngMgr().options(), updatedRepo ).unwrap() );
195  }
196 
197  void RepoManager::addRepository( const RepoInfo &info, const ProgressData::ReceiverFnc & progressrcv )
198  { addRepository( info, indeterminate, progressrcv ); }
199 
200  void RepoManager::addRepositories( const Url &url, const ProgressData::ReceiverFnc & progressrcv )
201  { return _pimpl->ngMgr().addRepositories( url, nullptr ).unwrap(); }
202 
203  void RepoManager::removeRepository( const RepoInfo & info, const ProgressData::ReceiverFnc & progressrcv )
204  {
206  auto adapt = zyppng::ProgressObserverAdaptor( progressrcv, report );
207  return _pimpl->ngMgr().removeRepository( info, adapt.observer() ).unwrap();
208  }
209 
210  void RepoManager::modifyRepository( const std::string &alias, const RepoInfo & newinfo, const ProgressData::ReceiverFnc & progressrcv )
211  {
212  RepoInfo updated = _pimpl->ngMgr().modifyRepository( alias, newinfo, nullptr ).unwrap();
213  // We should fix the API as we must inject those paths
214  // into the repoinfo in order to keep it usable.
215  RepoInfo & oinfo( const_cast<RepoInfo &>(newinfo) );
216  oinfo.setFilepath( updated.filepath());
217  oinfo.setMetadataPath( zyppng::rawcache_path_for_repoinfo( _pimpl->ngMgr().options(), updated ).unwrap() );
218  oinfo.setPackagesPath( zyppng::packagescache_path_for_repoinfo( _pimpl->ngMgr().options(), updated ).unwrap() );
219  }
220 
221  RepoInfo RepoManager::getRepositoryInfo( const std::string &alias, const ProgressData::ReceiverFnc & progressrcv )
222  { return _pimpl->ngMgr().getRepositoryInfo( alias ).unwrap(); }
223 
224  RepoInfo RepoManager::getRepositoryInfo( const Url & url, const url::ViewOption & urlview, const ProgressData::ReceiverFnc & progressrcv )
225  { return _pimpl->ngMgr().getRepositoryInfo( url, urlview ).unwrap(); }
226 
227  bool RepoManager::serviceEmpty() const
228  { return _pimpl->ngMgr().serviceEmpty(); }
229 
230  RepoManager::ServiceSizeType RepoManager::serviceSize() const
231  { return _pimpl->ngMgr().serviceSize(); }
232 
233  RepoManager::ServiceConstIterator RepoManager::serviceBegin() const
234  { return _pimpl->ngMgr().serviceBegin(); }
235 
236  RepoManager::ServiceConstIterator RepoManager::serviceEnd() const
237  { return _pimpl->ngMgr().serviceEnd(); }
238 
239  ServiceInfo RepoManager::getService( const std::string & alias ) const
240  { return _pimpl->ngMgr().getService( alias ); }
241 
242  bool RepoManager::hasService( const std::string & alias ) const
243  { return _pimpl->ngMgr().hasService( alias ); }
244 
245  repo::ServiceType RepoManager::probeService( const Url &url ) const
246  { return _pimpl->ngMgr().probeService( url ).unwrap(); }
247 
248  void RepoManager::addService( const std::string & alias, const Url& url )
249  { return _pimpl->ngMgr().addService( alias, url ).unwrap(); }
250 
251  void RepoManager::addService( const ServiceInfo & service )
252  { return _pimpl->ngMgr().addService( service ).unwrap(); }
253 
254  void RepoManager::removeService( const std::string & alias )
255  { return _pimpl->ngMgr().removeService( alias ).unwrap(); }
256 
257  void RepoManager::removeService( const ServiceInfo & service )
258  { return _pimpl->ngMgr().removeService( service ).unwrap(); }
259 
260  void RepoManager::refreshServices( const RefreshServiceOptions & options_r )
261  { return _pimpl->ngMgr().refreshServices( options_r ).unwrap(); }
262 
263  void RepoManager::refreshService( const std::string & alias, const RefreshServiceOptions & options_r )
264  { return _pimpl->ngMgr().refreshService( alias, options_r ).unwrap(); }
265 
266  void RepoManager::refreshService( const ServiceInfo & service, const RefreshServiceOptions & options_r )
267  { return _pimpl->ngMgr().refreshService( service, options_r ).unwrap(); }
268 
269  void RepoManager::modifyService( const std::string & oldAlias, const ServiceInfo & service )
270  { return _pimpl->ngMgr().modifyService( oldAlias, service ).unwrap(); }
271 
272  void RepoManager::refreshGeoIp (const RepoInfo::url_set &urls)
273  { (void) _pimpl->ngMgr().refreshGeoIp( urls ); }
274 
276 
277  std::ostream & operator<<( std::ostream & str, const RepoManager & obj )
278  { return str << *obj._pimpl; }
279 
280  std::list<RepoInfo> readRepoFile(const Url &repo_file)
281  {
283  }
284 
286 } // namespace zypp
std::string getScheme() const
Returns the scheme name of the URL.
Definition: Url.cc:560
Pathname filepath() const
File where this repo was read from.
Service data.
Definition: ServiceInfo.h:36
RepoSet::size_type RepoSizeType
Definition: RepoManager.h:75
MaybeAwaitable< expected< repo::RefreshContextRef > > refreshMetadata(repo::RefreshContextRef refCtx, LazyMediaHandle< Provide > medium, ProgressObserverRef progressObserver)
std::ostream & operator<<(std::ostream &str, const DeltaCandidates::Impl &obj)
relates: DeltaCandidates::Impl Stream output
RepoManagerFlags::RefreshServiceFlags RefreshServiceOptions
Options tuning RefreshService.
Definition: RepoManager.h:99
Impl * clone() const
clone for RWCOW_pointer
Definition: RepoManager.cc:67
MirroredOriginSet repoOrigins() const
The repodata origins.
Definition: RepoInfo.cc:735
MaybeAwaitable< expected< repo::RefreshContextRef > > buildCache(repo::RefreshContextRef refCtx, zypp::RepoManagerFlags::CacheBuildPolicy policy, ProgressObserverRef progressObserver)
function< bool(const ProgressData &)> ReceiverFnc
Most simple version of progress reporting The percentage in most cases.
Definition: progressdata.h:140
MaybeAwaitable< expected< void > > refreshService(RepoManagerRef repoMgr, ServiceInfo info, zypp::RepoManagerFlags::RefreshServiceOptions options)
Definition: serviceswf.cc:713
String related utilities and Regular expression matching.
MaybeAwaitable< expected< RepoInfo > > addRepository(RepoManagerRef mgr, RepoInfo info, ProgressObserverRef myProgress, const zypp::TriBool &forcedProbe)
void setFilepath(const Pathname &filename)
set the path to the .repo file
Definition: ansi.h:854
What is known about a repository.
Definition: RepoInfo.h:71
Url::asString() view options.
Definition: UrlBase.h:40
expected< zypp::Pathname > packagescache_path_for_repoinfo(const RepoManagerOptions &opt, const RepoInfo &info)
Calculates the packages cache path for a repository.
Definition: repomanager.h:189
Repo manager settings.
boost::logic::tribool TriBool
3-state boolean logic (true, false and indeterminate).
Definition: String.h:31
time_t ValueType
Definition: Date.h:38
zyppng::RepoManager & ngMgr()
Definition: RepoManager.cc:57
std::list< RepoInfo > readRepoFile(const Url &repo_file)
Parses repo_file and returns a list of RepoInfo objects corresponding to repositories found within th...
Definition: RepoManager.cc:280
Manages a data source characterized by an authoritative URL and a list of mirror URLs.
Service type enumeration.
Definition: ServiceType.h:26
void setMetadataPath(const Pathname &path)
Set the path where the local metadata is stored.
Definition: RepoInfo.cc:755
std::string asCompleteString() const
Returns a complete string representation of the Url object.
Definition: Url.cc:532
std::ostream & operator<<(std::ostream &str, const RepoManager &obj)
relates: RepoManager Stream output
Definition: RepoManager.cc:277
MaybeAwaitable< expected< repo::RefreshCheckStatus > > checkIfToRefreshMetadata(repo::RefreshContextRef refCtx, LazyMediaHandle< Provide > medium, ProgressObserverRef progressObserver)
ServiceSet::size_type ServiceSizeType
Definition: RepoManager.h:70
Impl(zyppng::ContextRef &&ctx, RepoManagerOptions &&opt)
Definition: RepoManager.cc:43
std::list< Url > url_set
Definition: RepoInfo.h:108
static ContextRef defaultContext()
Definition: context.cc:26
bool hasFallbackUrls() const
Whether this set contains more than one Url in total (authorities or mirrors).
void setPackagesPath(const Pathname &path)
set the path where the local packages are stored
Definition: RepoInfo.cc:758
Temporarily disable MediaChangeReport Sometimes helpful to suppress interactive messages connected to...
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: RepoManager.h:663
MaybeAwaitable< expected< void > > addRepositories(RepoManagerRef mgr, zypp::Url url, ProgressObserverRef myProgress)
std::string getHost(EEncoding eflag=zypp::url::E_DECODED) const
Returns the hostname or IP from the URL authority.
Definition: Url.cc:615
const zyppng::RepoManager & ngMgr() const
Definition: RepoManager.cc:53
RepoSet::const_iterator RepoConstIterator
Definition: RepoManager.h:74
static expected< std::shared_ptr< RepoManager > > create(Args &&...args)
Definition: repomanager.h:262
#define ZYPP_LOCAL
Definition: Globals.h:71
RefreshCheckStatus
Possibly return state of RepoManager::checkIfToRefreshMetadata function.
expected< zypp::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.
Definition: repomanager.h:166
Track changing files or directories.
Definition: RepoStatus.h:40
The RepoManager class Provides knowledge and methods to maintain repo settings and metadata for a giv...
Definition: repomanager.h:240
zyppng::RepoManagerRef _ngMgr
Definition: RepoManager.cc:62
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
std::string hexstring(char n, int w=4)
Definition: String.h:325
RepoManager implementation.
MaybeAwaitable< expected< std::list< RepoInfo > > > readRepoFile(ContextRef ctx, zypp::Url repoFileUrl)
zypp::RepoManagerOptions RepoManagerOptions
Definition: repomanager.h:42
Url manipulation class.
Definition: Url.h:92
RepoManager(RepoManagerOptions options=RepoManagerOptions())
Definition: repomanager.cc:238
Repository type enumeration.
Definition: RepoType.h:28
ServiceSet::const_iterator ServiceConstIterator
Definition: RepoManager.h:69