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 );
1124 (*workeriter)->dnsevent(
waitFds );
1171 XXX <<
"#" << worker->
_workerno <<
": sleep done, wake up" << endl;
1204 if ( !
str.empty () )
1215 WAR <<
"#" << worker->
_workerno <<
": has no multibyte handler, this is a bug" << endl;
1225 WAR <<
"#" << worker->
_workerno <<
": still has work to do or can recover from a error, continuing the job!" << endl;
1242 WAR <<
"#" << worker->
_workerno <<
": failed, but was set to discard, reusing for new requests" << endl;
1265 if ( s != Stripe::FINALIZED)
1266 s = Stripe::PENDING;
1321#if CURLVERSION_AT_LEAST(7,15,5)
1354 WAR <<
"overall result" << endl;
1392 std::map<std::string, CURL *>::iterator
it;
1414 for (;
sl;
sl =
sl->next)
1447 std::string
ct = std::string(
ptr);
1448 if (
ct.find(
"application/x-zsync") == 0 ||
ct.find(
"application/metalink+xml") == 0 ||
ct.find(
"application/metalink4+xml") == 0)
1477 if( assert_dir(
dest.dirname() ) )
1479 DBG <<
"assert_dir " <<
dest.dirname() <<
" failed" << endl;
1489 ERR <<
"out of memory for temp file name" << endl;
1496 ERR <<
"mkstemp failed for file '" <<
destNew <<
"'" << endl;
1501 file = ::fdopen(
tmp_fd,
"we" );
1504 ERR <<
"fopen failed for file '" <<
destNew <<
"'" << endl;
1510 DBG <<
"dest: " <<
dest << endl;
1559 WAR <<
"Could not get the response code." << endl;
1567 std::string
ct = std::string(
ptr);
1568 if (
ct.find(
"application/x-zsync") == 0 )
1570 else if (
ct.find(
"application/metalink+xml") == 0 ||
ct.find(
"application/metalink4+xml") == 0)
1590 std::vector<Url> urls;
1601 bl =
mlp.getBlockList();
1602 urls =
mlp.getUrls();
1610 XXX <<
"With no blocks" << std::endl;
1617 XXX <<
"No filesize in metalink file and no expected filesize, aborting multicurl." << std::endl;
1633 file =
fopen((*destNew).c_str(),
"w+e");
1638 XXX <<
"reusing blocks from file " << target << endl;
1652 XXX <<
"reusing blocks from file " << df << endl;
1673 WAR<<
"Failed to multifetch file " <<
ex <<
" falling back to single Curl download!" << std::endl;
1683 file =
fopen((*destNew).c_str(),
"w+e");
1695 ERR <<
"Failed to chmod file " <<
destNew << endl;
1702 ERR <<
"Fclose failed for file '" <<
destNew <<
"'" << endl;
1708 ERR <<
"Rename failed" << endl;
1719 if (filesize == off_t(-1) &&
blklist.haveFilesize())
1720 filesize =
blklist.getFilesize();
1721 if (!
blklist.haveBlocks() && filesize != 0) {
1722 if ( filesize == -1 ) {
1727 MIL <<
"Generate blocklist, since there was none in the metalink file." << std::endl;
1732 while (
currOff < filesize ) {
1734 auto blksize = filesize -
currOff ;
1742 XXX <<
"Generated blocklist: " << std::endl <<
blklist << std::endl <<
" End blocklist " << std::endl;
1745 if (filesize == 0 || !
blklist.numBlocks()) {
1765 std::string scheme =
urliter->getScheme();
1766 if (scheme ==
"http" || scheme ==
"https" || scheme ==
"ftp" || scheme ==
"tftp")
1784 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.