libzypp  17.37.5
mediafacade.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 
13 #include <zypp-media/ng/Provide>
14 #include <zypp-media/ng/LazyMediaHandle>
15 #include <zypp/MediaSetAccess.h>
17 
18 
19 #include <vector>
20 
21 namespace zyppng {
22  ZYPP_FWD_DECL_TYPE_WITH_REFS ( MediaSyncFacade );
23  DEFINE_PTR_TYPE(AttachedSyncMediaInfo);
24 
25 
27  public:
28 
30 
32  SyncMediaHandle( AttachedSyncMediaInfo_Ptr dataPtr );
33  MediaSyncFacadeRef parent() const;
34  bool isValid () const;
35  const zypp::Url &baseUrl() const;
36  const std::optional<zypp::Pathname> &localPath() const;
37  const AttachedSyncMediaInfo &info ()const;
38 
39  private:
40  AttachedSyncMediaInfo_Ptr _data;
41  };
42 
48  class ZYPP_API MediaSyncFacade : public Base
49  {
51  public:
52 
53  friend class AttachedSyncMediaInfo;
54 
57 
58  class Res {
59  public:
60 
61  Res( MediaHandle hdl, zypp::ManagedFile file );
62 
66  const zypp::Pathname file () const;
67 
73  const zypp::ManagedFile & asManagedFile () const {
74  return _res;
75  }
76 
77  private:
80  };
81 
83  ~MediaSyncFacade() override;
84 
85  expected<LazyMediaHandle> prepareMedia ( const std::vector<zypp::Url> &urls, const ProvideMediaSpec &request );
86  expected<LazyMediaHandle> prepareMedia ( const zypp::Url &url, const ProvideMediaSpec &request );
87 
88  expected<MediaHandle> attachMediaIfNeeded( LazyMediaHandle lazyHandle );
89  expected<MediaHandle> attachMedia( const std::vector<zypp::Url> &urls, const ProvideMediaSpec &request );
90  expected<MediaHandle> attachMedia( const zypp::Url &url, const ProvideMediaSpec &request );
91 
92  expected<Res> provide( const std::vector<zypp::Url> &urls, const ProvideFileSpec &request );
93  expected<Res> provide( const zypp::Url &url, const ProvideFileSpec &request );
94  expected<Res> provide( const MediaHandle &attachHandle, const zypp::Pathname &fileName, const ProvideFileSpec &request );
95  expected<Res> provide( const LazyMediaHandle &attachHandle, const zypp::Pathname &fileName, const ProvideFileSpec &request );
96 
97 
101  expected<zypp::CheckSum> checksumForFile ( const zypp::Pathname &p, const std::string &algorithm );
102 
106  expected<zypp::ManagedFile> copyFile ( const zypp::Pathname &source, const zypp::Pathname &target );
107  expected<zypp::ManagedFile> copyFile ( Res source, const zypp::Pathname &target );
108 
109  static auto copyResultToDest ( MediaSyncFacadeRef provider, const zypp::Pathname &targetPath ) {
110  return [ providerRef=std::move(provider), targetPath = targetPath ]( Res &&file ){
111  zypp::filesystem::assert_dir( targetPath.dirname () );
112  return providerRef->copyFile( std::move(file), targetPath );
113  };
114  }
115 
116  protected:
117  void releaseMedium ( const AttachedSyncMediaInfo *ptr );
118 
119  private:
120  std::vector<zypp::Url> sanitizeUrls(const std::vector<zypp::Url> &urls) const;
121  std::vector<AttachedSyncMediaInfo_Ptr> _attachedMedia;
122  };
123 
125 
126  //template <bool async>
127  //using MediaFacade = std::conditional_t<async, MediaAsyncFacade, MediaSyncFacade>;
128 }
129 
130 
131 
132 #endif
int assert_dir(const Pathname &path, unsigned mode)
Like &#39;mkdir -p&#39;.
Definition: PathInfo.cc:324
zypp::ManagedFile _res
Definition: mediafacade.h:78
const zypp::Url & baseUrl() const
Definition: mediafacade.cc:141
#define ZYPP_API
Definition: Globals.h:69
DEFINE_PTR_TYPE(AttachedSyncMediaInfo)
#define ZYPP_ADD_CREATE_FUNC(Class)
Definition: zyppglobal.h:205
const zypp::ManagedFile & asManagedFile() const
Definition: mediafacade.h:73
AttachedSyncMediaInfo_Ptr _data
Definition: mediafacade.h:40
Pathname dirname() const
Return all but the last component od this path.
Definition: Pathname.h:126
static auto copyResultToDest(MediaSyncFacadeRef provider, const zypp::Pathname &targetPath)
Definition: mediafacade.h:109
MediaSyncFacadeRef parent() const
Definition: mediafacade.cc:131
const AttachedSyncMediaInfo & info() const
Definition: mediafacade.cc:157
#define ZYPP_DECL_PRIVATE_CONSTR(Class)
Definition: zyppglobal.h:221
ZYPP_FWD_DECL_TYPE_WITH_REFS(EventDispatcher)
const std::optional< zypp::Pathname > & localPath() const
Definition: mediafacade.cc:149
std::vector< AttachedSyncMediaInfo_Ptr > _attachedMedia
Definition: mediafacade.h:121
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.
Url manipulation class.
Definition: Url.h:92