libzypp 17.38.15

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
17#include <zypp-curl/ng/network/curlmultiparthandler.h>
18#include <zypp-curl/ng/network/rangedesc.h>
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 ZYPP_FWD_DECL_TYPE_WITH_REFS(ZckLoader);
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 {
42 Initial,
43 DownloadLead,
44 DownloadHeader,
45 DownloadChunks,
46 Finished
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
59 Code _code;
60 std::vector<Block> _blocks;
61 zypp::ByteCount _bytesReused;
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
76 expected<void> cont();
77
81 void setFailed( const std::string &msg );
82
87 SignalProxy<void(const std::vector<Block> &)> sigBlocksRequired();
88
92 SignalProxy<void( PrepareResult )> sigFinished();
93
94
98 static zypp::ByteCount minZchunkDownloadSize();
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:
118 State _state = Initial;
119 zypp::AutoDispose<zckCtx *> _zchunkContext;
120 zypp::AutoFD _targetFd;
121 zypp::ByteCount _bytesReused = 0;
122
123 zypp::Pathname _target;
124 zypp::Pathname _delta;
125 std::optional<zypp::ByteCount> _expectedFileSize;
126 std::optional<zypp::ByteCount> _zcKHeaderSize;
127
128 Signal<void(const std::vector<Block> &)> _sigBlocksRequired;
129 Signal<void( PrepareResult )> _sigFinished;
130 };
131}
132#endif
AutoDispose.h
zypp::AutoDispose
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
Definition AutoDispose.h:95
zypp::ByteCount
Store and operate with byte count.
Definition ByteCount.h:32
zypp::Exception
Base class for Exception.
Definition Exception.h:153
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:48
zyppng::Base::Base
Base()
Definition base.cc:20
zyppng::SignalProxy
Definition signals.h:325
zyppng::Signal
Definition signals.h:151
zyppng::ZckError::ZckError
ZckError(const std::string &msg_r)
Definition zckhelper.cc:21
zyppng::ZckLoader
Definition zckhelper.h:38
zyppng::ZckLoader::prepareZck
static PrepareResult prepareZck(const zypp::Pathname &delta, const zypp::Pathname &target, const zypp::ByteCount &expectedFileSize)
Definition zckhelper.cc:322
zyppng::ZckLoader::validateZckFile
static bool validateZckFile(const zypp::Pathname &file, std::string &error)
Definition zckhelper.cc:457
zyppng::ZckLoader::setFailed
void setFailed(const std::string &msg)
Definition zckhelper.cc:279
zyppng::ZckLoader::_expectedFileSize
std::optional< zypp::ByteCount > _expectedFileSize
Definition zckhelper.h:125
zyppng::ZckLoader::buildZchunkFile
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
zyppng::ZckLoader::cont
expected< void > cont()
Definition zckhelper.cc:69
zyppng::ZckLoader::_sigFinished
Signal< void(PrepareResult)> _sigFinished
Definition zckhelper.h:129
zyppng::ZckLoader::_delta
zypp::Pathname _delta
Definition zckhelper.h:124
zyppng::ZckLoader::_bytesReused
zypp::ByteCount _bytesReused
Definition zckhelper.h:121
zyppng::ZckLoader::sigFinished
SignalProxy< void(PrepareResult)> sigFinished()
Called once the zchunk build process is finished, either with error or success.
Definition zckhelper.cc:299
zyppng::ZckLoader::_zchunkContext
zypp::AutoDispose< zckCtx * > _zchunkContext
Definition zckhelper.h:119
zyppng::ZckLoader::Block
RangeDesc Block
Definition zckhelper.h:49
zyppng::ZckLoader::_target
zypp::Pathname _target
Definition zckhelper.h:123
zyppng::ZckLoader::isZchunkFile
static bool isZchunkFile(const zypp::Pathname &file)
Definition zckhelper.cc:309
zyppng::ZckLoader::State
State
Definition zckhelper.h:41
zyppng::ZckLoader::DownloadLead
@ DownloadLead
Definition zckhelper.h:43
zyppng::ZckLoader::Finished
@ Finished
Definition zckhelper.h:46
zyppng::ZckLoader::DownloadChunks
@ DownloadChunks
Definition zckhelper.h:45
zyppng::ZckLoader::DownloadHeader
@ DownloadHeader
Definition zckhelper.h:44
zyppng::ZckLoader::Initial
@ Initial
Definition zckhelper.h:42
zyppng::ZckLoader::sigBlocksRequired
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
zyppng::ZckLoader::minZchunkDownloadSize
static zypp::ByteCount minZchunkDownloadSize()
The minimum size to download to have enough data to know the full header size.
Definition zckhelper.cc:304
zyppng::ZckLoader::_sigBlocksRequired
Signal< void(const std::vector< Block > &)> _sigBlocksRequired
Definition zckhelper.h:128
zyppng::ZckLoader::_zcKHeaderSize
std::optional< zypp::ByteCount > _zcKHeaderSize
Definition zckhelper.h:126
zyppng::ZckLoader::_targetFd
zypp::AutoFD _targetFd
Definition zckhelper.h:120
zyppng::ZckLoader::_state
State _state
Definition zckhelper.h:118
zyppng::expected
Definition expected.h:56
curlmultiparthandler.h
zypp::target
Definition KeyRing.h:325
zyppng
Definition MediaNetworkRequestExecutor.h:16
zyppng::ZYPP_FWD_DECL_TYPE_WITH_REFS
ZYPP_FWD_DECL_TYPE_WITH_REFS(EventDispatcher)
rangedesc.h
zypp::AutoFD
AutoDispose<int> calling close
Definition AutoDispose.h:310
zyppng::RangeDesc
Definition rangedesc.h:27
zyppng::ZckLoader::PrepareResult
Definition zckhelper.h:51
zyppng::ZckLoader::PrepareResult::Code
Code
Definition zckhelper.h:52
zyppng::ZckLoader::PrepareResult::ExceedsMaxLen
@ ExceedsMaxLen
Definition zckhelper.h:55
zyppng::ZckLoader::PrepareResult::Error
@ Error
Definition zckhelper.h:53
zyppng::ZckLoader::PrepareResult::Success
@ Success
Definition zckhelper.h:56
zyppng::ZckLoader::PrepareResult::NothingToDo
@ NothingToDo
Definition zckhelper.h:54
zyppng::ZckLoader::PrepareResult::_bytesReused
zypp::ByteCount _bytesReused
Definition zckhelper.h:61
zyppng::ZckLoader::PrepareResult::_code
Code _code
Definition zckhelper.h:59
zyppng::ZckLoader::PrepareResult::_blocks
std::vector< Block > _blocks
Definition zckhelper.h:60
zyppng::ZckLoader::PrepareResult::_message
std::string _message
Definition zckhelper.h:62
zckCtx
struct zckCtx zckCtx
Definition zckstream.h:18