19#include <zypp-core/parser/Sysconfig>
25#include <zypp-curl/ProxyInfo>
26#include <zypp-curl/CurlConfig>
48#ifdef ENABLE_ZCHUNK_COMPRESSION
69 const Pathname & attach_point_hint_r )
76 MIL <<
"MediaCurl2::MediaCurl2(" << origin_r.
authority().
url() <<
", " << attach_point_hint_r <<
")" << endl;
82 char *atemp = ::strdup( apath.
asString().c_str());
85 atemp == NULL || (atest=::mkdtemp(atemp)) == NULL)
87 WAR <<
"attach point " << ainfo.
path()
91 else if( atest != NULL)
103 if ( !zyppng::NetworkRequestDispatcher::supportsProtocol (
url ) )
105 std::string msg(
"Unsupported protocol '");
106 msg +=
url.getScheme();
130 const auto &filename = srcFile.
filename();
137 for (
unsigned mirr : mirrOrder ) {
138 MIL <<
"Trying to fetch file " << srcFile <<
" via URL: " <<
_origin[mirr].url() << std::endl;
143 const auto &myOrigin =
_origin[mirr];
144 if(!myOrigin.url().isValid())
147 if(myOrigin.url().getHost().empty())
152 if( assert_dir( dest.
dirname() ) ) {
153 DBG <<
"assert_dir " << dest.
dirname() <<
" failed" << endl;
160 ERR <<
"out of memory for temp file name" << endl;
164 AutoFD tmp_fd { ::mkostemp( buf, O_CLOEXEC ) };
166 ERR <<
"mkstemp failed for file '" << destNew <<
"'" << endl;
172 DBG <<
"dest: " << dest << endl;
173 DBG <<
"temp: " << destNew << endl;
175 Not implemented here yet because NetworkRequest can not
do IFMODSINCE yet
177 if(
PathInfo(
target).isExist() && !(options & OPTION_NO_IFMODSINCE) )
179 curl_easy_setopt(_curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE);
180 curl_easy_setopt(_curl, CURLOPT_TIMEVALUE, (
long)
PathInfo(
target).mtime());
184 curl_easy_setopt(_curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_NONE);
185 curl_easy_setopt(_curl, CURLOPT_TIMEVALUE, 0L);
205 #ifdef ENABLE_ZCHUNK_COMPRESSION
209 r.
_req->resetRequestRanges();
214 Also disabled IFMODSINCE code, see above
while not yet implemented here
215 #if CURLVERSION_AT_LEAST(7,19,4)
220 if ( ftell(file) == 0 && ret == 0 )
222 long httpReturnCode = 33;
223 if ( curl_easy_getinfo( _curl, CURLINFO_RESPONSE_CODE, &httpReturnCode ) == CURLE_OK && httpReturnCode == 200 )
225 long conditionUnmet = 33;
226 if ( curl_easy_getinfo( _curl, CURLINFO_CONDITION_UNMET, &conditionUnmet ) == CURLE_OK && conditionUnmet )
228 WAR <<
"TIMECONDITION unmet - retry without." << endl;
229 curl_easy_setopt(_curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_NONE);
230 curl_easy_setopt(_curl, CURLOPT_TIMEVALUE, 0L);
242 ERR <<
"Failed to chmod file " << destNew << endl;
246 if ( rename( destNew, dest ) != 0 ) {
247 ERR <<
"Rename failed" << endl;
278 std::exception_ptr lastErr;
279 MIL <<
"Trying origin: " <<
_origin << std::endl;
282 const auto &myEndpoint =
_origin[mirr];
284 if( !myEndpoint.url().isValid() )
292 DBG <<
"URL: " <<
url.asString() << endl;
302 r.
_req = std::make_shared<zyppng::NetworkRequest>( curlUrl,
"/dev/null" );
324 return ( !r.
_req->hasError() );
341#ifdef ENABLE_ZCHUNK_COMPRESSION
349 const auto &fetchChunks = [&](
const std::vector<zyppng::ZckLoader::Block> &blocks ){
351 reqData.
_req->resetRequestRanges();
353 for (
const auto &block : blocks ) {
354 if ( block._checksum.size() && block._chksumtype.size() ) {
356 if ( !dig->create( block._chksumtype ) ) {
357 WAR_MEDIA <<
"Trying to create Digest with chksum type " << block._chksumtype <<
" failed " << std::endl;
358 zckHelper->setFailed(
str::Str() <<
"Trying to create Digest with chksum type " << block._chksumtype <<
" failed " );
364 reqData.
_req->addRequestRange( block._start, block._len, std::move(dig), block._checksum, {}, block._relevantDigestLen, block._chksumPad );
367 DBG_MEDIA <<
"Starting block " << block._start <<
" without checksum!" << std::endl;
368 reqData.
_req->addRequestRange( block._start, block._len );
373 zckHelper->cont().unwrap();
379 res = std::move(result);
386 zckHelper->buildZchunkFile(
target, srcFile.
deltafile(), dSize ? dSize : std::optional<zypp::ByteCount>{}, hdrSize ? hdrSize : std::optional<zypp::ByteCount>{} ).unwrap();
390 ERR <<
"Failed to setup zchunk because of: " << res.
_message << std::endl;
406 const auto &authCb = [&](
const zypp::Url &,
TransferSettings &settings,
const std::string & availAuthTypes,
bool firstTry,
bool &canContinue ) {
410 settings = epSettings;
417 auto conn =
_executor->sigAuthRequired().connect (authCb);
void resetDispose()
Set no dispose function.
Compute Message Digests (MD5, SHA1 etc)
static std::string digestVectorToString(const UByteArray &vec)
get hex string representation of the digest vector given as parameter
Manages a data source characterized by an authoritative URL and a list of mirror URLs.
const OriginEndpoint & authority() const
const zypp::Url & url() const
std::string getScheme() const
Returns the scheme name of the URL.
std::string asString() const
Returns a default string representation of the Url object.
Wrapper class for stat/lstat.
const Pathname & path() const
Return current Pathname.
Pathname dirname() const
Return all but the last component od this path.
const char * c_str() const
String representation.
const std::string & asString() const
String representation.
bool empty() const
Test for an empty path.
SignalProxy< void(PrepareResult)> sigFinished()
Called once the zchunk build process is finished, either with error or success.
static bool isZchunkFile(const zypp::Pathname &file)
SignalProxy< void(const std::vector< Block > &)> sigBlocksRequired()
Signal to notify the caller about required blocks, once the blocks are downloaded call cont to contin...
const long & ZYPP_MEDIA_CURL_DEBUG()
const long& for setting CURLOPT_DEBUGDATA Returns a reference to a static variable,...
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'.
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.
Bottleneck filtering all DownloadProgressReport issued from Media[Muli]Curl.
AutoDispose<int> calling close
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...
#define ZYPP_RETHROW(EXCPT)
Drops a logline and rethrows, updating the CodeLocation.
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
#define ZYPP_FWD_CURRENT_EXCPT()
Drops a logline and returns the current Exception as a std::exception_ptr.
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.