33#include <zypp-curl/parser/MetaLinkParser>
36#include <zypp-curl/auth/CurlAuthData>
43#undef CURLVERSION_AT_LEAST
44#define CURLVERSION_AT_LEAST(M,N,O) LIBCURL_VERSION_NUM >= ((((M)<<8)+(N))<<8)+(O)
266 std::list< std::unique_ptr<multifetchworker> >
_workers;
319#if _POSIX_C_SOURCE >= 199309L
323 return ts.tv_sec +
ts.tv_nsec / 1000000000.;
328 return tv.tv_sec +
tv.tv_usec / 1000000.;
336 return bytes ? 0 : 1;
359 off_t seekTo =
blk.start +
blk.bytesWritten;
364 return bytes ? 0 : 1;
379 cancelReason =
"Cancelled because stripe block is already finalized";
424 std::string
line(
p + 9,
l - 9);
425 if (
line[
l - 10] ==
'\r')
426 line.erase(
l - 10, 1);
433 XXX <<
"#" <<
_workerno <<
": filesize mismatch" << endl;
445, _maxspeed(
request._maxspeed )
452 XXX <<
"reused worker from pool" << endl;
497 <<
" (CURLOPT_HTTPAUTH=" <<
auth <<
")" << std::endl;
513#if CURLVERSION_AT_LEAST(7,15,5)
548 const char *
s =
getenv(name.c_str());
549 return s && *
s ?
true :
false;
585 XXX <<
"checking DNS lookup of " << host << endl;
594 if (
_pid == pid_t(-1))
648 return ( waitfd.fd == _dnspipe && waitfd.revents != 0 );
707 size_t cnt =
l >
sizeof(
buf) ?
sizeof(
buf) :
l;
732 std::optional<zypp::Digest> digest;
745 return MultiByteHandler::Range::make(
759 XXX <<
"start stealing!" << endl;
773 if (worker->
_pass == -1)
829 XXX <<
"best #" <<
best->_workerno <<
": " <<
best->_avgspeed <<
", size " << (
best->_datasize -
best->_datareceived) << endl;
837 double sl = (
best->_datasize -
best->_datareceived) /
best->_avgspeed * 2;
840 XXX <<
"#" <<
_workerno <<
": going to sleep for " <<
sl * 1000 <<
" ms" << endl;
849 best->_competing =
true;
917 DBG <<
"#" <<
_workerno <<
"Done adding blocks to download, going to download: " <<
_blocks.size() <<
" nr of block with " <<
_datasize <<
" nr of bytes" << std::endl;
981 , _filename(
std::move(filename))
986 , _filesize(filesize)
988 , _timeout(
context->_settings.timeout())
989 , _connect_timeout(
context->_settings.connectTimeout())
990 , _maxspeed(
context->_settings.maxDownloadSpeed())
991 , _maxworkers(
context->_settings.maxConcurrentConnections())
1050 XXX <<
"finished!" << endl;
1074 WAR <<
"No more active workers!" << endl;
1087 (*workeriter)->adddnsfd(
waitFds );
1126 (*workeriter)->dnsevent(
waitFds );
1169 XXX <<
"#" << worker->
_workerno <<
": sleep done, wake up" << endl;
1202 if ( !
str.empty () )
1213 WAR <<
"#" << worker->
_workerno <<
": has no multibyte handler, this is a bug" << endl;
1223 WAR <<
"#" << worker->
_workerno <<
": still has work to do or can recover from a error, continuing the job!" << endl;
1240 WAR <<
"#" << worker->
_workerno <<
": failed, but was set to discard, reusing for new requests" << endl;
1263 if ( s != Stripe::FINALIZED)
1264 s = Stripe::PENDING;
1319#if CURLVERSION_AT_LEAST(7,15,5)
1352 WAR <<
"overall result" << endl;
1390 std::map<std::string, CURL *>::iterator
it;
1412 for (;
sl;
sl =
sl->next)
1445 std::string
ct = std::string(
ptr);
1446 if (
ct.find(
"application/x-zsync") == 0 ||
ct.find(
"application/metalink+xml") == 0 ||
ct.find(
"application/metalink4+xml") == 0)
1475 if( assert_dir(
dest.dirname() ) )
1477 DBG <<
"assert_dir " <<
dest.dirname() <<
" failed" << endl;
1487 ERR <<
"out of memory for temp file name" << endl;
1494 ERR <<
"mkstemp failed for file '" <<
destNew <<
"'" << endl;
1499 file = ::fdopen(
tmp_fd,
"we" );
1502 ERR <<
"fopen failed for file '" <<
destNew <<
"'" << endl;
1508 DBG <<
"dest: " <<
dest << endl;
1557 WAR <<
"Could not get the response code." << endl;
1565 std::string
ct = std::string(
ptr);
1566 if (
ct.find(
"application/x-zsync") == 0 )
1568 else if (
ct.find(
"application/metalink+xml") == 0 ||
ct.find(
"application/metalink4+xml") == 0)
1588 std::vector<Url> urls;
1599 bl =
mlp.getBlockList();
1600 urls =
mlp.getUrls();
1608 XXX <<
"With no blocks" << std::endl;
1615 XXX <<
"No filesize in metalink file and no expected filesize, aborting multicurl." << std::endl;
1631 file =
fopen((*destNew).c_str(),
"w+e");
1636 XXX <<
"reusing blocks from file " << target << endl;
1650 XXX <<
"reusing blocks from file " << df << endl;
1671 WAR<<
"Failed to multifetch file " <<
ex <<
" falling back to single Curl download!" << std::endl;
1681 file =
fopen((*destNew).c_str(),
"w+e");
1693 ERR <<
"Failed to chmod file " <<
destNew << endl;
1700 ERR <<
"Fclose failed for file '" <<
destNew <<
"'" << endl;
1706 ERR <<
"Rename failed" << endl;
1717 if (filesize == off_t(-1) &&
blklist.haveFilesize())
1718 filesize =
blklist.getFilesize();
1719 if (!
blklist.haveBlocks() && filesize != 0) {
1720 if ( filesize == -1 ) {
1725 MIL <<
"Generate blocklist, since there was none in the metalink file." << std::endl;
1730 while (
currOff < filesize ) {
1732 auto blksize = filesize -
currOff ;
1740 XXX <<
"Generated blocklist: " << std::endl <<
blklist << std::endl <<
" End blocklist " << std::endl;
1743 if (filesize == 0 || !
blklist.numBlocks()) {
1763 std::string scheme =
urliter->getScheme();
1764 if (scheme ==
"http" || scheme ==
"https" || scheme ==
"ftp" || scheme ==
"tftp")
1782 if ( !
blklist.haveFileChecksum() )
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
reference value() const
Reference to the Tp object.
void resetDispose()
Set no dispose function.
Store and operate with byte count.
static const Unit MB
1000^2 Byte
static const Unit K
1024 Byte
std::string asString(unsigned field_width_r=0, unsigned unit_width_r=1) const
Auto selected Unit and precision.
Compute Message Digests (MD5, SHA1 etc)
Base class for Exception.
std::string getScheme() const
Returns the scheme name of the URL.
std::string getHost(EEncoding eflag=zypp::url::E_DECODED) const
Returns the hostname or IP from the URL authority.
static ZConfig & instance()
Singleton ctor.
Wrapper class for stat/lstat.
Pathname extend(const std::string &r) const
Append string r to the last component of the path.
const std::string & asString() const
String representation.
Pathname absolutename() const
Return this path, adding a leading '/' if relative.
The CurlMultiPartHandler class.
zypp::callback::SendReport< zypp::KeyRingReport > _report
zypp::Url propagateQueryParams(zypp::Url url_r, const zypp::Url &template_r)
String related utilities and Regular expression matching.
mode_t applyUmaskTo(mode_t mode_r)
Modify mode_r according to the current umask ( mode_r & ~getUmask() ).
int hardlinkCopy(const Pathname &oldpath, const Pathname &newpath)
Create newpath as hardlink or copy of oldpath.
int unlink(const Pathname &path)
Like 'unlink'.
std::string numstring(char n, int w=0)
int zypp_poll(std::vector< GPollFD > &fds, int timeout)
Small wrapper around g_poll that additionally listens to the shutdown FD returned by ZYpp::shutdownSi...
Easy-to use interface to the ZYPP dependency resolver.
AutoDispose< const Pathname > ManagedFile
A Pathname plus associated cleanup code to be executed when path is no longer needed.
AutoDispose<int> calling ::close
AutoDispose<FILE*> calling ::fclose
#define ZYPP_RETHROW(EXCPT)
Drops a logline and rethrows, updating the CodeLocation.
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.