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