42 using MediaHandle =
typename ProvideType::MediaHandle;
45 StatusLogic( repo::DownloadContextRef ctx, MediaHandle &&
media )
46 : _ctx(std::move(ctx))
47 , _handle(std::move(
media))
50 MaybeAwaitable<expected<zypp::RepoStatus>> execute() {
51 return _ctx->zyppContext()->provider()->provide( _handle, _ctx->repoInfo().path() /
"content" ,
ProvideFileSpec().setMirrorsAllowed(
false) )
60 if ( !status.
empty() ) {
61 return _ctx->zyppContext()->provider()->provide( _handle,
"/media.1/media" ,
ProvideFileSpec().setMirrorsAllowed(
false) )
73 repo::DownloadContextRef _ctx;
80 StatusLogic impl( std::move(dl), std::move(mediaHandle) );
81 zypp_co_return zypp_co_await( impl.execute() );
101 using MediaHandle =
typename ProvideType::MediaHandle;
104 DlLogic( repo::DownloadContextRef ctx, MediaHandle &&mediaHandle, ProgressObserverRef &&progressObserver )
105 : _ctx(
std::move(ctx))
106 , _mediaHandle(
std::move(mediaHandle))
107 , _progressObserver(
std::move(progressObserver))
113 | [
this]( expected<zypp::ManagedFile> &&mediaInfo ) {
116 if ( mediaInfo ) _ctx->files().push_back ( std::move(mediaInfo.get()) );
118 if ( _progressObserver ) _progressObserver->inc();
122 |
and_then( [
this] ( repo::DownloadContextRef && ) {
124 zypp::Pathname contentPath = _ctx->files().front();
125 std::vector<zypp::OnMediaLocation> requiredFiles;
129 const zypp::Pathname &inputfile = contentPath;
130 zypp::parser::susetags::ContentFileReader content;
132 MIL <<
"Consuming repo index" << std::endl;
135 content.
parse( inputfile );
137 if ( ! _repoindex ) {
138 ZYPP_THROW( zypp::parser::ParseException( ( _ctx->destDir() / _ctx->repoInfo().path() ).asString() +
": " +
"No repository index in content file." ) );
141 MIL <<
"RepoIndex: " << _repoindex << std::endl;
142 if ( _repoindex->metaFileChecksums.empty() ) {
143 ZYPP_THROW( zypp::parser::ParseException( ( _ctx->destDir() / _ctx->repoInfo().path() ).asString() +
": " +
"No metadata checksums in content file." ) );
146 if ( _repoindex->signingKeys.empty() ) {
147 WAR <<
"No signing keys defined." << std::endl;
151 zypp::Pathname descr_dir = _repoindex->descrdir;
154 std::map<std::string,zypp::parser::susetags::RepoIndex::FileChecksumMap::const_iterator> availablePackageTranslations;
156 for_( it, _repoindex->metaFileChecksums.begin(), _repoindex->metaFileChecksums.end() )
161 static const zypp::str::regex rx_packages(
"^packages((.gz)?|(.([^.]*))(.gz)?)$" );
162 zypp::str::smatch what;
169 else if ( what[4] ==
"FL" )
174 availablePackageTranslations[what[4]] = it;
181 }
else if ( it->first ==
"patterns.pat"
182 || it->first ==
"patterns.pat.gz" ) {
194 std::vector<std::string> patparts;
195 unsigned archpos = 2;
197 unsigned count =
zypp::str::split( it->first, std::back_inserter(patparts),
"." );
198 if ( patparts[count-1] ==
"gz" )
201 if ( count > archpos ) {
203 zypp::Arch patarch( patparts[count-archpos] );
204 if ( !patarch.compatibleWith( zConfig().systemArchitecture() ) ) {
206 MIL <<
"Discarding pattern " << it->first << std::endl;
210 }
catch (
const zypp::Exception & excpt ) {
211 WAR <<
"Pattern file name does not contain recognizable architecture: " << it->first << std::endl;
217 MIL <<
"adding job " << it->first << std::endl;
218 auto location = zypp::OnMediaLocation( repoInfo().path() + descr_dir + it->first, 1 )
219 .setChecksum( it->second )
220 .setDeltafile( search_deltafile( _ctx->deltaDir() + descr_dir, it->first) );
222 requiredFiles.push_back( std::move(location) );
228 auto fnc_checkTransaltions( [&](
const zypp::Locale & locale_r ) {
229 for ( zypp::Locale toGet( locale_r ); toGet; toGet = toGet.fallback() ) {
230 auto it( availablePackageTranslations.find( toGet.code() ) );
231 if ( it != availablePackageTranslations.end() ) {
232 auto mit( it->second );
233 MIL <<
"adding job " << mit->first << std::endl;
234 requiredFiles.push_back( zypp::OnMediaLocation( repoInfo().path() + descr_dir + mit->first, 1 )
235 .setChecksum( mit->second )
236 .setDeltafile( search_deltafile( deltaDir() + descr_dir, mit->first) ));
242 for (
const zypp::Locale & it : zConfig().repoRefreshLocales() ) {
243 fnc_checkTransaltions( it );
245 fnc_checkTransaltions( zConfig().textLocale() );
248 for(
const auto &it : _repoindex->mediaFileChecksums ) {
250 if ( it.first !=
"license.tar.gz" )
253 MIL <<
"adding job " << it.first << std::endl;
254 requiredFiles.push_back( zypp::OnMediaLocation ( repoInfo().path() + it.first, 1 )
255 .setChecksum( it.second )
256 .setDeltafile( search_deltafile( deltaDir(), it.first ) ));
259 for(
const auto &it : _repoindex->signingKeys ) {
260 MIL <<
"adding job " << it.first << std::endl;
261 zypp::OnMediaLocation location( repoInfo().path() + it.first, 1 );
262 location.setChecksum( it.second );
263 requiredFiles.push_back( std::move(location) );
266 }
catch (
const zypp::Exception &e ) {
274 if ( _progressObserver ) _progressObserver->setBaseSteps ( _progressObserver->baseSteps () + requiredFiles.size() );
276 return transform_collect ( std::move(requiredFiles), [
this]( zypp::OnMediaLocation file ) {
281 }) |
and_then ( [
this]( std::vector<zypp::ManagedFile> &&dlFiles ) {
282 auto &downloadedFiles = _ctx->files();
283 downloadedFiles.insert( downloadedFiles.end(), std::make_move_iterator(dlFiles.begin()), std::make_move_iterator(dlFiles.end()) );
293 const zypp::RepoInfo &repoInfo()
const {
294 return _ctx->repoInfo();
297 const zypp::filesystem::Pathname &deltaDir()
const {
298 return _ctx->deltaDir();
301 zypp::ZConfig &zConfig() {
302 return _ctx->zyppContext()->config();
305 repo::DownloadContextRef _ctx;
306 zypp::parser::susetags::RepoIndex_Ptr _repoindex;
307 MediaHandle _mediaHandle;
308 ProgressObserverRef _progressObserver;
312 MaybeAwaitable<expected<repo::DownloadContextRef> >
download(repo::DownloadContextRef dl,
ProvideMediaHandle mediaHandle, ProgressObserverRef progressObserver)
314 DlLogic impl( std::move(dl), std::move(mediaHandle), std::move(progressObserver) );
315 zypp_co_return zypp_co_await( impl.execute() );