libzypp  17.37.18
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 
29  class ZckError : public zypp::Exception
30  {
31  public:
32  ZckError( const std::string & msg_r );
33  ZckError( std::string && msg_r );
34  };
35 
36  class ZckLoader : public Base {
37  public:
38 
39  enum State {
45  };
46 
47  using Block = RangeDesc;
48 
49  struct PrepareResult {
50  enum Code {
51  Error, // we got an error
52  NothingToDo, // Target file is already complete
53  ExceedsMaxLen, // Zchunk header reports a different filesize than what was expected
54  Success // Returns a list of blocks to fetch
55  };
56 
58  std::vector<Block> _blocks;
60  std::string _message;
61  };
62 
63 
68  expected<void> buildZchunkFile( const zypp::Pathname &target, const zypp::Pathname &delta, const std::optional<zypp::ByteCount> &expectedFileSize, const std::optional<zypp::ByteCount> &zcKHeaderSize );
69 
75 
79  void setFailed( const std::string &msg );
80 
86 
91 
92 
97 
101  static bool isZchunkFile(const zypp::Pathname &file);
102 
107  static PrepareResult prepareZck ( const zypp::Pathname &delta, const zypp::Pathname &target, const zypp::ByteCount &expectedFileSize );
108 
112  static bool validateZckFile( const zypp::Pathname &file, std::string &error );
113 
114 
115  private:
120 
123  std::optional<zypp::ByteCount> _expectedFileSize;
124  std::optional<zypp::ByteCount> _zcKHeaderSize;
125 
128  };
129 }
130 #endif
std::vector< Block > _blocks
Definition: zckhelper.h:58
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:124
static bool validateZckFile(const zypp::Pathname &file, std::string &error)
Definition: zckhelper.cc:457
zypp::AutoDispose< zckCtx * > _zchunkContext
Definition: zckhelper.h:117
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:123
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:122
Signal< void(const std::vector< Block > &)> _sigBlocksRequired
Definition: zckhelper.h:126
void setFailed(const std::string &msg)
Definition: zckhelper.cc:279
zypp::ByteCount _bytesReused
Definition: zckhelper.h:119
zypp::Pathname _target
Definition: zckhelper.h:121
Base class for Exception.
Definition: Exception.h:152
zypp::ByteCount _bytesReused
Definition: zckhelper.h:59
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:127
zypp::AutoFD _targetFd
Definition: zckhelper.h:118
expected< void > cont()
Definition: zckhelper.cc:69