103#include <sys/types.h>
112#include <zypp-core/base/Logger.h>
113#include <zypp-core/base/String.h>
114#include <zypp-core/AutoDispose.h>
115#include <zypp-core/base/Exception.h>
125 unsigned short a = 0;
126 unsigned short b = 0;
132 unsigned short a = 0;
133 unsigned short b = 0;
136 unsigned char c = *data++;
145 #define UPDATE_RSUM(a, b, oldc, newc, bshift) do { (a) += ((unsigned char)(newc)) - ((unsigned char)(oldc)); (b) += (a) - ((oldc) << (bshift)); } while (0)
301 s = (
rs >> 16) & 65535;
303 for (; len > 0 ; len--)
305 unsigned short c = (
unsigned char)*
bytes++;
309 return (
s & 65535) << 16 | (
m & 65535);
323 s = (
rs >> 16) & 65535;
326 rs = (
s & 65535) << 16 | (
m & 65535);
385 size_t len =
bufl - start > size ? size :
bufl - start;
386 dig.update((
const char *)
buf + start, len);
388 dig.update((
const char *)
buf, size - len);
404 size_t len =
bufl - start > size ? size :
bufl - start;
407 if (size > len &&
fwrite(
buf, size - len, 1,
fp) != 1)
445 DBG <<
"Delta XFER: Can not reuse blocks because we have no chksumlen" << std::endl;
449 if ( (
fp =
fopen(filename.c_str(),
"r")) == 0 ) {
450 DBG <<
"Delta XFER: Can not reuse blocks, unable to open file "<< filename << std::endl;
466 for ( std::size_t
i = 0;
i <
rsums.size();
i++ ) {
469 s = (
rs >> 16) & 65535;
475 const auto &
calc_rhash = [&](
const rsum*
e ) ->
unsigned {
487 size_t blksize =
blocks[0].size;
498 while ((2 << (
i - 1)) >
nblks &&
i > 4)
510 for (
size_t id = 0;
id <
nblks;
id++) {
537 if ((blksize & (blksize - 1)) == 0)
692 const auto blkOff = (
i*blksize );
706 auto buf = std::make_unique<unsigned char[]>(
bufl );
715 buf = std::make_unique<unsigned char[]>(
bufl );
734 DBG <<
"Delta XFER: No reusable blocks found for " << filename << std::endl;
738 std::vector<MediaBlock>
nblocks;
739 std::vector<unsigned char>
nchksums;
740 std::vector<unsigned int>
nrsums;
762 DBG <<
"Delta XFER: Found blocks to reuse, " <<
blocks.size() <<
" vs " <<
nblocks.size() <<
", resused blocks: " <<
blocks.size() -
nblocks.size() <<
"\n"
775 DBG <<
"Delta XFER: Can not reuse blocks because we have no chksumlen" << std::endl;
779 if ( (
fp =
fopen(filename.c_str(),
"r")) == 0 ) {
780 DBG <<
"Delta XFER: Can not reuse blocks, unable to open file "<< filename << std::endl;
784 std::vector<bool>
found;
788 size_t blksize =
blocks[0].size;
797 unsigned int hm =
rsums.size() * 2;
798 while (
hm & (
hm - 1)) {
812 for (
unsigned int i = 0;
i <
rsums.size();
i++)
817 unsigned int h =
r &
hm;
830 auto ringBuf = std::make_unique<unsigned char[]>( blksize );
833 auto buf2 = std::make_unique<unsigned char[]>( blksize );
844 if ((blksize & (blksize - 1)) == 0)
862 for (
size_t i = 0;
i < blksize;
i++)
909 if (
size_t(
i) != blksize - 1)
914 unsigned int r = ((
unsigned int)
a & 65535) << 16 | ((
unsigned int)
b & 65535);
917 unsigned int h =
r &
hm;
998 auto buf = std::make_unique<unsigned char[]>(
bufl );
1007 buf = std::make_unique<unsigned char[]>(
bufl );
1026 DBG <<
"Delta XFER: No reusable blocks found for " << filename << std::endl;
1030 std::vector<MediaBlock>
nblocks;
1031 std::vector<unsigned char>
nchksums;
1032 std::vector<unsigned int>
nrsums;
1054 DBG <<
"Delta XFER: Found blocks to reuse, " <<
blocks.size() <<
" vs " <<
nblocks.size() <<
", resused blocks: " <<
blocks.size() -
nblocks.size() <<
"\n"
1073 s =
"[ BlockList, filesize unknown\n";
1075 s +=
" No block information\n";
1083 long long size=
blocks[
i].size;
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
void reset()
Reset to default Ctor values.
Compute Message Digests (MD5, SHA1 etc)
UByteArray digestVector()
get vector of unsigned char representation of the digest
bool update(const char *bytes, size_t len)
feed data into digest computation algorithm
bool create(const std::string &name)
initialize creation of a new message digest
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Easy-to use interface to the ZYPP dependency resolver.
AutoDispose<FILE*> calling ::fclose