14 #include <zypp-media/ng/Provide> 15 #include <zypp-media/ng/ProvideSpec> 16 #include <zypp/ng/Context> 17 #include <zypp/ng/repo/Downloader> 30 #undef ZYPP_BASE_LOGGER_LOGGROUP 31 #define ZYPP_BASE_LOGGER_LOGGROUP "zypp::repomanager" 38 template <
class Executor,
class OpType >
39 struct DownloadMasterIndexLogic :
public LogicBase<Executor, OpType>
45 using ZyppContextType =
typename remove_smart_ptr_t<DlContextRefType>::ContextType;
46 using ProvideType =
typename ZyppContextType::ProvideType;
47 using MediaHandle =
typename ProvideType::MediaHandle;
48 using ProvideRes =
typename ProvideType::Res;
52 ,
_media(std::move( mediaHandle ))
57 MaybeAsyncRef<expected<DlContextRefType>> execute( ) {
63 auto providerRef =
_dlContext->zyppContext()->provider();
72 | [
this]( std::vector<expected<zypp::ManagedFile>> &&res ) {
75 std::for_each( res.begin (), res.end(),
76 [
this]( expected<zypp::ManagedFile> &f){
78 _dlContext->files().push_back( std::move(f.get()));
86 |
and_then( std::bind( &DownloadMasterIndexLogic::pluginVerification,
this, std::placeholders::_1 ) )
89 |
and_then( std::bind( &DownloadMasterIndexLogic::signatureCheck,
this, std::placeholders::_1 ) )
105 allFiles.insert( allFiles.begin (), std::move(masterIndex) );
116 MaybeAsyncRef<expected<ProvideRes>> signatureCheck ( ProvideRes &&res ) {
118 if (
_dlContext->repoInfo().repoGpgCheck() ) {
125 if ( isSigned ||
_dlContext->repoInfo().repoGpgCheckIsMandatory() ) {
144 verifyCtx.keyContext(
_dlContext->repoInfo() );
146 return getExtraKeysInRepomd( std::move(res ) )
147 |
and_then([
this, vCtx = std::move(verifyCtx) ]( ProvideRes &&res )
mutable {
149 DBG <<
"Keyhint remember buddy " << keyData << std::endl;
150 vCtx.addBuddyKey( keyData.id() );
162 WAR <<
"Accept unsigned repository because repoGpgCheck is not mandatory for " <<
_dlContext->repoInfo().alias() << std::endl;
165 WAR <<
"Signature checking disabled in config of repository " <<
_dlContext->repoInfo().alias() << std::endl;
171 expected<ProvideRes> pluginVerification ( ProvideRes &&prevRes ) {
175 if (
_dlContext->pluginRepoverification() &&
_dlContext->pluginRepoverification()->isNeeded() ) {
177 _dlContext->pluginRepoverification()->getChecker( sigpathLocal, keypathLocal,
_dlContext->repoInfo() )( prevRes.file() );
189 MaybeAsyncRef<expected<ProvideRes>> getExtraKeysInRepomd ( ProvideRes &&res ) {
196 if ( keyhints.empty() )
198 DBG <<
"Check keyhints: " << keyhints.size() << std::endl;
200 auto keyRing {
_dlContext->zyppContext()->keyRing() };
202 |
transform([
this, keyRing]( std::pair<std::string, std::string> val ) {
204 const auto& [ file, keyid ] = val;
205 auto keyData = keyRing->trustedPublicKeyData( keyid );
207 DBG <<
"Keyhint is already trusted: " << keyid <<
" (" << file <<
")" << std::endl;
211 DBG <<
"Keyhint search key " << keyid <<
" (" << file <<
")" << std::endl;
213 keyData = keyRing->publicKeyData( keyid );
222 | [ keyid = keyid ](
auto &&key ){
223 if ( key.fileProvidesKey( keyid ) )
228 |
or_else ([
this, file = file, keyid = keyid, cacheFile ] (
auto )
mutable -> MaybeAsyncRef<expected<zypp::PublicKey>> {
229 auto providerRef =
_dlContext->zyppContext()->provider();
230 return providerRef->provide(
_media, file, ProvideFileSpec().setOptional(
true) )
235 _dlContext->files().push_back ( std::move(res) );
238 if ( not key.fileProvidesKey( keyid ) ) {
239 const auto &
str =
zypp::str::Str() <<
"Keyhint " << file <<
" does not contain a key with id " << keyid <<
". Skipping it.";
246 return providerRef->copyFile( key.path(), cacheFile )
247 | [ key ]( expected<zypp::ManagedFile> res )
mutable {
250 res->resetDispose ();
257 keyRing->importKey( key,
false );
261 | [
this, res = res] ( std::vector<expected<zypp::PublicKeyData>> &&keyHints )
mutable {
262 std::for_each( keyHints.begin(), keyHints.end(), [
this]( expected<zypp::PublicKeyData> &keyData ){
263 if ( keyData && *keyData ) {
265 WAR <<
"Keyhint " << keyData->id() <<
" for " << *keyData <<
" is not strong enough for auto import. Just caching it." << std::endl;
268 _buddyKeys.push_back ( std::move(keyData.get()) );
272 MIL <<
"Check keyhints done. Buddy keys: " <<
_buddyKeys.size() << std::endl;
304 return dl->zyppContext()->provider()->attachMediaIfNeeded( mediaHandle )
313 return dl->zyppContext()->provider()->attachMediaIfNeeded( mediaHandle )
321 template <
class DlContextRefType,
class MediaHandleType>
322 auto statusImpl ( DlContextRefType dlCtx, MediaHandleType &&mediaHandle ) {
324 constexpr
bool isAsync = std::is_same_v<DlContextRefType,repo::AsyncDownloadContextRef>;
330 switch( dlCtx->repoInfo().type().toEnum()) {
346 return statusImpl( dl, std::move(mediaHandle) );
350 return statusImpl( dl, std::move(mediaHandle) );
355 return dl->zyppContext()->provider()->attachMediaIfNeeded( mediaHandle )
363 return dl->zyppContext()->provider()->attachMediaIfNeeded( mediaHandle )
371 template <
class DlContextRefType,
class MediaHandleType>
372 auto downloadImpl ( DlContextRefType dlCtx, MediaHandleType &&mediaHandle, ProgressObserverRef &&progressObserver ) {
374 constexpr
bool isAsync = std::is_same_v<DlContextRefType,repo::AsyncDownloadContextRef>;
376 switch( dlCtx->repoInfo().type().toEnum()) {
378 return RpmmdWorkflows::download( std::move(dlCtx), std::forward<MediaHandleType>(mediaHandle), std::move(progressObserver) );
393 return downloadImpl( dl, std::move(mediaHandle), std::move(progressObserver) );
398 return downloadImpl( dl, std::move(mediaHandle), std::move(progressObserver) );
404 return dl->zyppContext()->provider()->attachMediaIfNeeded( mediaHandle )
406 return downloadImpl( dl, std::move(handle), std::move(po) );
413 return dl->zyppContext()->provider()->attachMediaIfNeeded( mediaHandle )
415 return downloadImpl( dl, std::move(handle), std::move(po) );
AsyncOpRef< expected< repo::AsyncDownloadContextRef > > download(repo::AsyncDownloadContextRef dl, ProvideMediaHandle mediaHandle, ProgressObserverRef progressObserver=nullptr)
boost::logic::tribool TriBool
3-state boolean logic (true, false and indeterminate).
thrown when it was impossible to determine this repo type.
auto transform(Transformation &&transformation)
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
Store and operate with byte count.
Pathname pubkeyCachePath() const
Path where the pubkey caches.
Pathname extend(const std::string &r) const
Append string r to the last component of the path.
zypp::Pathname _masterIndex
String related utilities and Regular expression matching.
zypp::TriBool _repoSigValidated
static expected< std::decay_t< Type >, Err > make_expected_success(Type &&t)
I/O context for KeyRing::verifyFileSignatureWorkflow.
static const Unit MB
1000^2 Byte
std::string basename() const
Return the last component of this path.
#define ZYPP_EXCPT_PTR(EXCPT)
Drops a logline and returns Exception as a std::exception_ptr.
Pathname repoManagerRoot() const
The RepoManager root directory.
AsyncOpRef< expected< repo::AsyncDownloadContextRef > > download(repo::AsyncDownloadContextRef dl, ProvideMediaHandle mediaHandle, ProgressObserverRef progressObserver)
auto or_else(Fun &&function)
const Pathname & signature() const
Detached signature or empty.
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...
bool isExist() const
Return whether valid stat info exists.
Pathname dirname() const
Return all but the last component od this path.
Interim helper class to collect global options and settings.
#define ZYPP_ENABLE_LOGIC_BASE(Executor, OpType)
AsyncOpRef< expected< repo::AsyncDownloadContextRef > > downloadMasterIndex(repo::AsyncDownloadContextRef dl, ProvideMediaHandle mediaHandle, zypp::filesystem::Pathname masterIndex_r)
AsyncOpRef< expected< zypp::RepoStatus > > repoStatus(repo::AsyncDownloadContextRef dl, ProvideMediaHandle mediaHandle)
DlContextRefType _dlContext
typename conditional< B, T, F >::type conditional_t
std::conditional_t< isAsync, AsyncOpRef< T >, T > makeReadyResult(T &&result)
static expected success(ConsParams &&...params)
std::shared_ptr< AsyncOp< T > > AsyncOpRef
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Reads through a repomd.xml file and collects type, location, checksum and other data about metadata f...
AsyncOpRef< expected< zypp::RepoStatus > > repoStatus(repo::AsyncDownloadContextRef dl, ProvideMediaHandle mediaHandle)
Base class for Exception.
expected< zypp::keyring::VerifyFileContext > verifySignature(SyncContextRef ctx, zypp::keyring::VerifyFileContext context)
static bool isSafeKeyId(const std::string &id_r)
!<
AsyncOpRef< expected< zypp::RepoStatus > > repoStatus(repo::AsyncDownloadContextRef dl, ProvideMediaHandle mediaHandle)
auto and_then(Fun &&function)
Wrapper class for ::stat/::lstat.
Interface of repomd.xml file reader.
AsyncOpRef< expected< repo::AsyncDownloadContextRef > > download(repo::AsyncDownloadContextRef dl, ProvideMediaHandle mediaHandle, ProgressObserverRef progressObserver)
ResultType and_then(const expected< T, E > &exp, Function &&f)
Track changing files or directories.
static PublicKey noThrow(const Pathname &keyFile_r)
Static ctor returning an empty PublicKey rather than throwing.
#define ZYPP_FWD_CURRENT_EXCPT()
Drops a logline and returns the current Exception as a std::exception_ptr.
std::vector< zypp::PublicKeyData > _buddyKeys