40 const auto &scheme = serviceUrl.
getScheme();
41 if ( !root.
empty() && (scheme ==
"dir" || scheme ==
"file") ) {
47 struct FetchRIMServiceLogic
50 FetchRIMServiceLogic( ContextRef &&ctx,
zypp::Pathname &&root_r,
ServiceInfo &&service, ProgressObserverRef &&myProgress )
51 : _ctx( std::move(ctx) )
52 , _root_r( std::move(root_r) )
53 , _service( std::move(service) )
54 , _myProgress( std::move(myProgress) )
58 MaybeAwaitable<expected< std::pair<zypp::ServiceInfo, RepoInfoList> >> execute() {
66 return adaptServiceUrlToChroot( serviceUrl, _root_r );
69 |
and_then( [
this](
auto mediaHandle ) {
return _ctx->provider()->provide( mediaHandle,
"repo/repoindex.xml",
ProvideFileSpec() ); } )
70 |
and_then( [
this](
auto provideResult ) {
73 zypp::RepoInfoList repos;
77 _service.setProbedTtl( reader.
ttl() );
96 ProgressObserverRef _myProgress;
99 struct FetchPluginServiceLogic
104 FetchPluginServiceLogic( ContextRef &&ctx,
zypp::Pathname &&root_r,
ServiceInfo &&service, ProgressObserverRef &&myProgress )
105 : _ctx( std::move(ctx) )
106 , _root_r( std::move(root_r) )
107 , _service( std::move(service) )
108 , _myProgress( std::move(myProgress) )
112 MaybeAwaitable<Ret> execute() {
120 return runPlugin( std::move(stripped) )
121 |
and_then( [
this](
int exitCode ) {
123 if ( exitCode != 0 ) {
126 ERR <<
"Capture plugin error:[" << std::endl << _stderrBuf << std::endl <<
']' << std::endl;
131 zypp::RepoInfoList repos;
134 std::stringstream buffer( _stdoutBuf );
139 return Ret::error( std::current_exception () );
145#ifdef ZYPP_ENABLE_ASYNC
146 AsyncOpRef<expected<int>> runPlugin( std::string command ) {
149 const char *args[] = {
157 pluginProcess->setChroot ( _root_r );
160 if ( !pluginProcess->start( args ) || !pluginProcess->isRunning () ) {
161 return makeReadyTask ( finalize( std::move(pluginProcess) ) );
164 co_return co_await ( std::move(pluginProcess)
166 | [
this]( ProcessRef proc ) {
return finalize( std::move(proc) ); } );
170 if ( proc->isRunning () ) {
171 proc->stop ( SIGKILL );
176 if ( proc->exitStatus() != 0 ) {
185 std::stringstream buffer;
189 args.push_back(
"/bin/sh" );
190 args.push_back(
"-c" );
191 args.push_back( command );
195 _stdoutBuf = buffer.str();
197 int retCode = prog.
close();
198 if ( retCode != 0 ) {
214 ProgressObserverRef _myProgress;
215 std::string _stdoutBuf;
216 std::string _stderrBuf;
222 if ( service.
type() == zypp::repo::ServiceType::PLUGIN ) {
223 FetchPluginServiceLogic impl( std::move(ctx), std::move(root_r), std::move(service), std::move(myProgress) );
224 zypp_co_return zypp_co_await( impl.execute() );
226 FetchRIMServiceLogic impl( std::move(ctx), std::move(root_r), std::move(service), std::move(myProgress) );
227 zypp_co_return zypp_co_await( impl.execute() );
237 |
and_then( [ctx]( MediaHandle medium ) {
return ctx->provider()->provide( medium,
"/repo/repoindex.xml",
ProvideFileSpec().setCheckExistsOnly()); } )
243 std::rethrow_exception( result.
error() );
263 enew.
remember( std::current_exception() );
273 struct RefreshServiceLogic
279 : _repoMgr(
std::move(repoMgr) )
280 , _service(
std::move(info) )
284 MaybeAwaitable<expected<void>> probeServiceIfNeeded() {
286 if ( _service.type() == zypp::repo::ServiceType::NONE ) {
288 return probeServiceType( _repoMgr->zyppContext(), adaptServiceUrlToChroot( _service.url(), _repoMgr->options().rootDir ) )
290 _service.setProbedType( type );
291 _serviceModified =
true;
299 MaybeAwaitable<Ret> execute() {
308 MIL <<
"Going to refresh service '" << _service.alias() <<
"', url: " << _service.url() <<
", opts: " << _options << std::endl;
313 zypp::Date lrf = _service.lrf();
319 if ( (lrf+=_service.ttl()) > now )
321 MIL <<
"Skip: '" << _service.alias() <<
"' metadata valid until " << lrf << std::endl;
326 WAR <<
"Force: '" << _service.alias() <<
"' metadata last refresh in the future: " << lrf << std::endl;
332 return probeServiceIfNeeded ()
342 | [
this]( expected<std::pair<zypp::ServiceInfo, RepoInfoList>> serviceReposExp ) {
344 if ( !serviceReposExp ) {
346 std::rethrow_exception( serviceReposExp.error() );
348 }
catch (
const zypp::repo::ServicePluginInformalException & e ) {
357 std::pair<zypp::ServiceInfo, RepoInfoList> serviceRepos = serviceReposExp.is_valid() ? std::move( serviceReposExp.get() ) : std::make_pair( _service,
RepoInfoList{} );
360 std::string servicesTargetDistro = _repoMgr->options().servicesTargetDistro;
361 if ( servicesTargetDistro.empty() ) {
362 servicesTargetDistro = zypp::Target::targetDistribution( zypp::Pathname() );
364 DBG <<
"ServicesTargetDistro: " << servicesTargetDistro << std::endl;
367 RepoCollector
collector( servicesTargetDistro );
368 std::for_each( serviceRepos.second.begin(), serviceRepos.second.end(), [&](
const auto &r ){ collector.collect(r); } );
370 if ( _service.ttl () != serviceRepos.first.ttl () ) {
372 if ( !serviceRepos.first.ttl() )
373 serviceRepos.first.setLrf( zypp::Date() );
375 _serviceModified =
true;
379 _service = serviceRepos.first;
390 it->setAlias(
zypp::str::form(
"%s:%s", _service.alias().c_str(), it->alias().c_str() ) );
392 it->setService( _service.alias() );
395 newRepoStates[it->alias()] = *it;
403 if ( !it->path().empty() )
405 if ( it->path() !=
"/" )
410 if ( it->baseUrlsEmpty() )
412 zypp::Url url( _service.rawUrl() );
414 url.setPathName( url.getPathName() / path );
415 it->setBaseUrl( std::move(url) );
417 else if ( !path.
empty() )
420 for ( zypp::Url & url : urls )
422 url.setPathName( url.getPathName() / path );
424 it->setBaseUrls( std::move(urls) );
432 _repoMgr->getRepositoriesInService( _service.alias(), std::back_inserter( oldRepos ) );
436 for_( oldRepo, oldRepos.begin(), oldRepos.end() )
440 if ( oldRepo->enabled() )
443 const auto & last = _service.repoStates().find( oldRepo->alias() );
444 if ( last != _service.repoStates().end() && ! last->second.enabled )
446 DBG <<
"Service removes user enabled repo " << oldRepo->alias() << std::endl;
447 _service.addRepoToEnable( oldRepo->alias() );
448 _serviceModified =
true;
451 DBG <<
"Service removes enabled repo " << oldRepo->alias() << std::endl;
454 DBG <<
"Service removes disabled repo " << oldRepo->alias() << std::endl;
456 auto remRes = _repoMgr->removeRepository( *oldRepo );
457 if ( !remRes )
return Ret::error( remRes.error() );
464 zypp::UrlCredentialExtractor urlCredentialExtractor( _repoMgr->options().rootDir );
472 DBG <<
"Service request to " << (it->enabled()?
"enable":
"disable") <<
" service repo " << it->alias() << std::endl;
476 DBG <<
"Opt RefreshService_restoreStatus " << it->alias() << std::endl;
481 _service.delRepoToEnable( it->alias() );
486 if ( _service.repoToEnableFind( it->alias() ) )
488 DBG <<
"User request to enable service repo " << it->alias() << std::endl;
493 _service.delRepoToEnable( it->alias() );
494 _serviceModified =
true;
496 else if ( _service.repoToDisableFind( it->alias() ) )
498 DBG <<
"User request to disable service repo " << it->alias() << std::endl;
503 RepoInfoList::iterator oldRepo(
findAlias( it->alias(), oldRepos ) );
504 if ( oldRepo == oldRepos.end() )
509 if ( ! indeterminate(toBeEnabled) )
510 it->setEnabled( (
bool ) toBeEnabled );
512 DBG <<
"Service adds repo " << it->alias() <<
" " << (it->enabled()?
"enabled":
"disabled") << std::endl;
513 const auto &addRes = _repoMgr->addRepository( *it );
514 if (!addRes)
return Ret::error( addRes.error() );
519 bool oldRepoModified =
false;
521 if ( indeterminate(toBeEnabled) )
525 if ( oldRepo->enabled() == it->enabled() )
526 toBeEnabled = it->enabled();
529 toBeEnabled = it->enabled();
530 DBG <<
"Opt RefreshService_restoreStatus " << it->alias() <<
" forces " << (toBeEnabled?
"enabled":
"disabled") << std::endl;
534 const auto & last = _service.repoStates().find( oldRepo->alias() );
535 if ( last == _service.repoStates().end() || last->second.enabled != it->enabled() )
536 toBeEnabled = it->enabled();
539 toBeEnabled = oldRepo->enabled();
540 DBG <<
"User modified service repo " << it->alias() <<
" may stay " << (toBeEnabled?
"enabled":
"disabled") << std::endl;
546 if ( toBeEnabled == oldRepo->enabled() )
548 DBG <<
"Service repo " << it->alias() <<
" stays " << (oldRepo->enabled()?
"enabled":
"disabled") << std::endl;
550 else if ( toBeEnabled )
552 DBG <<
"Service repo " << it->alias() <<
" gets enabled" << std::endl;
553 oldRepo->setEnabled(
true );
554 oldRepoModified =
true;
558 DBG <<
"Service repo " << it->alias() <<
" gets disabled" << std::endl;
559 oldRepo->setEnabled(
false );
560 oldRepoModified =
true;
566 if ( oldRepo->rawName() != it->rawName() )
568 DBG <<
"Service repo " << it->alias() <<
" gets new NAME " << it->rawName() << std::endl;
569 oldRepo->setName( it->rawName() );
570 oldRepoModified =
true;
574 if ( oldRepo->autorefresh() != it->autorefresh() )
576 DBG <<
"Service repo " << it->alias() <<
" gets new AUTOREFRESH " << it->autorefresh() << std::endl;
577 oldRepo->setAutorefresh( it->autorefresh() );
578 oldRepoModified =
true;
582 if ( oldRepo->priority() != it->priority() )
584 DBG <<
"Service repo " << it->alias() <<
" gets new PRIORITY " << it->priority() << std::endl;
585 oldRepo->setPriority( it->priority() );
586 oldRepoModified =
true;
592 urlCredentialExtractor.extract( newUrls );
593 if ( oldRepo->rawBaseUrls() != newUrls )
595 DBG <<
"Service repo " << it->alias() <<
" gets new URLs " << newUrls << std::endl;
596 oldRepo->setBaseUrls( std::move(newUrls) );
597 oldRepoModified =
true;
603 if ( _service.type() == zypp::repo::ServiceType::PLUGIN )
607 oldRepo->getRawGpgChecks( ogpg[0], ogpg[1], ogpg[2] );
608 it-> getRawGpgChecks( ngpg[0], ngpg[1], ngpg[2] );
609 #define Z_CHKGPG(I,N) \
610 if ( ! sameTriboolState( ogpg[I], ngpg[I] ) ) \
612 DBG << "Service repo " << it->alias() << " gets new "#N"Check " << ngpg[I] << std::endl; \
613 oldRepo->set##N##Check( ngpg[I] ); \
614 oldRepoModified = true; \
623 if ( oldRepo->rawGpgKeyUrls() != it->rawGpgKeyUrls() )
625 DBG <<
"Service repo " << it->alias() <<
" gets new GPGKEY url " << it->rawGpgKeyUrls() << std::endl;
626 oldRepo->setGpgKeyUrls( it->rawGpgKeyUrls() );
627 oldRepoModified =
true;
631 if ( oldRepo->rawCfgMirrorlistUrl() != it->rawCfgMirrorlistUrl() )
633 DBG <<
"Service repo " << it->alias() <<
" gets new MIRRORLIST url " << it->rawCfgMirrorlistUrl() << std::endl;
634 oldRepo->setMirrorlistUrl( it->rawCfgMirrorlistUrl() );
635 oldRepoModified =
true;
639 if ( oldRepo->rawCfgMetalinkUrl() != it->rawCfgMetalinkUrl() )
641 DBG <<
"Service repo " << it->alias() <<
" gets new METALINK url " << it->rawCfgMetalinkUrl() << std::endl;
642 oldRepo->setMetalinkUrl( it->rawCfgMetalinkUrl() );
643 oldRepoModified =
true;
647 if ( oldRepoModified )
649 auto modRes = _repoMgr->modifyRepository( oldRepo->alias(), *oldRepo );
650 if ( !modRes )
return Ret::error( modRes.error() );
656 if ( ! _service.reposToDisableEmpty() )
658 _service.clearReposToDisable();
659 _serviceModified =
true;
663 if ( _service.repoStates() != newRepoStates )
665 _service.setRepoStates( std::move(newRepoStates) );
666 _serviceModified =
true;
671 if ( _service.type() != zypp::repo::ServiceType::PLUGIN )
673 if ( _service.ttl() )
676 _serviceModified =
true;
679 if ( _serviceModified )
682 auto modRes = _repoMgr->modifyService( _service.alias(), _service );
683 if ( !modRes )
return Ret::error( modRes.error() );
687 if ( _informalError ) {
688 return Ret::error( std::make_exception_ptr (_informalError.value()) );
696 RepoManagerRef _repoMgr;
697 zypp::ServiceInfo _service;
703 bool _serviceModified =
false;
709 std::optional<zypp::repo::ServicePluginInformalException> _informalError;
715 RefreshServiceLogic impl( std::move(repoMgr), std::move(info), std::move(options) );
716 zypp_co_return zypp_co_await ( impl.execute() );