libzypp: zypp/ng/media/provide.h Source File

libzypp 17.38.6

provide.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
9#ifndef ZYPP_NG_MEDIASETFACADE_INCLUDED
10#define ZYPP_NG_MEDIASETFACADE_INCLUDED
11
12#include <zypp-core/ng/base/base.h>
13#include <zypp-core/base/PtrTypes.h>
14#include <zypp-core/MirroredOrigin.h>
15#include <zypp-core/ManagedFile.h>
16#include <zypp-media/ng/LazyMediaHandle>
17#include <zypp/media/MediaManager.h>
18#include <zypp-core/ng/pipelines/expected.h>
19
20#include <vector>
21
22namespace zyppng {
23 ZYPP_FWD_DECL_TYPE_WITH_REFS ( Provide );
24 DEFINE_PTR_TYPE(AttachedMediaInfo);
25
26
27 class ProvideMediaHandle {
28 public:
29
30 using ParentType = Provide;
31
32 ProvideMediaHandle();
33 ProvideMediaHandle( AttachedMediaInfo_Ptr dataPtr );
34 ProvideRef parent() const;
35 bool isValid () const;
36 const zypp::Url &baseUrl() const;
37 const std::optional<zypp::Pathname> &localPath() const;
38 const AttachedMediaInfo &info ()const;
39
40 private:
41 AttachedMediaInfo_Ptr _data;
42 };
43
44 class ProvideRes {
45 public:
46
47 ProvideRes( ProvideMediaHandle hdl, zypp::ManagedFile file );
48
52 const zypp::Pathname file () const;
53
59 const zypp::ManagedFile & asManagedFile () const {
60 return _res;
61 }
62
66 const ProvideMediaHandle &mediaHandle () const {
67 return _provideHandle;
68 }
69
70#if 0
71
72 Disabled for now so we hit a compile error, since we currently have no way to get those values from the old media backend.
73
77 const zypp::Url &resourceUrl () const {
78 return _resourceUrl;
79 }
80#endif
81
86 const HeaderValueMap &headers () const {
87 return _hdrs;
88 }
89
90 private:
91 zypp::ManagedFile _res;
92 ProvideMediaHandle _provideHandle;
93 // zypp::Url _resourceUrl;
94 HeaderValueMap _hdrs;
95 };
96
102 class ZYPP_API Provide : public Base
103 {
104 ZYPP_ADD_CREATE_FUNC(Provide)
105 public:
106
107 friend class AttachedMediaInfo;
108
109 using MediaHandle = ProvideMediaHandle;
110 using LazyMediaHandle = ::zyppng::LazyMediaHandle<Provide>;
111 using Res = ProvideRes;
112
113 ZYPP_DECL_PRIVATE_CONSTR ( Provide );
114 ~Provide() override;
115
116 expected<LazyMediaHandle> prepareMedia ( const zypp::MirroredOrigin &origin, const ProvideMediaSpec &request );
117 expected<LazyMediaHandle> prepareMedia ( const zypp::Url &url, const ProvideMediaSpec &request );
118
119 expected<MediaHandle> attachMediaIfNeeded( LazyMediaHandle lazyHandle );
120 expected<MediaHandle> attachMedia( const zypp::MirroredOrigin &origin, const ProvideMediaSpec &request );
121 expected<MediaHandle> attachMedia( const zypp::Url &url, const ProvideMediaSpec &request );
122
123 expected<Res> provide( const zypp::MirroredOrigin &origin, const ProvideFileSpec &request );
124 expected<Res> provide( const zypp::Url &url, const ProvideFileSpec &request );
125 expected<Res> provide( const MediaHandle &attachHandle, const zypp::Pathname &fileName, const ProvideFileSpec &request );
126 expected<Res> provide( const LazyMediaHandle &attachHandle, const zypp::Pathname &fileName, const ProvideFileSpec &request );
127
131 expected<zypp::CheckSum> checksumForFile ( const zypp::Pathname &p, const std::string &algorithm );
132
136 expected<zypp::ManagedFile> copyFile ( const zypp::Pathname &source, const zypp::Pathname &target );
137 expected<zypp::ManagedFile> copyFile ( Res source, const zypp::Pathname &target );
138
139 static auto copyResultToDest ( ProvideRef provider, const zypp::Pathname &targetPath ) {
140 return [ providerRef=std::move(provider), targetPath = targetPath ]( Res &&file ){
141 zypp::filesystem::assert_dir( targetPath.dirname () );
142 return providerRef->copyFile( std::move(file), targetPath );
143 };
144 }
145
146 protected:
147 void releaseMedium ( const AttachedMediaInfo *ptr );
148
149 private:
150 zypp::MirroredOrigin sanitizeUrls(const zypp::MirroredOrigin &origin) const;
151 std::vector<AttachedMediaInfo_Ptr> _attachedMedia;
152 };
153
154 using ProvideRes = Provide::Res;
155
156 //template <bool async>
157 //using MediaFacade = std::conditional_t<async, MediaAsyncFacade, Provide>;
158}
159
160
161
162#endif
MediaManager.h
MirroredOrigin.h
PtrTypes.h
DEFINE_PTR_TYPE
#define DEFINE_PTR_TYPE(NAME)
Forward declaration of Ptr types.
Definition PtrTypes.h:639
base.h
zypp::MirroredOrigin
Manages a data source characterized by an authoritative URL and a list of mirror URLs.
Definition MirroredOrigin.h:170
zypp::Url
Url manipulation class.
Definition Url.h:93
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:48
zypp::filesystem::Pathname::dirname
Pathname dirname() const
Return all but the last component od this path.
Definition Pathname.h:133
zyppng::AttachedMediaInfo
Definition provide.cc:25
zyppng::Base::Base
Base()
Definition base.cc:20
zyppng::HeaderValueMap
Definition headervaluemap.h:67
zyppng::LazyMediaHandle
Definition lazymediahandle.h:20
zyppng::ProvideFileSpec
Definition providespec.h:95
zyppng::ProvideMediaHandle
Definition provide.h:27
zyppng::ProvideMediaHandle::ParentType
Provide ParentType
Definition provide.h:30
zyppng::ProvideMediaHandle::baseUrl
const zypp::Url & baseUrl() const
Definition provide.cc:127
zyppng::ProvideMediaHandle::isValid
bool isValid() const
Definition provide.cc:122
zyppng::ProvideMediaHandle::localPath
const std::optional< zypp::Pathname > & localPath() const
Definition provide.cc:134
zyppng::ProvideMediaHandle::parent
ProvideRef parent() const
Definition provide.cc:117
zyppng::ProvideMediaHandle::info
const AttachedMediaInfo & info() const
Definition provide.cc:142
zyppng::ProvideMediaHandle::_data
AttachedMediaInfo_Ptr _data
Definition provide.h:41
zyppng::ProvideMediaHandle::ProvideMediaHandle
ProvideMediaHandle()
Definition provide.cc:112
zyppng::ProvideMediaSpec
Definition providespec.h:30
zyppng::ProvideRes
Definition provide.h:44
zyppng::ProvideRes::headers
const HeaderValueMap & headers() const
Definition provide.h:86
zyppng::ProvideRes::ProvideRes
ProvideRes(ProvideMediaHandle hdl, zypp::ManagedFile file)
Definition provide.cc:147
zyppng::ProvideRes::file
const zypp::Pathname file() const
Definition provide.cc:152
zyppng::ProvideRes::_provideHandle
ProvideMediaHandle _provideHandle
Definition provide.h:92
zyppng::ProvideRes::_res
zypp::ManagedFile _res
Definition provide.h:91
zyppng::ProvideRes::mediaHandle
const ProvideMediaHandle & mediaHandle() const
Definition provide.h:66
zyppng::ProvideRes::_hdrs
HeaderValueMap _hdrs
Definition provide.h:94
zyppng::ProvideRes::asManagedFile
const zypp::ManagedFile & asManagedFile() const
Definition provide.h:59
zyppng::Provide
Definition provide.h:103
zyppng::Provide::ZYPP_DECL_PRIVATE_CONSTR
ZYPP_DECL_PRIVATE_CONSTR(Provide)
zyppng::Provide::checksumForFile
expected< zypp::CheckSum > checksumForFile(const zypp::Pathname &p, const std::string &algorithm)
Definition provide.cc:509
zyppng::Provide::attachMedia
expected< MediaHandle > attachMedia(const zypp::MirroredOrigin &origin, const ProvideMediaSpec &request)
Definition provide.cc:188
zyppng::Provide::prepareMedia
expected< LazyMediaHandle > prepareMedia(const zypp::MirroredOrigin &origin, const ProvideMediaSpec &request)
Definition provide.cc:391
zyppng::Provide::AttachedMediaInfo
friend class AttachedMediaInfo
Definition provide.h:107
zyppng::Provide::Res
ProvideRes Res
Definition provide.h:111
zyppng::Provide::copyFile
expected< zypp::ManagedFile > copyFile(const zypp::Pathname &source, const zypp::Pathname &target)
Definition provide.cc:518
zyppng::Provide::provide
expected< Res > provide(const zypp::MirroredOrigin &origin, const ProvideFileSpec &request)
Definition provide.cc:419
zyppng::Provide::copyResultToDest
static auto copyResultToDest(ProvideRef provider, const zypp::Pathname &targetPath)
Definition provide.h:139
zyppng::Provide::LazyMediaHandle
::zyppng::LazyMediaHandle< Provide > LazyMediaHandle
Definition provide.h:110
zyppng::Provide::_attachedMedia
std::vector< AttachedMediaInfo_Ptr > _attachedMedia
Definition provide.h:151
zyppng::Provide::attachMediaIfNeeded
expected< MediaHandle > attachMediaIfNeeded(LazyMediaHandle lazyHandle)
Definition provide.cc:404
zyppng::Provide::MediaHandle
ProvideMediaHandle MediaHandle
Definition provide.h:109
zyppng::expected
Definition expected.h:56
expected.h
a
unsigned short a
Definition mediablocklist.cc:0
zypp::filesystem::assert_dir
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
Definition PathInfo.cc:338
zypp::media
Definition MediaNetworkRequestExecutor.h:22
zypp::target
Definition KeyRing.h:325
zypp::url
Url details namespace.
Definition UrlBase.cc:58
zypp::ManagedFile
AutoDispose< const Pathname > ManagedFile
A Pathname plus associated cleanup code to be executed when path is no longer needed.
Definition ManagedFile.h:27
zypp::ZYPP_API
const Arch Arch_empty ZYPP_API
relates: Arch This is an empty Arch represented by an empty string.
Definition Arch.h:173
zyppng
Definition MediaNetworkRequestExecutor.h:16
zyppng::ProvideRes
Provide::Res ProvideRes
Definition provide.h:154
ManagedFile.h
ZYPP_ADD_CREATE_FUNC
#define ZYPP_ADD_CREATE_FUNC(Class)
Definition zyppglobal.h:198
ZYPP_FWD_DECL_TYPE_WITH_REFS
#define ZYPP_FWD_DECL_TYPE_WITH_REFS(T)
Definition zyppglobal.h:119