libzypp 17.38.15

rpmmd.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
9#include "rpmmd.h"
10#include <zypp/repo/RepoException.h>
11#include <zypp-core/ng/ui/ProgressObserver>
12#include <zypp-media/ng/ProvideSpec>
13#include <zypp/ng/Context>
14
15
16#include <zypp/ng/repo/workflows/repodownloaderwf.h>
17#include <zypp/parser/yum/RepomdFileReader.h>
18#include <zypp/repo/yum/RepomdFileCollector.h>
19#include <zypp/ng/workflows/checksumwf.h>
20
21#undef ZYPP_BASE_LOGGER_LOGGROUP
22#define ZYPP_BASE_LOGGER_LOGGROUP "zypp::repomanager"
23
24 namespace zyppng::RpmmdWorkflows {
25
26 namespace {
27
28 using namespace zyppng::operators;
29
30 struct StatusLogic {
31
32 public:
33 using MediaHandle = typename Provide::MediaHandle;
34 using ProvideRes = typename Provide::Res;
35
36 StatusLogic( repo::DownloadContextRef ctx, MediaHandle &&media )
37 : _ctx(std::move(ctx))
38 , _handle(std::move(media))
39 {}
40
41 MaybeAwaitable<expected<zypp::RepoStatus>> execute() {
42 return _ctx->zyppContext()->provider()->provide( _handle, _ctx->repoInfo().path() / "/repodata/repomd.xml" , ProvideFileSpec().setMirrorsAllowed(false) )
43 | [this]( expected<ProvideRes> repomdFile ) {
44
45 if ( !repomdFile )
46 return makeReadyTask( make_expected_success (zypp::RepoStatus() ));
47
48 zypp::RepoStatus status ( repomdFile->file() );
49
50 if ( !status.empty() && _ctx->repoInfo ().requireStatusWithMediaFile()) {
51 return _ctx->zyppContext()->provider()->provide( _handle, "/media.1/media" , ProvideFileSpec().setMirrorsAllowed(false) )
52 | [status = std::move(status)]( expected<ProvideRes> mediaFile ) mutable {
53 if ( mediaFile ) {
54 return make_expected_success( status && zypp::RepoStatus( mediaFile->file()) );
55 }
56 return make_expected_success( std::move(status) );
57 };
58 }
59 return makeReadyTask( make_expected_success(std::move(status)) );
60 };
61 }
62
63 repo::DownloadContextRef _ctx;
64 MediaHandle _handle;
65 };
66 }
67
68 MaybeAwaitable<expected<zypp::RepoStatus> > repoStatus( repo::DownloadContextRef dl, ProvideMediaHandle mediaHandle)
69 {
70 StatusLogic impl( std::move(dl), std::move(mediaHandle) );
71 zypp_co_return zypp_co_await( impl.execute() );
72 }
73
74
75 namespace {
76
77 using namespace zyppng::operators;
78
79 struct DlLogic : private zypp::repo::yum::RepomdFileCollector {
80
81 public:
82 using MediaHandle = typename Provide::MediaHandle;
83 using ProvideRes = typename Provide::Res;
84
85 DlLogic( repo::DownloadContextRef ctx, MediaHandle &&mediaHandle, ProgressObserverRef &&progressObserver )
86 : zypp::repo::yum::RepomdFileCollector( ctx->destDir() )
87 , _ctx( std::move(ctx))
88 , _mediaHandle(std::move(mediaHandle))
89 , _progressObserver(std::move(progressObserver))
90 {}
91
92 auto execute() {
93 // download media file here
94 return RepoDownloaderWorkflow::downloadMediaInfo( _mediaHandle, _ctx->destDir() )
95 | [this]( expected<zypp::ManagedFile> &&mediaInfo ) {
96
97 // remember the media info if we had one
98 if ( mediaInfo ) _ctx->files().push_back ( std::move(mediaInfo.get()) );
99
100 if ( _progressObserver ) _progressObserver->inc();
101
102 return RepoDownloaderWorkflow::downloadMasterIndex( _ctx, _mediaHandle, _ctx->repoInfo().path() / "/repodata/repomd.xml" )
103 | inspect( incProgress( _progressObserver ) )
104 | and_then( [this] ( repo::DownloadContextRef && ) {
105
106 zypp::Pathname repomdPath = _ctx->files().front();
107 std::vector<zypp::OnMediaLocation> requiredFiles;
108 try {
109 zypp::parser::yum::RepomdFileReader reader( repomdPath, [this]( const zypp::OnMediaLocation & loc_r, const std::string & typestr_r ){ return collect( loc_r, typestr_r ); });
110 finalize([&]( const zypp::OnMediaLocation &file ){
111 if ( file.medianr () != 1 ) {
112 // ALL repo files NEED to come from media nr 1 , otherwise we fail
113 ZYPP_THROW(zypp::repo::RepoException( _ctx->repoInfo(), "Repo can only require metadata files from primary medium."));
114 }
115 requiredFiles.push_back( file );
116 });
117 } catch ( ... ) {
118 return makeReadyTask(expected< repo::DownloadContextRef>::error( ZYPP_FWD_CURRENT_EXCPT() ) );
119 }
120
121 // add the required files to the base steps
122 if ( _progressObserver ) _progressObserver->setBaseSteps ( _progressObserver->baseSteps () + requiredFiles.size() );
123
124 return transform_collect ( std::move(requiredFiles), [this]( zypp::OnMediaLocation file ) {
125
126 return DownloadWorkflow::provideToCacheDir( _ctx, _mediaHandle, file.filename(), ProvideFileSpec(file) )
127 | inspect ( incProgress( _progressObserver ) );
128
129 }) | and_then ( [this]( std::vector<zypp::ManagedFile> &&dlFiles ) {
130 auto &downloadedFiles = _ctx->files();
131 downloadedFiles.insert( downloadedFiles.end(), std::make_move_iterator(dlFiles.begin()), std::make_move_iterator(dlFiles.end()) );
132 return expected< repo::DownloadContextRef>::success( std::move(_ctx) );
133 });
134 });
135
136 } | finishProgress( _progressObserver );
137 }
138
139 private:
140
141 const zypp::RepoInfo &repoInfo() const override {
142 return _ctx->repoInfo();
143 }
144
145 const zypp::filesystem::Pathname &deltaDir() const override {
146 return _ctx->deltaDir();
147 }
148
149 repo::DownloadContextRef _ctx;
150 MediaHandle _mediaHandle;
151 ProgressObserverRef _progressObserver;
152 };
153 }
154
155 MaybeAwaitable<expected< repo::DownloadContextRef> > download( repo::DownloadContextRef dl, ProvideMediaHandle mediaHandle, ProgressObserverRef progressObserver)
156 {
157 DlLogic impl( std::move(dl), std::move(mediaHandle), std::move(progressObserver) );
158 zypp_co_return zypp_co_await( impl.execute() );
159 }
160
161
162}
ZYPP_FWD_CURRENT_EXCPT
#define ZYPP_FWD_CURRENT_EXCPT()
Drops a logline and returns the current Exception as a std::exception_ptr.
Definition Exception.h:471
ZYPP_THROW
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition Exception.h:459
RepoException.h
RepomdFileCollector.h
RepomdFileReader.h
Interface of repomd.xml file reader.
checksumwf.h
zypp::OnMediaLocation
Describes a resource file located on a medium.
Definition onmedialocation.h:37
zypp::OnMediaLocation::filename
const Pathname & filename() const
The path to the resource on the medium.
Definition onmedialocation.cc:90
zypp::OnMediaLocation::medianr
unsigned medianr() const
The media number the resource is located on.
Definition onmedialocation.cc:93
zypp::RepoStatus
Track changing files or directories.
Definition RepoStatus.h:41
zypp::RepoStatus::empty
bool empty() const
Whether the status is empty (empty checksum).
Definition RepoStatus.cc:234
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:48
zypp::parser::yum::RepomdFileReader
Reads through a repomd.xml file and collects type, location, checksum and other data about metadata f...
Definition RepomdFileReader.h:39
zyppng::ProvideFileSpec
Definition providespec.h:95
zyppng::ProvideFileSpec::ProvideFileSpec
ProvideFileSpec()
Definition providespec.cc:192
zyppng::ProvideMediaHandle
Definition provide.h:27
zyppng::ProvideRes
Definition provide.h:44
zyppng::Provide::Res
ProvideRes Res
Definition provide.h:111
zyppng::Provide::MediaHandle
ProvideMediaHandle MediaHandle
Definition provide.h:109
zyppng::expected
Definition expected.h:56
zyppng::expected::success
static expected success(ConsParams &&...params)
Definition expected.h:178
zyppng::expected::error
E & error()
Definition expected.h:288
std
Definition ansi.h:855
zypp::media
Definition MediaNetworkRequestExecutor.h:22
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
zyppng::DownloadWorkflow::provideToCacheDir
MaybeAwaitable< expected< zypp::ManagedFile > > provideToCacheDir(CacheProviderContextRef cacheContext, ProvideMediaHandle medium, zypp::Pathname file, ProvideFileSpec filespec)
Definition downloadwf.cc:192
zyppng::RepoDownloaderWorkflow::downloadMediaInfo
auto downloadMediaInfo(MediaHandle &&mediaHandle, const zypp::filesystem::Pathname &destdir)
Definition repodownloaderwf.h:41
zyppng::RepoDownloaderWorkflow::downloadMasterIndex
MaybeAwaitable< expected< repo::DownloadContextRef > > downloadMasterIndex(repo::DownloadContextRef dl, ProvideMediaHandle mediaHandle, zypp::filesystem::Pathname masterIndex_r)
Definition repodownloaderwf.cc:426
zyppng::RpmmdWorkflows
Downloader workspace for YUM (rpm-nmd) repositories Encapsulates all the knowledge of which files hav...
Definition rpmmd.cc:24
zyppng::RpmmdWorkflows::download
MaybeAwaitable< expected< repo::DownloadContextRef > > download(repo::DownloadContextRef dl, ProvideMediaHandle mediaHandle, ProgressObserverRef progressObserver)
Definition rpmmd.cc:155
zyppng::RpmmdWorkflows::repoStatus
MaybeAwaitable< expected< zypp::RepoStatus > > repoStatus(repo::DownloadContextRef dl, ProvideMediaHandle mediaHandle)
Definition rpmmd.cc:68
zyppng::operators
Definition expected.h:699
zyppng::operators::transform_collect
auto transform_collect(Transformation &&f)
Definition expected.h:778
zyppng::operators::and_then
auto and_then(Fun &&function)
Definition expected.h:708
zyppng::operators::finishProgress
auto finishProgress(ProgressObserverRef progressObserver, ProgressObserver::FinishResult result=ProgressObserver::Success)
Definition progressobserver.h:252
zyppng::operators::collect
detail::collect_helper collect()
Definition expected.h:735
zyppng::operators::incProgress
auto incProgress(ProgressObserverRef progressObserver, double progrIncrease=1.0, std::optional< std::string > newStr={})
Definition progressobserver.h:229
zyppng::operators::inspect
auto inspect(Fun &&function)
Definition expected.h:722
zyppng::repo
Definition downloader.cc:22
repodownloaderwf.h
rpmmd.h
zypp::repo::yum::RepomdFileCollector
Helper filtering the files offered by a RepomdFileReader.
Definition RepomdFileCollector.h:25