libzypp  17.38.7
zckhelper.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 ----------------------------------------------------------------------/
9 *
10 * This file contains private API, this might break at any time between releases.
11 * You have been warned!
12 *
13 */
14 #ifndef ZYPPNG_CURL_ZCKHELPER_H_INCLUDED
15 #define ZYPPNG_CURL_ZCKHELPER_H_INCLUDED
16 
19 
20 #include <zypp-core/AutoDispose.h>
21 #include <zypp-core/ng/base/Base>
22 
23 extern "C" {
24  typedef struct zckCtx zckCtx;
25 }
26 
27 namespace zyppng {
28 
30 
31  class ZckError : public zypp::Exception
32  {
33  public:
34  ZckError( const std::string & msg_r );
35  ZckError( std::string && msg_r );
36  };
37 
38  class ZckLoader : public Base {
39  public:
40 
41  enum State {
47  };
48 
49  using Block = RangeDesc;
50 
51  struct PrepareResult {
52  enum Code {
53  Error, // we got an error
54  NothingToDo, // Target file is already complete
55  ExceedsMaxLen, // Zchunk header reports a different filesize than what was expected
56  Success // Returns a list of blocks to fetch
57  };
58 
60  std::vector<Block> _blocks;
62  std::string _message;
63  };
64 
65 
70  expected<void> buildZchunkFile( const zypp::Pathname &target, const zypp::Pathname &delta, const std::optional<zypp::ByteCount> &expectedFileSize, const std::optional<zypp::ByteCount> &zcKHeaderSize );
71 
77 
81  void setFailed( const std::string &msg );
82 
88 
93 
94 
99 
103  static bool isZchunkFile(const zypp::Pathname &file);
104 
109  static PrepareResult prepareZck ( const zypp::Pathname &delta, const zypp::Pathname &target, const zypp::ByteCount &expectedFileSize );
110 
114  static bool validateZckFile( const zypp::Pathname &file, std::string &error );
115 
116 
117  private:
122 
125  std::optional<zypp::ByteCount> _expectedFileSize;
126  std::optional<zypp::ByteCount> _zcKHeaderSize;
127 
130  };
131 }
132 #endif
std::vector< Block > _blocks
Definition: zckhelper.h:60
struct zckCtx zckCtx
Definition: zckstream.h:18
Store and operate with byte count.
Definition: ByteCount.h:31
static bool isZchunkFile(const zypp::Pathname &file)
Definition: zckhelper.cc:309
std::optional< zypp::ByteCount > _zcKHeaderSize
Definition: zckhelper.h:126
static bool validateZckFile(const zypp::Pathname &file, std::string &error)
Definition: zckhelper.cc:457
zypp::AutoDispose< zckCtx * > _zchunkContext
Definition: zckhelper.h:119
expected< void > buildZchunkFile(const zypp::Pathname &target, const zypp::Pathname &delta, const std::optional< zypp::ByteCount > &expectedFileSize, const std::optional< zypp::ByteCount > &zcKHeaderSize)
Definition: zckhelper.cc:27
static zypp::ByteCount minZchunkDownloadSize()
The minimum size to download to have enough data to know the full header size.
Definition: zckhelper.cc:304
std::optional< zypp::ByteCount > _expectedFileSize
Definition: zckhelper.h:125
AutoDispose<int> calling ::close
Definition: AutoDispose.h:309
SignalProxy< void(PrepareResult)> sigFinished()
Called once the zchunk build process is finished, either with error or success.
Definition: zckhelper.cc:299
ZckError(const std::string &msg_r)
Definition: zckhelper.cc:21
zypp::Pathname _delta
Definition: zckhelper.h:124
Signal< void(const std::vector< Block > &)> _sigBlocksRequired
Definition: zckhelper.h:128
void setFailed(const std::string &msg)
Definition: zckhelper.cc:279
zypp::ByteCount _bytesReused
Definition: zckhelper.h:121
zypp::Pathname _target
Definition: zckhelper.h:123
Base class for Exception.
Definition: Exception.h:152
zypp::ByteCount _bytesReused
Definition: zckhelper.h:61
ZYPP_FWD_DECL_TYPE_WITH_REFS(EventDispatcher)
SignalProxy< void(const std::vector< Block > &)> sigBlocksRequired()
Signal to notify the caller about required blocks, once the blocks are downloaded call cont to contin...
Definition: zckhelper.cc:294
static PrepareResult prepareZck(const zypp::Pathname &delta, const zypp::Pathname &target, const zypp::ByteCount &expectedFileSize)
Definition: zckhelper.cc:322
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
Definition: AutoDispose.h:94
Signal< void(PrepareResult)> _sigFinished
Definition: zckhelper.h:129
zypp::AutoFD _targetFd
Definition: zckhelper.h:120
expected< void > cont()
Definition: zckhelper.cc:69