libzypp  17.38.7
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>
15 #include <zypp-core/ManagedFile.h>
16 #include <zypp-media/ng/LazyMediaHandle>
19 
20 #include <vector>
21 
22 namespace zyppng {
23  ZYPP_FWD_DECL_TYPE_WITH_REFS ( Provide );
24  DEFINE_PTR_TYPE(AttachedMediaInfo);
25 
26 
28  public:
29 
31 
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 
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:
93  // zypp::Url _resourceUrl;
95  };
96 
102  class ZYPP_API Provide : public Base
103  {
105  public:
106 
107  friend class AttachedMediaInfo;
108 
111  using Res = ProvideRes;
112 
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 
155 
156  //template <bool async>
157  //using MediaFacade = std::conditional_t<async, MediaAsyncFacade, Provide>;
158 }
159 
160 
161 
162 #endif
int assert_dir(const Pathname &path, unsigned mode)
Like &#39;mkdir -p&#39;.
Definition: PathInfo.cc:338
const zypp::ManagedFile & asManagedFile() const
Definition: provide.h:59
AttachedMediaInfo_Ptr _data
Definition: provide.h:41
#define ZYPP_ADD_CREATE_FUNC(Class)
Definition: zyppglobal.h:198
std::vector< AttachedMediaInfo_Ptr > _attachedMedia
Definition: provide.h:151
HeaderValueMap _hdrs
Definition: provide.h:94
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:66
const AttachedMediaInfo & info() const
Definition: provide.cc:142
const HeaderValueMap & headers() const
Definition: provide.h:86
DEFINE_PTR_TYPE(AttachedMediaInfo)
Manages a data source characterized by an authoritative URL and a list of mirror URLs.
Container to(Range &&range)
Convert any range into a Container.
Definition: ranges.h:109
Pathname dirname() const
Return all but the last component od this path.
Definition: Pathname.h:133
#define ZYPP_API
Definition: Globals.h:69
zypp::ManagedFile _res
Definition: provide.h:91
Provide::Res ProvideRes
Definition: provide.h:154
#define ZYPP_DECL_PRIVATE_CONSTR(Class)
Definition: zyppglobal.h:214
const zypp::Url & baseUrl() const
Definition: provide.cc:127
ZYPP_FWD_DECL_TYPE_WITH_REFS(EventDispatcher)
unsigned short a
ProvideRes Res
Definition: provide.h:111
ProvideMediaHandle _provideHandle
Definition: provide.h:92
bool provide(const Pathname &delta_r, const Pathname &new_r, const Progress &report_r)
Apply a binary delta to on-disk data to re-create a new rpm.
static auto copyResultToDest(ProvideRef provider, const zypp::Pathname &targetPath)
Definition: provide.h:139
Url manipulation class.
Definition: Url.h:92
const zypp::Pathname file() const
Definition: provide.cc:152