42 template <
class Executor,
class OpType>
43 struct ProbeRepoLogic :
public LogicBase<Executor, OpType>
51 using MediaHandle =
typename ProvideType::MediaHandle;
58 ,
_path(std::move(path))
62 MaybeAsyncRef<expected<zypp::repo::RepoType>> execute( ) {
63 const auto &url =
_medium.baseUrl();
64 MIL <<
"going to probe the repo type at " << url <<
" (" <<
_path <<
")" << std::endl;
68 MIL <<
"Probed type NONE (not exists) at " << url <<
" (" <<
_path <<
")" << std::endl;
78 std::shared_ptr<ProvideType> providerRef =
_zyppContext->provider();
83 return providerRef->attachMediaIfNeeded(
_medium )
84 |
and_then([
this, providerRef]( MediaHandle medium )
88 |
and_then( maybeCopyResultToDest(
"repodata/repomd.xml") )
91 |
or_else( [
this, providerRef, medium]( std::exception_ptr err ) {
93 std::rethrow_exception (err);
98 DBG <<
"problem checking for repodata/repomd.xml file" << std::endl;
106 |
and_then( maybeCopyResultToDest(
"content") )
110 |
or_else( [
this, medium]( std::exception_ptr err ) {
113 std::rethrow_exception (err);
118 DBG <<
"problem checking for content file" << std::endl;
130 const auto &url = medium.baseUrl();
133 if ( ! ( url.schemeIsDownloading() || url.schemeIsPlugin() ) ) {
137 MIL <<
"Probed type RPMPLAINDIR at " << url <<
" (" <<
_path <<
")" << std::endl;
145 MIL <<
"Probed type NONE at " << url <<
" (" <<
_path <<
")" << std::endl;
157 auto maybeCopyResultToDest ( std::string &&subPath ) {
160 MIL <<
"Target path is set, copying " << file.file() <<
" to " << *
_targetPath/subPath << std::endl;
161 return std::move(file)
179 template <
class RefreshContextRef>
180 auto probeRepoLogic( RefreshContextRef ctx,
RepoInfo repo, std::optional<zypp::Pathname> targetPath)
184 |
and_then( [ctx, path = repo.
path() ](
auto &&mediaHandle ) {
185 return probeRepoType( ctx, std::forward<decltype(mediaHandle)>(mediaHandle), path );
202 return probeRepoLogic( std::move(ctx), std::move(repo), std::move(targetPath) );
207 return probeRepoLogic( std::move(ctx), std::move(repo), std::move(targetPath) );
212 template <
class ZyppContextRef>
213 auto readRepoFileLogic( ZyppContextRef ctx,
zypp::Url repoFileUrl )
217 |
and_then([repoFileUrl](
auto local ){
218 DBG <<
"reading repo file " << repoFileUrl <<
", local path: " << local.file() << std::endl;
226 return readRepoFileLogic( std::move(ctx), std::move(repoFileUrl) );
231 return readRepoFileLogic( std::move(ctx), std::move(repoFileUrl) );
236 template<
typename Executor,
class OpType>
237 struct CheckIfToRefreshMetadataLogic :
public LogicBase<Executor, OpType> {
243 using ZyppContextRefType =
typename RefreshContextRefType::element_type::ContextRefType;
244 using ZyppContextType =
typename RefreshContextRefType::element_type::ContextType;
245 using ProvideType =
typename ZyppContextType::ProvideType;
247 using MediaHandle =
typename ProvideType::MediaHandle;
250 CheckIfToRefreshMetadataLogic( RefreshContextRefType refCtx,
LazyMediaHandle &&medium, ProgressObserverRef progressObserver )
256 MaybeAsyncRef<expected<repo::RefreshCheckStatus>> execute( ) {
258 MIL <<
"Going to CheckIfToRefreshMetadata" << std::endl;
264 MIL <<
"Check if to refresh repo " <<
_refreshContext->repoInfo().alias() <<
" at " <<
_medium.baseUrl() <<
" (" << info.type() <<
")" << std::endl;
273 if ( oldstatus.
empty() ) {
274 MIL <<
"No cached metadata, going to refresh" << std::endl;
278 if (
_medium.baseUrl().schemeIsVolatile() ) {
279 MIL <<
"Never refresh CD/DVD" << std::endl;
284 MIL <<
"Forced refresh!" << std::endl;
288 if (
_medium.baseUrl().schemeIsLocal() ) {
301 if ( oldstatus == *cachestatus ) {
304 const auto refDelay =
_refreshContext->zyppContext()->config().repo_refresh_delay();
305 if ( diff < refDelay ) {
307 WAR <<
"Repository '" << info.alias() <<
"' was refreshed in the future!" << std::endl;
310 MIL <<
"Repository '" << info.alias()
311 <<
"' has been refreshed less than repo.refresh.delay ("
313 <<
") minutes ago. Advising to skip refresh" << std::endl;
319 MIL <<
"Metadata and solv cache don't match. Check data on server..." << std::endl;
337 if ( oldstatus == newstatus ) {
338 MIL <<
"repo has not changed" << std::endl;
343 MIL <<
"repo has changed, going to refresh" << std::endl;
344 MIL <<
"Old status: " << oldstatus <<
" New Status: " << newstatus << std::endl;
372 template<
typename Executor,
class OpType>
373 struct RefreshMetadataLogic :
public LogicBase<Executor, OpType>{
380 using ZyppContextRefType =
typename RefreshContextRefType::element_type::ContextRefType;
381 using ZyppContextType =
typename RefreshContextRefType::element_type::ContextType;
382 using ProvideType =
typename ZyppContextType::ProvideType;
383 using MediaHandle =
typename ProvideType::MediaHandle;
388 using DlContextRefType = std::shared_ptr<DlContextType>;
390 RefreshMetadataLogic( RefreshContextRefType refCtx,
LazyMediaHandle &&medium, ProgressObserverRef progressObserver )
396 MaybeAsyncRef<expected<RefreshContextRefType>> execute() {
403 MIL <<
"RefreshCheckStatus returned: " << status << std::endl;
410 MIL <<
"Going to refresh metadata from " <<
_medium.baseUrl() << std::endl;
420 if ( info.type() != repokind ) {
423 info.setProbedType( repokind );
437 dlContext->setPluginRepoverification(
_refreshContext->pluginRepoverification() );
442 |
and_then([
this]( DlContextRefType && ) {
475 template <
class RefreshContextRef>
476 auto refreshMetadataLogic( RefreshContextRef refCtx, ProgressObserverRef progressObserver)
485 auto helper = std::make_shared<ExHelper>( ExHelper{
488 "Valid metadata not found at specified URLs",
489 refCtx->repoInfo().baseUrlsSize() ) }
493 auto refreshPipeline = [ refCtx, progressObserver ](
zypp::Url url ){
495 |
and_then( [ refCtx , progressObserver](
auto mediaHandle )
mutable {
return refreshMetadata ( std::move(refCtx), std::move(mediaHandle), progressObserver ); } );
504 ERR <<
"Trying another url..." << std::endl;
509 if ( helper->isFirst ) {
510 helper->rexception.remember( e );
511 helper->isFirst =
false;
522 return refCtx->repoInfo().baseUrls()
527 ERR <<
"No more urls..." << std::endl;
537 return refreshMetadataLogic ( std::move(refCtx), std::move(progressObserver) );
541 return refreshMetadataLogic ( std::move(refCtx), std::move(progressObserver) );
547 template <
typename ZyppCtxRef>
struct Repo2SolvOp;
550 struct Repo2SolvOp<ContextRef> :
public AsyncOp<expected<void>>
555 MIL <<
"Starting repo2solv for repo " << repo.
alias () << std::endl;
556 auto me = std::make_shared<Repo2SolvOp<ContextRef>>();
557 me->_repo = std::move(repo);
562 std::vector<const char *> argsIn;
563 argsIn.reserve ( args.size() );
564 std::for_each( args.begin (), args.end(), [&](
const std::string &s ) { argsIn.push_back(s.data()); });
565 argsIn.push_back (
nullptr);
567 if (!me->_proc->start( argsIn.data() )) {
575 const std::string &line = data.
asString();
580 void procFinished(
int ret ) {
582 while (
_proc->canReadLine() )
601 struct Repo2SolvOp<SyncContextRef>
605 std::string errdetail;
608 WAR <<
" " << output;
612 int ret = prog.
close();
623 template<
typename Executor,
class OpType>
624 struct BuildCacheLogic :
public LogicBase<Executor, OpType>{
627 using ZyppContextRefType =
typename RefreshContextRefType::element_type::ContextRefType;
628 using ZyppContextType =
typename RefreshContextRefType::element_type::ContextType;
629 using ProvideType =
typename ZyppContextType::ProvideType;
630 using MediaHandle =
typename ProvideType::MediaHandle;
641 MaybeAsyncRef<expected<RefreshContextRefType>> execute() {
652 const auto &options =
_refCtx->repoManagerOptions();
663 if ( raw_metadata_status.
empty() )
675 bool needs_cleaning =
false;
676 const auto &info =
_refCtx->repoInfo();
677 if (
_refCtx->repoManager()->isCached( info ) )
679 MIL << info.alias() <<
" is already cached." << std::endl;
684 if ( *cache_status == raw_metadata_status )
686 MIL << info.alias() <<
" cache is up to date with metadata." << std::endl;
700 MIL << info.alias() <<
" cache rebuild is forced" << std::endl;
704 needs_cleaning =
true;
711 auto r =
_refCtx->repoManager()->cleanCache(info);
716 MIL << info.alias() <<
" building cache..." << info.type() << std::endl;
740 switch ( repokind.
toEnum() )
750 MIL <<
"repo type is " << repokind << std::endl;
752 return mountIfRequired( repokind, info )
753 |
and_then([
this, repokind, solvfile = std::move(solvfile) ]( std::optional<MediaHandle> forPlainDirs )
mutable {
755 const auto &info =
_refCtx->repoInfo();
757 switch ( repokind.
toEnum() )
767#ifdef ZYPP_REPO2SOLV_PATH
768 cmd.push_back( ZYPP_REPO2SOLV_PATH );
770 cmd.push_back(
zypp::PathInfo(
"/usr/bin/repo2solv" ).isFile() ?
"repo2solv" :
"repo2solv.sh" );
773 cmd.push_back(
"-o" );
774 cmd.push_back( solvfile.
asString() );
775 cmd.push_back(
"-X" );
781 cmd.push_back(
"-R" );
783 std::optional<zypp::Pathname> localPath = forPlainDirs.has_value() ? forPlainDirs->localPath() :
zypp::Pathname();
788 cmd.push_back( (*localPath / info.path().absolutename()).c_str() );
793 return Repo2SolvOp<ZyppContextRefType>::run( info, std::move(cmd) )
794 |
and_then( [
this, guard = std::move(guard), solvfile = std::move(solvfile) ]()
mutable {
796 guard.resetDispose();
806 |
and_then([
this, raw_metadata_status](){
808 return _refCtx->repoManager()->setCacheStatus(
_refCtx->repoInfo(), raw_metadata_status );
812 MIL <<
"Commit cache.." << std::endl;
817 |
or_else ( [
this]( std::exception_ptr e ) {
829 |
and_then( [
this]( MediaHandle handle ) {
858 template<
typename Executor,
class OpType>
859 struct AddRepoLogic :
public LogicBase<Executor, OpType>{
865 AddRepoLogic( RepoManagerPtrType &&repoMgrRef,
RepoInfo &&info, ProgressObserverRef &&myProgress )
871 MaybeAsyncRef<expected<RepoInfo> > execute() {
877 MIL <<
"Try adding repo " <<
_info << std::endl;
887 DBG <<
"unknown repository type, probing" << std::endl;
906 MIL <<
"done" << std::endl;
909 |
or_else( [
this]( std::exception_ptr e) {
911 MIL <<
"done" << std::endl;
935 template<
typename Executor,
class OpType>
936 struct AddReposLogic :
public LogicBase<Executor, OpType>{
941 AddReposLogic( RepoManagerPtrType &&repoMgrRef,
zypp::Url &&url, ProgressObserverRef &&myProgress )
947 MaybeAsyncRef<expected<void>> execute() {
952 |
and_then([
this]( std::list<RepoInfo> repos ) {
954 for ( std::list<RepoInfo>::const_iterator it = repos.begin();
961 if ( (*it).alias() == (*kit).alias() )
963 ERR <<
"To be added repo " << (*it).alias() <<
" conflicts with existing repo " << (*kit).alias() << std::endl;
983 MIL <<
"Saving " << repos.size() <<
" repo" << ( repos.size() ?
"s" :
"" ) <<
" in " << repofile << std::endl;
985 std::ofstream file(repofile.
c_str());
992 for ( std::list<RepoInfo>::iterator it = repos.begin();
996 MIL <<
"Saving " << (*it).alias() << std::endl;
1004 it->dumpAsIniOn(file);
1005 it->setFilepath(repofile);
1006 it->setMetadataPath( *rawCachePath );
1007 it->setPackagesPath( *pckCachePath );
1013 MIL <<
"done" << std::endl;
1039 template<
typename Executor,
class OpType>
1040 struct RefreshGeoIpLogic :
public LogicBase<Executor, OpType>{
1046 using ZyppContextType =
typename ZyppContextRefType::element_type;
1047 using ProvideType =
typename ZyppContextType::ProvideType;
1048 using MediaHandle =
typename ProvideType::MediaHandle;
1049 using ProvideRes =
typename ProvideType::Res;
1057 MaybeAsyncRef<expected<void>> execute() {
1061 if ( !
_zyppCtx->config().geoipEnabled() ) {
1062 MIL <<
"GeoIp disabled via ZConfig, not refreshing the GeoIP information." << std::endl;
1066 std::vector<std::string> hosts;
1067 for (
const auto &baseUrl : _urls ) {
1068 const auto &host = baseUrl.getHost();
1069 if (
zypp::any_of(
_zyppCtx->config().geoipHostnames(), [&host](
const auto &elem ){ return ( zypp::str::compareCI( host, elem ) == 0 ); } ) ) {
1070 hosts.push_back( host );
1075 if ( hosts.empty() ) {
1076 MIL <<
"No configured geoip URL found, not updating geoip data" << std::endl;
1083 MIL <<
"Unable to create cache directory for GeoIP." << std::endl;
1088 MIL <<
"No access rights for the GeoIP cache directory." << std::endl;
1098 auto age = std::chrono::system_clock::now() - std::chrono::system_clock::from_time_t( pi.mtime() );
1099 if ( age < std::chrono::hours(24) )
1102 MIL <<
"Removing GeoIP file for " << entry.
name <<
" since it's older than 24hrs." << std::endl;
1107 auto firstOfCb = [
this]( std::string hostname ) {
1111 MIL <<
"Skipping GeoIP request for " << hostname <<
" since a valid cache entry exists." << std::endl;
1115 MIL <<
"Query GeoIP for " << hostname << std::endl;
1124 MIL <<
"Ignoring invalid GeoIP hostname: " << hostname << std::endl;
1131 |
inspect_err( [hostname](
const std::exception_ptr& ){
MIL <<
"Failed to query GeoIP from hostname: " << hostname << std::endl; } )
1136 constexpr auto writeHostToFile = [](
const zypp::Pathname &fName,
const std::string &host ){
1138 out.open( fName.
asString(), std::ios_base::trunc );
1139 if ( out.is_open() ) {
1140 out << host << std::endl;
1142 MIL <<
"Failed to create/open GeoIP cache file " << fName << std::endl;
1146 std::string geoipMirror;
1149 if ( reader.seekToNode( 1,
"host" ) ) {
1150 const auto &
str = reader.nodeText().asString();
1158 MIL <<
"Storing geoIP redirection: " << hostname <<
" -> " <<
str << std::endl;
1163 MIL <<
"No host entry or empty file returned for GeoIP, remembering for 24hrs" << std::endl;
1167 MIL <<
"Empty or invalid GeoIP file, not requesting again for 24hrs" << std::endl;
1170 writeHostToFile( _geoIPCache / hostname, geoipMirror );
1176 return std::move(hosts)
1178 | [](
bool foundGeoIP ){
1181 MIL <<
"Successfully queried GeoIP data." << std::endl;
1185 MIL <<
"Failed to query GeoIP data." << std::endl;