libzypp  17.32.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/MediaSetAccess.h>
16 
17 
18 #include <vector>
19 
20 namespace zyppng {
21  ZYPP_FWD_DECL_TYPE_WITH_REFS ( MediaSyncFacade );
22  DEFINE_PTR_TYPE(AttachedSyncMediaInfo);
23 
24 
26  public:
27 
29 
31  SyncMediaHandle( AttachedSyncMediaInfo_Ptr dataPtr );
32  MediaSyncFacadeRef parent() const;
33  bool isValid () const;
34  const zypp::Url &baseUrl() const;
35  const std::optional<zypp::Pathname> &localPath() const;
36  const AttachedSyncMediaInfo &info ()const;
37 
38  private:
39  AttachedSyncMediaInfo_Ptr _data;
40  };
41 
47  class MediaSyncFacade : public Base
48  {
50  public:
51 
52  friend class AttachedSyncMediaInfo;
53 
55 
56  class Res {
57  public:
58 
60 
64  const zypp::Pathname file () const;
65 
71  const zypp::ManagedFile & asManagedFile () const {
72  return _res;
73  }
74 
75  private:
78  };
79 
81  ~MediaSyncFacade() override;
82 
83  expected<MediaHandle> attachMedia( const std::vector<zypp::Url> &urls, const ProvideMediaSpec &request );
84  expected<MediaHandle> attachMedia( const zypp::Url &url, const ProvideMediaSpec &request );
85 
86  expected<Res> provide( const std::vector<zypp::Url> &urls, const ProvideFileSpec &request );
87  expected<Res> provide( const zypp::Url &url, const ProvideFileSpec &request );
88  expected<Res> provide( const MediaHandle &attachHandle, const zypp::Pathname &fileName, const ProvideFileSpec &request );
89 
90 
94  expected<zypp::CheckSum> checksumForFile ( const zypp::Pathname &p, const std::string &algorithm );
95 
99  expected<zypp::ManagedFile> copyFile ( const zypp::Pathname &source, const zypp::Pathname &target );
100  expected<zypp::ManagedFile> copyFile ( Res source, const zypp::Pathname &target );
101 
102  static auto copyResultToDest ( MediaSyncFacadeRef provider, const zypp::Pathname &targetPath ) {
103  return [ providerRef=std::move(provider), targetPath = targetPath ]( Res &&file ){
104  zypp::filesystem::assert_dir( targetPath.dirname () );
105  return providerRef->copyFile( std::move(file), targetPath );
106  };
107  }
108 
109  protected:
110  void releaseMedium ( const AttachedSyncMediaInfo *ptr );
111 
112  private:
113  std::vector<AttachedSyncMediaInfo_Ptr> _attachedMedia;
114  };
115 
117 
118  //template <bool async>
119  //using MediaFacade = std::conditional_t<async, MediaAsyncFacade, MediaSyncFacade>;
120 }
121 
122 
123 
124 #endif
int assert_dir(const Pathname &path, unsigned mode)
Like &#39;mkdir -p&#39;.
Definition: PathInfo.cc:320
Res(MediaHandle hdl, zypp::ManagedFile file)
Definition: mediafacade.cc:140
zypp::ManagedFile _res
Definition: mediafacade.h:76
const zypp::Url & baseUrl() const
Definition: mediafacade.cc:119
expected< Res > provide(const std::vector< zypp::Url > &urls, const ProvideFileSpec &request)
Definition: mediafacade.cc:222
DEFINE_PTR_TYPE(AttachedSyncMediaInfo)
expected< zypp::ManagedFile > copyFile(const zypp::Pathname &source, const zypp::Pathname &target)
Definition: mediafacade.cc:309
const zypp::ManagedFile & asManagedFile() const
Definition: mediafacade.h:71
AttachedSyncMediaInfo_Ptr _data
Definition: mediafacade.h:39
ZYPP_DECL_PRIVATE_CONSTR(MediaSyncFacade)
ZYPP_FWD_DECL_TYPE_WITH_REFS(Context)
Pathname dirname() const
Return all but the last component od this path.
Definition: Pathname.h:124
static auto copyResultToDest(MediaSyncFacadeRef provider, const zypp::Pathname &targetPath)
Definition: mediafacade.h:102
MediaSyncFacadeRef parent() const
Definition: mediafacade.cc:109
ZYPP_ADD_CREATE_FUNC(MediaSyncFacade)
expected< MediaHandle > attachMedia(const std::vector< zypp::Url > &urls, const ProvideMediaSpec &request)
Definition: mediafacade.cc:151
void releaseMedium(const AttachedSyncMediaInfo *ptr)
Definition: mediafacade.cc:340
const AttachedSyncMediaInfo & info() const
Definition: mediafacade.cc:135
const std::optional< zypp::Pathname > & localPath() const
Definition: mediafacade.cc:127
const zypp::Pathname file() const
Definition: mediafacade.cc:145
std::vector< AttachedSyncMediaInfo_Ptr > _attachedMedia
Definition: mediafacade.h:113
expected< zypp::CheckSum > checksumForFile(const zypp::Pathname &p, const std::string &algorithm)
Definition: mediafacade.cc:300
Url manipulation class.
Definition: Url.h:91