50 std::vector<Block> initialBlocks;
55 initialBlocks.push_back (
b);
61 initialBlocks.push_back (
b);
75 ._blocks = std::vector<Block>(),
77 ._message = std::move(message),
131 if(!zck_init_read(zck_src, src_fd)) {
150 const auto srcHashType = zck_get_chunk_hash_type(
_zchunkContext );
151 const auto targetHashType = zck_get_chunk_hash_type(
_zchunkContext );
162 if ( ftruncate (
_targetFd, fileSize ) < 0 ) {
166 if( srcHashType != targetHashType ) {
168 % zck_hash_name_from_type ( srcHashType )
169 % zck_hash_name_from_type ( targetHashType ) );
172 std::vector<Block> ranges;
178 auto bytesReused = fileSize;
188 if ( zck_get_chunk_valid( chunk ) == 1 )
192 UByteArray chksumVec = zypp::Digest::hexStringToUByteArray( std::string_view( zckDigest.
value() ) );
193 std::string chksumName;
194 std::optional<size_t> chksumCompareLen;
196 switch ( targetHashType ) {
197 case ZCK_HASH_SHA1: {
201 case ZCK_HASH_SHA256: {
205 case ZCK_HASH_SHA512: {
209 case ZCK_HASH_SHA512_128: {
213 chksumCompareLen = chksumVec.size();
221 const auto s =
static_cast<size_t>( zck_get_chunk_start( chunk ) );
222 const auto l =
static_cast<size_t>( zck_get_chunk_comp_size ( chunk ) );
224 MIL_MEDIA <<
"Downloading block " << s <<
" with length " << l <<
" checksum " << zckDigest.
value() <<
" type " << chksumName << std::endl;
225 ranges.push_back(
Block {
228 ._chksumtype = chksumName,
229 ._checksum = std::move( chksumVec ),
230 ._relevantDigestLen = std::move(chksumCompareLen)
236 }
while ( (chunk = zck_get_next_chunk( chunk )) );
251 if ( res == 0 || res == -1 ) {
252 if( zck_is_error(
nullptr) ) {
253 std::string err = zck_get_error(NULL);
254 zck_clear_error(NULL);
288 ._blocks = std::vector<Block>(),
296 return _sigBlocksRequired;
306 return zck_get_min_download_size();
310 std::ifstream dFile(file.
c_str());
311 if (!dFile.is_open())
314 constexpr std::string_view magic(
"\0ZCK1", 5);
316 std::array<char, magic.size()> lead;
318 dFile.read(lead.data(), lead.size());
319 return (magic == std::string_view(lead.data(), lead.size()));
327 ._blocks = std::vector<Block>(),
329 ._message = std::move(message),
341 if(!zck_init_read(zck_src, src_fd))
352 if(!zck_init_read(zckTarget, target_fd))
356 switch ( zck_find_valid_chunks(zckTarget) ) {
365 const auto srcHashType = zck_get_chunk_hash_type( zckTarget );
366 const auto targetHashType = zck_get_chunk_hash_type( zckTarget );
368 auto _fileSize = expectedFileSize;
370 const size_t fLen = zck_get_length( zckTarget );
371 if ( expectedFileSize > 0 ) {
373 if ( expectedFileSize != fLen ) {
376 zypp::str::Format(
"Zchunk header reports a different filesize than what was expected ( Zck: %1% != Exp: %2%).") % fLen % _fileSize
383 if( srcHashType != targetHashType )
385 % zck_hash_name_from_type ( srcHashType )
386 % zck_hash_name_from_type ( targetHashType ) );
388 std::vector<Block> ranges;
390 if(!zck_copy_chunks( zck_src, zckTarget ))
394 auto bytesReused = _fileSize;
396 auto chunk = zck_get_first_chunk( zckTarget );
399 if ( zck_get_chunk_valid( chunk ) == 1 )
403 UByteArray chksumVec = zypp::Digest::hexStringToUByteArray( std::string_view( zckDigest.
value() ) );
404 std::string chksumName;
405 std::optional<size_t> chksumCompareLen;
407 switch ( targetHashType ) {
408 case ZCK_HASH_SHA1: {
412 case ZCK_HASH_SHA256: {
416 case ZCK_HASH_SHA512: {
420 case ZCK_HASH_SHA512_128: {
424 chksumCompareLen = chksumVec.size();
432 const auto s =
static_cast<size_t>( zck_get_chunk_start( chunk ) );
433 const auto l =
static_cast<size_t>( zck_get_chunk_comp_size ( chunk ) );
435 MIL_MEDIA <<
"Downloading block " << s <<
" with length " << l <<
" checksum " << zckDigest.
value() <<
" type " << chksumName << std::endl;
436 ranges.push_back(
Block {
439 ._chksumtype = chksumName,
440 ._checksum = std::move( chksumVec ),
441 ._relevantDigestLen = std::move(chksumCompareLen)
447 }
while ( (chunk = zck_get_next_chunk( chunk )) );
451 ._blocks = std::move(ranges),
452 ._bytesReused = std::move(bytesReused),
453 ._message = std::string()
459 const auto &
setFailed = [&]( std::string &&err ) {
460 error = std::move(err);
472 if(!zck_init_read(zckTarget, target_fd))
477 const auto res = zck_validate_checksums( zckTarget );
478 if ( res == 0 || res == -1 ) {
479 if( zck_is_error(
nullptr) ) {
480 std::string err = zck_get_error(NULL);
481 zck_clear_error(NULL);
484 if( zck_is_error(zckTarget) )
485 return setFailed( zck_get_error(zckTarget) );
486 return setFailed(
"zck_validate_checksums returned a unknown error." );
static const std::string & sha256()
sha256
static const std::string & sha1()
sha1
Store and operate with byte count.
static bool isZchunkFile(const zypp::Pathname &file)
std::optional< zypp::ByteCount > _zcKHeaderSize
static bool validateZckFile(const zypp::Pathname &file, std::string &error)
zypp::AutoDispose< zckCtx * > _zchunkContext
const char * c_str() const
String representation.
expected< void > buildZchunkFile(const zypp::Pathname &target, const zypp::Pathname &delta, const std::optional< zypp::ByteCount > &expectedFileSize, const std::optional< zypp::ByteCount > &zcKHeaderSize)
static zypp::ByteCount minZchunkDownloadSize()
The minimum size to download to have enough data to know the full header size.
std::optional< zypp::ByteCount > _expectedFileSize
AutoDispose<int> calling ::close
#define ZYPP_EXCPT_PTR(EXCPT)
Drops a logline and returns Exception as a std::exception_ptr.
SignalProxy< void(PrepareResult)> sigFinished()
Called once the zchunk build process is finished, either with error or success.
ZckError(const std::string &msg_r)
Signal< void(const std::vector< Block > &)> _sigBlocksRequired
static const std::string & sha512()
sha512
void setFailed(const std::string &msg)
zypp::ByteCount _bytesReused
const std::string & asString() const
String representation.
static expected success(ConsParams &&...params)
Base class for Exception.
reference value() const
Reference to the Tp object.
zypp::ByteCount _bytesReused
SignalProxy< void(const std::vector< Block > &)> sigBlocksRequired()
Signal to notify the caller about required blocks, once the blocks are downloaded call cont to contin...
static PrepareResult prepareZck(const zypp::Pathname &delta, const zypp::Pathname &target, const zypp::ByteCount &expectedFileSize)
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
Signal< void(PrepareResult)> _sigFinished