libzypp  17.37.18
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 
14 #include <zypp-core/ManagedFile.h>
15 #include <zypp-media/ng/LazyMediaHandle>
18 
19 #include <vector>
20 
21 namespace zyppng {
22  ZYPP_FWD_DECL_TYPE_WITH_REFS ( Provide );
23  DEFINE_PTR_TYPE(AttachedMediaInfo);
24 
25 
27  public:
28 
30 
32  ProvideMediaHandle( AttachedMediaInfo_Ptr dataPtr );
33  ProvideRef parent() const;
34  bool isValid () const;
35  const zypp::Url &baseUrl() const;
36  const std::optional<zypp::Pathname> &localPath() const;
37  const AttachedMediaInfo &info ()const;
38 
39  private:
40  AttachedMediaInfo_Ptr _data;
41  };
42 
43  class ProvideRes {
44  public:
45 
47 
51  const zypp::Pathname file () const;
52 
58  const zypp::ManagedFile & asManagedFile () const {
59  return _res;
60  }
61 
65  const ProvideMediaHandle &mediaHandle () const {
66  return _provideHandle;
67  }
68 
69 #if 0
70 
71  Disabled for now so we hit a compile error, since we currently have no way to get those values from the old media backend.
72 
76  const zypp::Url &resourceUrl () const {
77  return _resourceUrl;
78  }
79 #endif
80 
85  const HeaderValueMap &headers () const {
86  return _hdrs;
87  }
88 
89  private:
92  // zypp::Url _resourceUrl;
94  };
95 
101  class ZYPP_API Provide : public Base
102  {
104  public:
105 
106  friend class AttachedMediaInfo;
107 
110  using Res = ProvideRes;
111 
113  ~Provide() override;
114 
115  expected<LazyMediaHandle> prepareMedia ( const zypp::MirroredOrigin &origin, const ProvideMediaSpec &request );
116  expected<LazyMediaHandle> prepareMedia ( const zypp::Url &url, const ProvideMediaSpec &request );
117 
118  expected<MediaHandle> attachMediaIfNeeded( LazyMediaHandle lazyHandle );
119  expected<MediaHandle> attachMedia( const zypp::MirroredOrigin &origin, const ProvideMediaSpec &request );
120  expected<MediaHandle> attachMedia( const zypp::Url &url, const ProvideMediaSpec &request );
121 
122  expected<Res> provide( const zypp::MirroredOrigin &origin, const ProvideFileSpec &request );
123  expected<Res> provide( const zypp::Url &url, const ProvideFileSpec &request );
124  expected<Res> provide( const MediaHandle &attachHandle, const zypp::Pathname &fileName, const ProvideFileSpec &request );
125  expected<Res> provide( const LazyMediaHandle &attachHandle, const zypp::Pathname &fileName, const ProvideFileSpec &request );
126 
130  expected<zypp::CheckSum> checksumForFile ( const zypp::Pathname &p, const std::string &algorithm );
131 
135  expected<zypp::ManagedFile> copyFile ( const zypp::Pathname &source, const zypp::Pathname &target );
136  expected<zypp::ManagedFile> copyFile ( Res source, const zypp::Pathname &target );
137 
138  static auto copyResultToDest ( ProvideRef provider, const zypp::Pathname &targetPath ) {
139  return [ providerRef=std::move(provider), targetPath = targetPath ]( Res &&file ){
140  zypp::filesystem::assert_dir( targetPath.dirname () );
141  return providerRef->copyFile( std::move(file), targetPath );
142  };
143  }
144 
145  protected:
146  void releaseMedium ( const AttachedMediaInfo *ptr );
147 
148  private:
149  zypp::MirroredOrigin sanitizeUrls(const zypp::MirroredOrigin &origin) const;
150  std::vector<AttachedMediaInfo_Ptr> _attachedMedia;
151  };
152 
154 
155  //template <bool async>
156  //using MediaFacade = std::conditional_t<async, MediaAsyncFacade, Provide>;
157 }
158 
159 
160 
161 #endif
int assert_dir(const Pathname &path, unsigned mode)
Like &#39;mkdir -p&#39;.
Definition: PathInfo.cc:324
const zypp::ManagedFile & asManagedFile() const
Definition: provide.h:58
AttachedMediaInfo_Ptr _data
Definition: provide.h:40
#define ZYPP_ADD_CREATE_FUNC(Class)
Definition: zyppglobal.h:205
std::vector< AttachedMediaInfo_Ptr > _attachedMedia
Definition: provide.h:150
HeaderValueMap _hdrs
Definition: provide.h:93
ProvideRef parent() const
Definition: provide.cc:117
ProvideRes(ProvideMediaHandle hdl, zypp::ManagedFile file)
Definition: provide.cc:147
const std::optional< zypp::Pathname > & localPath() const
Definition: provide.cc:134
const ProvideMediaHandle & mediaHandle() const
Definition: provide.h:65
const AttachedMediaInfo & info() const
Definition: provide.cc:142
const HeaderValueMap & headers() const
Definition: provide.h:85
DEFINE_PTR_TYPE(AttachedMediaInfo)
Manages a data source characterized by an authoritative URL and a list of mirror URLs.
Pathname dirname() const
Return all but the last component od this path.
Definition: Pathname.h:126
#define ZYPP_API
Definition: Globals.h:69
zypp::ManagedFile _res
Definition: provide.h:90
Provide::Res ProvideRes
Definition: provide.h:153
#define ZYPP_DECL_PRIVATE_CONSTR(Class)
Definition: zyppglobal.h:221
const zypp::Url & baseUrl() const
Definition: provide.cc:127
ZYPP_FWD_DECL_TYPE_WITH_REFS(EventDispatcher)
unsigned short a
ProvideRes Res
Definition: provide.h:110
ProvideMediaHandle _provideHandle
Definition: provide.h:91
static auto copyResultToDest(ProvideRef provider, const zypp::Pathname &targetPath)
Definition: provide.h:138
Url manipulation class.
Definition: Url.h:92
const zypp::Pathname file() const
Definition: provide.cc:152