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)
546 const char *
s =
getenv(name.c_str());
547 return s && *
s ?
true :
false;
583 XXX <<
"checking DNS lookup of " << host << endl;
592 if (
_pid == pid_t(-1))
646 return ( waitfd.fd == _dnspipe && waitfd.revents != 0 );
701 size_t cnt =
l >
sizeof(
buf) ?
sizeof(
buf) :
l;
726 std::optional<zypp::Digest> digest;
739 return MultiByteHandler::Range::make(
753 XXX <<
"start stealing!" << endl;
767 if (worker->
_pass == -1)
823 XXX <<
"best #" <<
best->_workerno <<
": " <<
best->_avgspeed <<
", size " << (
best->_datasize -
best->_datareceived) << endl;
831 double sl = (
best->_datasize -
best->_datareceived) /
best->_avgspeed * 2;
834 XXX <<
"#" <<
_workerno <<
": going to sleep for " <<
sl * 1000 <<
" ms" << endl;
843 best->_competing =
true;
911 DBG <<
"#" <<
_workerno <<
"Done adding blocks to download, going to download: " <<
_blocks.size() <<
" nr of block with " <<
_datasize <<
" nr of bytes" << std::endl;
975 , _filename(
std::move(filename))
980 , _filesize(filesize)
982 , _timeout(
context->_settings.timeout())
983 , _connect_timeout(
context->_settings.connectTimeout())
984 , _maxspeed(
context->_settings.maxDownloadSpeed())
985 , _maxworkers(
context->_settings.maxConcurrentConnections())
1044 XXX <<
"finished!" << endl;
1068 WAR <<
"No more active workers!" << endl;
1081 (*workeriter)->adddnsfd(
waitFds );
1120 (*workeriter)->dnsevent(
waitFds );
1163 XXX <<
"#" << worker->
_workerno <<
": sleep done, wake up" << endl;
1196 if ( !
str.empty () )
1207 WAR <<
"#" << worker->
_workerno <<
": has no multibyte handler, this is a bug" << endl;
1217 WAR <<
"#" << worker->
_workerno <<
": still has work to do or can recover from a error, continuing the job!" << endl;
1234 WAR <<
"#" << worker->
_workerno <<
": failed, but was set to discard, reusing for new requests" << endl;
1257 if ( s != Stripe::FINALIZED)
1258 s = Stripe::PENDING;
1313#if CURLVERSION_AT_LEAST(7,15,5)
1346 WAR <<
"overall result" << endl;
1384 std::map<std::string, CURL *>::iterator
it;
1406 for (;
sl;
sl =
sl->next)
1439 std::string
ct = std::string(
ptr);
1440 if (
ct.find(
"application/x-zsync") == 0 ||
ct.find(
"application/metalink+xml") == 0 ||
ct.find(
"application/metalink4+xml") == 0)
1469 if( assert_dir(
dest.dirname() ) )
1471 DBG <<
"assert_dir " <<
dest.dirname() <<
" failed" << endl;
1481 ERR <<
"out of memory for temp file name" << endl;
1488 ERR <<
"mkstemp failed for file '" <<
destNew <<
"'" << endl;
1493 file = ::fdopen(
tmp_fd,
"we" );
1496 ERR <<
"fopen failed for file '" <<
destNew <<
"'" << endl;
1502 DBG <<
"dest: " <<
dest << endl;
1551 WAR <<
"Could not get the response code." << endl;
1559 std::string
ct = std::string(
ptr);
1560 if (
ct.find(
"application/x-zsync") == 0 )
1562 else if (
ct.find(
"application/metalink+xml") == 0 ||
ct.find(
"application/metalink4+xml") == 0)
1582 std::vector<Url> urls;
1593 bl =
mlp.getBlockList();
1594 urls =
mlp.getUrls();
1602 XXX <<
"With no blocks" << std::endl;
1609 XXX <<
"No filesize in metalink file and no expected filesize, aborting multicurl." << std::endl;
1625 file =
fopen((*destNew).c_str(),
"w+e");
1630 XXX <<
"reusing blocks from file " << target << endl;
1644 XXX <<
"reusing blocks from file " << df << endl;
1665 WAR<<
"Failed to multifetch file " <<
ex <<
" falling back to single Curl download!" << std::endl;
1675 file =
fopen((*destNew).c_str(),
"w+e");
1687 ERR <<
"Failed to chmod file " <<
destNew << endl;
1694 ERR <<
"Fclose failed for file '" <<
destNew <<
"'" << endl;
1700 ERR <<
"Rename failed" << endl;
1711 if (filesize == off_t(-1) &&
blklist.haveFilesize())
1712 filesize =
blklist.getFilesize();
1713 if (!
blklist.haveBlocks() && filesize != 0) {
1714 if ( filesize == -1 ) {
1719 MIL <<
"Generate blocklist, since there was none in the metalink file." << std::endl;
1724 while (
currOff < filesize ) {
1726 auto blksize = filesize -
currOff ;
1734 XXX <<
"Generated blocklist: " << std::endl <<
blklist << std::endl <<
" End blocklist " << std::endl;
1737 if (filesize == 0 || !
blklist.numBlocks()) {
1757 std::string scheme =
urliter->getScheme();
1758 if (scheme ==
"http" || scheme ==
"https" || scheme ==
"ftp" || scheme ==
"tftp")
1776 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::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.
auto eintrSafeCall(Fun &&function, Args &&... args)
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.