26#include <zypp/ManagedFile.h>
28#include <zypp/base/Logger.h>
31#include <zypp-core/zyppng/base/private/linuxhelpers_p.h>
32#include <zypp-curl/parser/MetaLinkParser>
35#include <zypp-curl/auth/CurlAuthData>
42#undef CURLVERSION_AT_LEAST
43#define CURLVERSION_AT_LEAST(M,N,O) LIBCURL_VERSION_NUM >= ((((M)<<8)+(N))<<8)+(O)
254 std::list< std::unique_ptr<multifetchworker> >
_workers;
293#if _POSIX_C_SOURCE >= 199309L
297 return ts.tv_sec +
ts.tv_nsec / 1000000000.;
302 return tv.tv_sec +
tv.tv_usec / 1000000.;
310 return bytes ? 0 : 1;
333 off_t seekTo =
blk.start +
blk.bytesWritten;
338 return bytes ? 0 : 1;
353 cancelReason =
"Cancelled because stripe block is already finalized";
398 std::string
line(
p + 9,
l - 9);
399 if (
line[
l - 10] ==
'\r')
400 line.erase(
l - 10, 1);
407 XXX <<
"#" <<
_workerno <<
": filesize mismatch" << endl;
419, _maxspeed(
request._maxspeed )
426 XXX <<
"reused worker from pool" << endl;
471 <<
" (CURLOPT_HTTPAUTH=" <<
auth <<
")" << std::endl;
487#if CURLVERSION_AT_LEAST(7,15,5)
522 const char *
s =
getenv(name.c_str());
523 return s && *
s ?
true :
false;
559 XXX <<
"checking DNS lookup of " << host << endl;
568 if (
_pid == pid_t(-1))
622 return ( waitfd.fd == _dnspipe && waitfd.revents != 0 );
681 size_t cnt =
l >
sizeof(
buf) ?
sizeof(
buf) :
l;
706 std::optional<zypp::Digest> digest;
719 return MultiByteHandler::Range::make(
733 XXX <<
"start stealing!" << endl;
747 if (worker->
_pass == -1)
803 XXX <<
"best #" <<
best->_workerno <<
": " <<
best->_avgspeed <<
", size " << (
best->_datasize -
best->_datareceived) << endl;
811 double sl = (
best->_datasize -
best->_datareceived) /
best->_avgspeed * 2;
814 XXX <<
"#" <<
_workerno <<
": going to sleep for " <<
sl * 1000 <<
" ms" << endl;
823 best->_competing =
true;
891 DBG <<
"#" <<
_workerno <<
"Done adding blocks to download, going to download: " <<
_blocks.size() <<
" nr of block with " <<
_datasize <<
" nr of bytes" << std::endl;
955 , _filename(filename)
960 , _filesize(filesize)
962 , _timeout(
context->_settings.timeout())
963 , _connect_timeout(
context->_settings.connectTimeout())
964 , _maxspeed(
context->_settings.maxDownloadSpeed())
965 , _maxworkers(
context->_settings.maxConcurrentConnections())
1024 XXX <<
"finished!" << endl;
1048 WAR <<
"No more active workers!" << endl;
1061 (*workeriter)->adddnsfd(
waitFds );
1100 (*workeriter)->dnsevent(
waitFds );
1143 XXX <<
"#" << worker->
_workerno <<
": sleep done, wake up" << endl;
1176 if ( !
str.empty () )
1187 WAR <<
"#" << worker->
_workerno <<
": has no multibyte handler, this is a bug" << endl;
1197 WAR <<
"#" << worker->
_workerno <<
": still has work to do or can recover from a error, continuing the job!" << endl;
1214 WAR <<
"#" << worker->
_workerno <<
": failed, but was set to discard, reusing for new requests" << endl;
1237 if ( s != Stripe::FINALIZED)
1238 s = Stripe::PENDING;
1293#if CURLVERSION_AT_LEAST(7,15,5)
1326 WAR <<
"overall result" << endl;
1362 std::map<std::string, CURL *>::iterator
it;
1384 for (;
sl;
sl =
sl->next)
1417 std::string
ct = std::string(
ptr);
1418 if (
ct.find(
"application/x-zsync") == 0 ||
ct.find(
"application/metalink+xml") == 0 ||
ct.find(
"application/metalink4+xml") == 0)
1447 if( assert_dir(
dest.dirname() ) )
1449 DBG <<
"assert_dir " <<
dest.dirname() <<
" failed" << endl;
1459 ERR <<
"out of memory for temp file name" << endl;
1466 ERR <<
"mkstemp failed for file '" <<
destNew <<
"'" << endl;
1471 file = ::fdopen(
tmp_fd,
"we" );
1474 ERR <<
"fopen failed for file '" <<
destNew <<
"'" << endl;
1480 DBG <<
"dest: " <<
dest << endl;
1529 WAR <<
"Could not get the response code." << endl;
1537 std::string
ct = std::string(
ptr);
1538 if (
ct.find(
"application/x-zsync") == 0 )
1540 else if (
ct.find(
"application/metalink+xml") == 0 ||
ct.find(
"application/metalink4+xml") == 0)
1560 std::vector<Url> urls;
1571 bl =
mlp.getBlockList();
1572 urls =
mlp.getUrls();
1580 XXX <<
"With no blocks" << std::endl;
1587 XXX <<
"No filesize in metalink file and no expected filesize, aborting multicurl." << std::endl;
1603 file =
fopen((*destNew).c_str(),
"w+e");
1608 XXX <<
"reusing blocks from file " << target << endl;
1622 XXX <<
"reusing blocks from file " << df << endl;
1643 WAR<<
"Failed to multifetch file " <<
ex <<
" falling back to single Curl download!" << std::endl;
1653 file =
fopen((*destNew).c_str(),
"w+e");
1665 ERR <<
"Failed to chmod file " <<
destNew << endl;
1672 ERR <<
"Fclose failed for file '" <<
destNew <<
"'" << endl;
1678 ERR <<
"Rename failed" << endl;
1689 if (filesize == off_t(-1) &&
blklist.haveFilesize())
1690 filesize =
blklist.getFilesize();
1691 if (!
blklist.haveBlocks() && filesize != 0) {
1692 if ( filesize == -1 ) {
1697 MIL <<
"Generate blocklist, since there was none in the metalink file." << std::endl;
1702 while (
currOff < filesize ) {
1704 auto blksize = filesize -
currOff ;
1712 XXX <<
"Generated blocklist: " << std::endl <<
blklist << std::endl <<
" End blocklist " << std::endl;
1715 if (filesize == 0 || !
blklist.numBlocks()) {
1735 std::string scheme =
urliter->getScheme();
1736 if (scheme ==
"http" || scheme ==
"https" || scheme ==
"ftp" || scheme ==
"tftp")
1754 if ( !
blklist.haveFileChecksum() )
std::optional< KeyManagerCtx > _context
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 unlink(const Pathname &path)
Like 'unlink'.
int hardlinkCopy(const Pathname &oldpath, const Pathname &newpath)
Create newpath as hardlink or copy of oldpath.
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.