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        std::optional<zypp::Digest> digest;
 
  353        if ( !headerSum.empty () ) {
 
  355          if ( !digest->create( headerSum.type() ) ) {
 
  356            ERR << 
"Unknown header checksum type " << headerSum.type() << std::endl;
 
  359          sum = zypp::Digest::hexStringToUByteArray( headerSum.checksum() );
 
  362        reqData.
_req->addRequestRange( 0, srcFile.
headerSize(), std::move(digest), sum );
 
  365        reqData.
_req->resetRequestRanges();
 
  370            ERR << 
"Failed to setup zchunk because of: " << res._message << std::endl;
 
  381        for ( 
const auto &block : res._blocks ) {
 
  382          if ( block._checksum.size() && block._chksumtype.size() ) {
 
  384            if ( !dig->create( block._chksumtype ) ) {
 
  385              WAR_MEDIA << 
"Trying to create Digest with chksum type " << block._chksumtype << 
" failed " << std::endl;
 
  391            reqData.
_req->addRequestRange( block._start, block._len, std::move(dig), block._checksum, {}, block._relevantDigestLen, block._chksumPad );
 
  400          ERR << 
"ZCK failed with error: " << err << std::endl;
 
 
  411      const auto &authCb = [&]( 
const zypp::Url &, 
TransferSettings &settings, 
const std::string & availAuthTypes, 
bool firstTry, 
bool &canContinue ) {
 
  415          settings = epSettings;
 
  422      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.
static bool validateZckFile(const zypp::Pathname &file, std::string &error)
static bool isZchunkFile(const zypp::Pathname &file)
static PrepareResult prepareZck(const zypp::Pathname &delta, const zypp::Pathname &target, const zypp::ByteCount &expectedFileSize)
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
#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.