libzypp  17.36.7
MediaCurl2.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
13 #include <iostream>
14 #include <chrono>
15 #include <list>
16 
17 #include <zypp/base/Logger.h>
18 #include <zypp/ExternalProgram.h>
19 #include <zypp/base/String.h>
20 #include <zypp/base/Gettext.h>
21 #include <zypp-core/parser/Sysconfig>
22 #include <zypp/base/Gettext.h>
23 
24 #include <zypp/media/MediaCurl2.h>
25 
28 #include <zypp-curl/ProxyInfo>
29 #include <zypp-curl/auth/CurlAuthData>
30 #include <zypp-media/auth/CredentialManager>
31 #include <zypp-curl/CurlConfig>
33 #include <zypp/Target.h>
34 #include <zypp/ZYppFactory.h>
35 #include <zypp/ZConfig.h>
36 #include <zypp/zypp_detail/ZYppImpl.h> // for zypp_poll
37 
42 
43 #include <cstdlib>
44 #include <sys/types.h>
45 #include <sys/stat.h>
46 #include <sys/mount.h>
47 #include <dirent.h>
48 #include <unistd.h>
49 #include <glib.h>
50 
54 
55 #ifdef ENABLE_ZCHUNK_COMPRESSION
57 #endif
58 
59 
66 using std::endl;
67 
68 using namespace internal;
69 using namespace zypp::base;
70 
71 namespace zypp {
72 
73  namespace media {
74 
75  MediaCurl2::MediaCurl2( const Url & url_r,
76  const Pathname & attach_point_hint_r )
77  : MediaNetworkCommonHandler( url_r, attach_point_hint_r,
78  "/", // urlpath at attachpoint
79  true ) // does_download
80  , _evDispatcher( zyppng::ThreadData::current().ensureDispatcher() )
81  , _nwDispatcher( std::make_shared<zyppng::NetworkRequestDispatcher>() )
82  {
83 
84  MIL << "MediaCurl2::MediaCurl2(" << url_r << ", " << attach_point_hint_r << ")" << endl;
85 
86  if( !attachPoint().empty())
87  {
88  PathInfo ainfo(attachPoint());
89  Pathname apath(attachPoint() + "XXXXXX");
90  char *atemp = ::strdup( apath.asString().c_str());
91  char *atest = NULL;
92  if( !ainfo.isDir() || !ainfo.userMayRWX() ||
93  atemp == NULL || (atest=::mkdtemp(atemp)) == NULL)
94  {
95  WAR << "attach point " << ainfo.path()
96  << " is not useable for " << url_r.getScheme() << endl;
97  setAttachPoint("", true);
98  }
99  else if( atest != NULL)
100  ::rmdir(atest);
101 
102  if( atemp != NULL)
103  ::free(atemp);
104  }
105 
106  _nwDispatcher->setAgentString ( str::asString( agentString () ) );
107  _nwDispatcher->setHostSpecificHeader ("download.opensuse.org", "X-ZYpp-DistributionFlavor", str::asString(distributionFlavorHeader()) );
108  _nwDispatcher->setHostSpecificHeader ("download.opensuse.org", "X-ZYpp-AnonymousId", str::asString(anonymousIdHeader()) );
109  }
110 
112  {
114  }
115 
117 
118  void MediaCurl2::checkProtocol(const Url &url) const
119  {
120  if ( !zyppng::NetworkRequestDispatcher::supportsProtocol ( url ) )
121  {
122  std::string msg("Unsupported protocol '");
123  msg += url.getScheme();
124  msg += "'";
126  }
127  }
128 
130  {
131  // fill some settings from url query parameters
132  try
133  {
136  }
137  catch ( const MediaException &e )
138  {
139  disconnectFrom();
140  ZYPP_RETHROW(e);
141  }
142  // if the proxy was not set (or explicitly unset) by url, then look...
143  if ( _effectiveSettings.proxy().empty() )
144  {
145  // ...at the system proxy settings
147  }
148 
149  /* Fixes bsc#1174011 "auth=basic ignored in some cases"
150  * We should proactively add the password to the request if basic auth is configured
151  * and a password is available in the credentials but not in the URL.
152  *
153  * We will be a bit paranoid here and require that the URL has a user embedded, otherwise we go the default route
154  * and ask the server first about the auth method
155  */
156  if ( _effectiveSettings.authType() == "basic"
157  && _effectiveSettings.username().size()
158  && !_effectiveSettings.password().size() ) {
159 
160  CredentialManager cm(CredManagerOptions(ZConfig::instance().repoManagerRoot()));
161  const auto cred = cm.getCred( _url );
162  if ( cred && cred->valid() ) {
163  if ( !_effectiveSettings.username().size() )
164  _effectiveSettings.setUsername(cred->username());
165  _effectiveSettings.setPassword(cred->password());
166  }
167  }
168  }
169 
170  void MediaCurl2::attachTo (bool next)
171  {
172  if ( next )
174 
175  if ( !_url.isValid() )
177 
180  {
182  }
183 
184  disconnectFrom(); // clean state if needed
185 
186  // here : setup TransferSettings
187  setupEasy();
188 
189  // FIXME: need a derived class to propelly compare url's
191  setMediaSource(media);
192  }
193 
194  bool
196  {
197  return MediaHandler::checkAttachPoint( apoint, true, true);
198  }
199 
201  {
202  // clear effective settings
204  }
205 
207 
208  void MediaCurl2::releaseFrom( const std::string & ejectDev )
209  {
210  disconnect();
211  }
212 
214 
215  void MediaCurl2::getFile( const OnMediaLocation &file ) const
216  {
217  // Use absolute file name to prevent access of files outside of the
218  // hierarchy below the attach point.
219  getFileCopy( file, localPath(file.filename()).absolutename() );
220  }
221 
223 
224  void MediaCurl2::getFileCopy( const OnMediaLocation & srcFile , const Pathname & target ) const
225  {
226 
227  const auto &filename = srcFile.filename();
228 
229  // Optional files will send no report until data are actually received (we know it exists).
230  OptionalDownloadProgressReport reportfilter( srcFile.optional() );
232 
233  Url fileurl(getFileUrl(filename));
234  do
235  {
236  try
237  {
238  doGetFileCopy( srcFile, target, report );
239  break; // success!
240  }
241  // unexpected exception
242  catch (MediaException & excpt_r)
243  {
245  if( typeid(excpt_r) == typeid( media::MediaFileNotFoundException ) ||
246  typeid(excpt_r) == typeid( media::MediaNotAFileException ) )
247  {
249  }
250  report->finish(fileurl, reason, excpt_r.asUserHistory());
251  ZYPP_RETHROW(excpt_r);
252  }
253  }
254  while ( true );
255  report->finish(fileurl, zypp::media::DownloadProgressReport::NO_ERROR, "");
256  }
257 
258  bool MediaCurl2::getDoesFileExist( const Pathname & filename ) const
259  {
260  DBG << filename.asString() << endl;
261 
262  if(!_url.isValid())
264 
265  if(_url.getHost().empty())
267 
268  Url url(getFileUrl(filename));
269 
270  DBG << "URL: " << url.asString() << endl;
271 
272  // Use URL without options and without username and passwd
273  // (some proxies dislike them in the URL).
274  // Curl seems to need the just scheme, hostname and a path;
275  // the rest was already passed as curl options (in attachTo).
276  Url curlUrl( clearQueryString(url) );
277 
278  auto req = std::make_shared<zyppng::NetworkRequest>( curlUrl, "/dev/null" );
279  req->setOptions ( zyppng::NetworkRequest::HeadRequest ); // just check for existance
280 
281  // as we are not having user interaction, the user can't cancel
282  // the file existence checking, a callback or timeout return code
283  // will be always a timeout.
284  try {
285  const_cast<MediaCurl2*>(this)->executeRequest ( req );
286  }
287  catch ( const MediaFileNotFoundException &e ) {
288  // if the file did not exist then we can return false
289  return false;
290  }
291  catch ( const MediaException &e ) {
292  // some error, we are not sure about file existence, rethrw
293  ZYPP_RETHROW(e);
294  }
295 
296  // exists
297  return ( !req->hasError() );
298  }
299 
301 
302  void MediaCurl2::doGetFileCopy( const OnMediaLocation &srcFile , const Pathname & target, callback::SendReport<DownloadProgressReport> & report, RequestOptions options ) const
303  {
304  Pathname dest = target.absolutename();
305  if( assert_dir( dest.dirname() ) ) {
306  DBG << "assert_dir " << dest.dirname() << " failed" << endl;
307  ZYPP_THROW( MediaSystemException(getFileUrl(srcFile.filename()), "System error on " + dest.dirname().asString()) );
308  }
309 
310  ManagedFile destNew { target.extend( ".new.zypp.XXXXXX" ) }; {
311  AutoFREE<char> buf { ::strdup( (*destNew).c_str() ) };
312  if( ! buf ) {
313  ERR << "out of memory for temp file name" << endl;
314  ZYPP_THROW(MediaSystemException(getFileUrl(srcFile.filename()), "out of memory for temp file name"));
315  }
316 
317  AutoFD tmp_fd { ::mkostemp( buf, O_CLOEXEC ) };
318  if( tmp_fd == -1 ) {
319  ERR << "mkstemp failed for file '" << destNew << "'" << endl;
321  }
322  destNew = ManagedFile( (*buf), filesystem::unlink );
323  }
324 
325  DBG << "dest: " << dest << endl;
326  DBG << "temp: " << destNew << endl;
327 #if 0
328  Not implemented here yet because NetworkRequest can not do IFMODSINCE yet
329  // set IFMODSINCE time condition (no download if not modified)
330  if( PathInfo(target).isExist() && !(options & OPTION_NO_IFMODSINCE) )
331  {
332  curl_easy_setopt(_curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE);
333  curl_easy_setopt(_curl, CURLOPT_TIMEVALUE, (long)PathInfo(target).mtime());
334  }
335  else
336  {
337  curl_easy_setopt(_curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_NONE);
338  curl_easy_setopt(_curl, CURLOPT_TIMEVALUE, 0L);
339  }
340 #endif
341 
342  DBG << srcFile.filename().asString() << endl;
343 
344  if(!_url.isValid())
346 
347  if(_url.getHost().empty())
349 
350  Url url(getFileUrl(srcFile.filename()));
351 
352  DBG << "URL: " << url.asString() << endl;
353  // Use URL without options and without username and passwd
354  // (some proxies dislike them in the URL).
355  // Curl seems to need the just scheme, hostname and a path;
356  // the rest was already passed as curl options (in attachTo).
357  Url curlUrl( clearQueryString(url) );
358 
359  auto req = std::make_shared<zyppng::NetworkRequest>( curlUrl, destNew, zyppng::NetworkRequest::WriteShared /*do not truncate*/ );
360  req->setExpectedFileSize ( srcFile.downloadSize () );
361 
362  bool done = false;
363 #ifdef ENABLE_ZCHUNK_COMPRESSION
364  done = const_cast<MediaCurl2*>(this)->tryZchunk(req, srcFile, destNew, report);
365 #endif
366  if ( !done ) {
367  req->resetRequestRanges();
368  const_cast<MediaCurl2 *>(this)->executeRequest ( req, &report );
369  }
370 
371 #if 0
372  Also disabled IFMODSINCE code, see above while not yet implemented here
373  #if CURLVERSION_AT_LEAST(7,19,4)
374  // bnc#692260: If the client sends a request with an If-Modified-Since header
375  // with a future date for the server, the server may respond 200 sending a
376  // zero size file.
377  // curl-7.19.4 introduces CURLINFO_CONDITION_UNMET to check this condition.
378  if ( ftell(file) == 0 && ret == 0 )
379  {
380  long httpReturnCode = 33;
381  if ( curl_easy_getinfo( _curl, CURLINFO_RESPONSE_CODE, &httpReturnCode ) == CURLE_OK && httpReturnCode == 200 )
382  {
383  long conditionUnmet = 33;
384  if ( curl_easy_getinfo( _curl, CURLINFO_CONDITION_UNMET, &conditionUnmet ) == CURLE_OK && conditionUnmet )
385  {
386  WAR << "TIMECONDITION unmet - retry without." << endl;
387  curl_easy_setopt(_curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_NONE);
388  curl_easy_setopt(_curl, CURLOPT_TIMEVALUE, 0L);
389  ret = executeCurl();
390  }
391  }
392  }
393 #endif
394 #endif
395 
396 
397  // apply umask
398  if ( ::chmod( destNew->c_str(), filesystem::applyUmaskTo( 0644 ) ) )
399  {
400  ERR << "Failed to chmod file " << destNew << endl;
401  }
402 
403  // move the temp file into dest
404  if ( rename( destNew, dest ) != 0 ) {
405  ERR << "Rename failed" << endl;
407  }
408  destNew.resetDispose(); // no more need to unlink it
409 
410  DBG << "done: " << PathInfo(dest) << endl;
411  }
412 
413 
414  bool MediaCurl2::tryZchunk( zyppng::NetworkRequestRef req, const OnMediaLocation &srcFile, const Pathname &target, callback::SendReport<DownloadProgressReport> &report )
415  {
416 #ifdef ENABLE_ZCHUNK_COMPRESSION
417 
418  // HERE add zchunk logic if required
419  if ( !srcFile.deltafile().empty()
421  && srcFile.headerSize () > 0 ) {
422 
423  // first fetch the zck header
424  std::optional<zypp::Digest> digest;
425  UByteArray sum;
426 
427  const auto &headerSum = srcFile.headerChecksum();
428  if ( !headerSum.empty () ) {
429  digest = zypp::Digest();
430  if ( !digest->create( headerSum.type() ) ) {
431  ERR << "Unknown header checksum type " << headerSum.type() << std::endl;
432  return false;
433  }
434  sum = zypp::Digest::hexStringToUByteArray( headerSum.checksum() );
435  }
436 
437  req->addRequestRange( 0, srcFile.headerSize(), std::move(digest), sum );
438  executeRequest ( req, nullptr );
439 
440  req->resetRequestRanges();
441 
442  auto res = zyppng::ZckHelper::prepareZck( srcFile.deltafile(), target, srcFile.downloadSize() );
443  switch(res._code) {
445  ERR << "Failed to setup zchunk because of: " << res._message << std::endl;
446  return false;
447  }
449  return true; // already done
451  ZYPP_THROW( MediaFileSizeExceededException( req->url(), srcFile.downloadSize(), res._message ));
453  break;
454  }
455 
456  for ( const auto &block : res._blocks ) {
457  if ( block._checksum.size() && block._chksumtype.size() ) {
458  std::optional<zypp::Digest> dig = zypp::Digest();
459  if ( !dig->create( block._chksumtype ) ) {
460  WAR_MEDIA << "Trying to create Digest with chksum type " << block._chksumtype << " failed " << std::endl;
461  return false;
462  }
463 
465  DBG_MEDIA << "Starting block " << block._start << " with checksum " << zypp::Digest::digestVectorToString( block._checksum ) << "." << std::endl;
466  req->addRequestRange( block._start, block._len, std::move(dig), block._checksum, {}, block._relevantDigestLen, block._chksumPad );
467  }
468  };
469 
470  executeRequest ( req, &report );
471 
472  //we might have the file ready
473  std::string err;
474  if ( !zyppng::ZckHelper::validateZckFile( target, err) ) {
475  ERR << "ZCK failed with error: " << err << std::endl;
476  return false;
477  }
478  return true;
479  }
480 #endif
481  return false;
482  }
483 
484 
485 
487 
488  void MediaCurl2::getDir( const Pathname & dirname, bool recurse_r ) const
489  {
490  filesystem::DirContent content;
491  getDirInfo( content, dirname, /*dots*/false );
492 
493  for ( filesystem::DirContent::const_iterator it = content.begin(); it != content.end(); ++it ) {
494  Pathname filename = dirname + it->name;
495  int res = 0;
496 
497  switch ( it->type ) {
498  case filesystem::FT_NOT_AVAIL: // old directory.yast contains no typeinfo at all
499  case filesystem::FT_FILE:
500  getFile( OnMediaLocation( filename ) );
501  break;
502  case filesystem::FT_DIR: // newer directory.yast contain at least directory info
503  if ( recurse_r ) {
504  getDir( filename, recurse_r );
505  } else {
506  res = assert_dir( localPath( filename ) );
507  if ( res ) {
508  WAR << "Ignore error (" << res << ") on creating local directory '" << localPath( filename ) << "'" << endl;
509  }
510  }
511  break;
512  default:
513  // don't provide devices, sockets, etc.
514  break;
515  }
516  }
517  }
518 
520 
521  void MediaCurl2::getDirInfo( std::list<std::string> & retlist,
522  const Pathname & dirname, bool dots ) const
523  {
524  getDirectoryYast( retlist, dirname, dots );
525  }
526 
528 
530  const Pathname & dirname, bool dots ) const
531  {
532  getDirectoryYast( retlist, dirname, dots );
533  }
534 
535  void MediaCurl2::executeRequest( zyppng::NetworkRequestRef req , callback::SendReport<DownloadProgressReport> *report )
536  {
537  auto loop = zyppng::EventLoop::create();
538 
539  _nwDispatcher->run();
540 
541  bool firstAuth = true;
542  bool retry = true;
543  int maxTries = _effectiveSettings.maxSilentTries();
544 
545  while ( retry ) {
546  std::optional<internal::ProgressTracker> progTracker;
547 
548  std::vector<zyppng::connection> signalConnections {
549  req->sigStarted().connect( [&]( zyppng::NetworkRequest &req ){
550  if ( !report) return;
551  (*report)->start( req.url(), req.targetFilePath() );
552  }),
553  req->sigProgress().connect( [&]( zyppng::NetworkRequest &req, off_t dlTotal, off_t dlNow, off_t, off_t ){
554  if ( !report || !progTracker )
555  return;
556 
557  progTracker->updateStats( dlTotal, dlNow );
558  if ( !(*report)->progress( progTracker->_dnlPercent, req.url(), progTracker-> _drateTotal, progTracker->_drateLast ) )
559  _nwDispatcher->cancel ( req );
560 
561  }),
562  req->sigFinished().connect( [&]( zyppng::NetworkRequest &req, const zyppng::NetworkRequestError &err ) {
563  loop->quit();
564  })
565  };
566 
567  // clean up slots for every loop
568  zypp_defer {
569  std::for_each( signalConnections.begin(), signalConnections.end(), []( auto &conn ) { conn.disconnect(); });
570  signalConnections.clear();
571  };
572 
573  if ( report ) {
574  progTracker = internal::ProgressTracker();
575  }
576 
577  maxTries--;
578  retry = false; // normally we don't retry
579  req->transferSettings() = _effectiveSettings; // use settings from MediaCurl
580  _nwDispatcher->enqueue ( req );
581  loop->run();
582 
583  // once the request is done there should be nothing there anymore
584  if ( _nwDispatcher->count () != 0 ) {
585  ZYPP_THROW( zypp::Exception("Unexpected request count after finishing MediaCurl2 request!") );
586  }
587 
588  if ( req->hasError() ) {
590  std::exception_ptr excp;
591  const auto &error = req->error();
592  switch ( error.type() ) {
602  excp = ZYPP_EXCPT_PTR( zypp::media::MediaCurlException( req->url(), error.toString(), error.nativeErrorString() ) );
603  break;
604  }
606  excp = ZYPP_EXCPT_PTR( zypp::media::MediaRequestCancelledException( error.toString() ) );
607  break;
608  }
610  excp = ZYPP_EXCPT_PTR( zypp::media::MediaFileSizeExceededException( req->url(), req->expectedFileSize() ) );
611  break;
612  }
614  excp = ZYPP_EXCPT_PTR( zypp::media::MediaTemporaryProblemException( req->url(), error.toString() ) );
615  break;
616  }
618  excp = ZYPP_EXCPT_PTR( zypp::media::MediaTimeoutException( req->url(), error.toString() ) );
619  break;
620  }
622  excp = ZYPP_EXCPT_PTR( zypp::media::MediaForbiddenException( req->url(), error.toString() ) );
623  break;
624  }
627 
628  //@BUG using getPathName() can result in wrong error messages
630  break;
631  }
634 
635  //in case we got a auth hint from the server the error object will contain it
636  std::string authHint = error.extraInfoValue("authHint", std::string());
637  if ( authenticate( authHint, firstAuth ) ) {
638  firstAuth = false;
639  retry = true;
640  continue;
641  }
642 
644  excp = ZYPP_EXCPT_PTR( zypp::media::MediaUnauthorizedException( req->url(), error.toString(), error.nativeErrorString(), "" ) );
645  break;
646  }
648  // should never happen
649  DBG << "BUG: Download error flag is set , but Error code is NoError" << std::endl;
650  break;
653  excp = ZYPP_EXCPT_PTR( zypp::media::MediaCurlException( req->url(), error.toString(), error.nativeErrorString() ) );
654  break;
655  }
656  }
657 
658  if ( excp ) {
659  if ( maxTries > 0 ) {
660  retry = true;
661  continue;
662  }
663 
664  if ( report ) (*report)->finish( req->url(), errCode, error.toString() );
665  std::rethrow_exception( excp );
666  }
667  }
668 
669  }
670 
671  if ( report ) (*report)->finish( req->url(), zypp::media::DownloadProgressReport::NO_ERROR, "" );
672  }
673 
674 
675  bool MediaCurl2::authenticate(const std::string & availAuthTypes, bool firstTry)
676  {
678  CredentialManager cm(CredManagerOptions(ZConfig::instance().repoManagerRoot()));
679  return authenticate( _url, cm, _effectiveSettings, availAuthTypes, firstTry );
680  }
681 
682  bool MediaCurl2::authenticate(const Url &url, CredentialManager &cm, TransferSettings &settings, const std::string & availAuthTypes, bool firstTry)
683  {
684  CurlAuthData_Ptr credentials;
685 
686  // get stored credentials
687  AuthData_Ptr cmcred = cm.getCred(url);
688 
689  if (cmcred && firstTry)
690  {
691  credentials.reset(new CurlAuthData(*cmcred));
692  DBG << "got stored credentials:" << endl << *credentials << endl;
693  }
694  // if not found, ask user
695  else
696  {
697 
698  CurlAuthData_Ptr curlcred;
699  curlcred.reset(new CurlAuthData());
701 
702  // preset the username if present in current url
703  if (!url.getUsername().empty() && firstTry)
704  curlcred->setUsername(url.getUsername());
705  // if CM has found some credentials, preset the username from there
706  else if (cmcred)
707  curlcred->setUsername(cmcred->username());
708 
709  // indicate we have no good credentials from CM
710  cmcred.reset();
711 
712  std::string prompt_msg = str::Format(_("Authentication required for '%s'")) % url.asString();
713 
714  // set available authentication types from the exception
715  // might be needed in prompt
716  curlcred->setAuthType(availAuthTypes);
717 
718  // ask user
719  if (auth_report->prompt(url, prompt_msg, *curlcred))
720  {
721  DBG << "callback answer: retry" << endl
722  << "CurlAuthData: " << *curlcred << endl;
723 
724  if (curlcred->valid())
725  {
726  credentials = curlcred;
727  // if (credentials->username() != _url.getUsername())
728  // _url.setUsername(credentials->username());
736  }
737  }
738  else
739  {
740  DBG << "callback answer: cancel" << endl;
741  }
742  }
743 
744  // set username and password
745  if (credentials)
746  {
747  settings.setUsername(credentials->username());
748  settings.setPassword(credentials->password());
749 
750  // set available authentication types from the exception
751  if (credentials->authType() == CURLAUTH_NONE)
752  credentials->setAuthType(availAuthTypes);
753 
754  // set auth type (seems this must be set _after_ setting the userpwd)
755  if (credentials->authType() != CURLAUTH_NONE) {
756  settings.setAuthType(credentials->authTypeAsString());
757  }
758 
759  if (!cmcred)
760  {
761  credentials->setUrl(url);
762  cm.addCred(*credentials);
763  cm.save();
764  }
765 
766  return true;
767  }
768 
769  return false;
770  }
771 
772  } // namespace media
773 } // namespace zypp
774 //
std::string getScheme() const
Returns the scheme name of the URL.
Definition: Url.cc:551
Url getFileUrl(const Pathname &filename) const
concatenate the attach url and the filename to a complete download url
Interface to gettext.
#define MIL
Definition: Logger.h:100
#define DBG_MEDIA
Definition: mediadebug_p.h:28
int assert_dir(const Pathname &path, unsigned mode)
Like &#39;mkdir -p&#39;.
Definition: PathInfo.cc:324
const ByteCount & headerSize() const
The size of the header prepending the resource (e.g.
#define _(MSG)
Definition: Gettext.h:39
const Pathname & path() const
Return current Pathname.
Definition: PathInfo.h:251
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:424
Implementation class for FTP, HTTP and HTTPS MediaHandler.
Definition: MediaCurl2.h:40
Describes a resource file located on a medium.
bool getDoesFileExist(const Pathname &filename) const override
Repeatedly calls doGetDoesFileExist() until it successfully returns, fails unexpectedly, or user cancels the operation.
Definition: MediaCurl2.cc:258
static ZConfig & instance()
Singleton ctor.
Definition: ZConfig.cc:940
void setPassword(const std::string &val_r)
sets the auth password
void setupEasy()
initializes the curl easy handle with the data from the url
Definition: MediaCurl2.cc:129
Compute Message Digests (MD5, SHA1 etc)
Definition: Digest.h:37
virtual bool checkAttachPoint(const Pathname &apoint) const
Verify if the specified directory as attach point (root) as requires by the particular media handler ...
void getFileCopy(const OnMediaLocation &srcFile, const Pathname &targetFilename) const override
Definition: MediaCurl2.cc:224
void executeRequest(zyppng::NetworkRequestRef req, callback::SendReport< DownloadProgressReport > *report=nullptr)
Definition: MediaCurl2.cc:535
Holds transfer setting.
void save()
Saves any unsaved credentials added via addUserCred() or addGlobalCred() methods. ...
const std::string & authType() const
get the allowed authentication types
Pathname extend(const std::string &r) const
Append string r to the last component of the path.
Definition: Pathname.h:175
int chmod(const Pathname &path, mode_t mode)
Like &#39;chmod&#39;.
Definition: PathInfo.cc:1097
Url clearQueryString(const Url &url)
Definition: curlhelper.cc:380
void setAttachPoint(const Pathname &path, bool temp)
Set a new attach point.
bool isUseableAttachPoint(const Pathname &path, bool mtab=true) const
Ask media manager, if the specified path is already used as attach point or if there are another atta...
void setUsername(const std::string &val_r)
sets the auth username
const std::string & asString(const std::string &t)
Global asString() that works with std::string too.
Definition: String.h:139
Definition: Arch.h:363
AuthData_Ptr getCred(const Url &url)
Get credentials for the specified url.
bool tryZchunk(zyppng::NetworkRequestRef req, const OnMediaLocation &srcFile, const Pathname &target, callback::SendReport< DownloadProgressReport > &report)
Definition: MediaCurl2.cc:414
Convenient building of std::string with boost::format.
Definition: String.h:252
void disconnectFrom() override
Definition: MediaCurl2.cc:200
AutoDispose<int> calling ::close
Definition: AutoDispose.h:309
#define ZYPP_EXCPT_PTR(EXCPT)
Drops a logline and returns Exception as a std::exception_ptr.
Definition: Exception.h:428
const std::string & password() const
auth password
#define zypp_defer
Definition: AutoDispose.h:293
std::list< DirEntry > DirContent
Returned by readdir.
Definition: PathInfo.h:526
#define ERR
Definition: Logger.h:102
const std::string & username() const
auth username
static bool isZchunkFile(const zypp::Pathname &file)
Definition: zckhelper.cc:21
Pathname localPath(const Pathname &pathname) const
Files provided will be available at &#39;localPath(filename)&#39;.
AutoDispose< const Pathname > ManagedFile
A Pathname plus associated cleanup code to be executed when path is no longer needed.
Definition: ManagedFile.h:27
static std::string digestVectorToString(const UByteArray &vec)
get hex string representation of the digest vector given as parameter
Definition: Digest.cc:243
long maxSilentTries() const
Maximum silent retries.
bool empty() const
Test for an empty path.
Definition: Pathname.h:116
#define ZYPP_RETHROW(EXCPT)
Drops a logline and rethrows, updating the CodeLocation.
Definition: Exception.h:444
std::string asString() const
Returns a default string representation of the Url object.
Definition: Url.cc:515
Bottleneck filtering all DownloadProgressReport issued from Media[Muli]Curl.
void setAuthType(const std::string &val_r)
set the allowed authentication types
const Url _url
Url to handle.
Definition: MediaHandler.h:113
void setMediaSource(const MediaSourceRef &ref)
Set new media source reference.
const std::string & asString() const
String representation.
Definition: Pathname.h:93
TransferSettings _effectiveSettings
Definition: MediaCurl2.h:133
Just inherits Exception to separate media exceptions.
std::string asUserHistory() const
A single (multiline) string composed of asUserString and historyAsString.
Definition: Exception.cc:127
const ByteCount & downloadSize() const
The size of the resource on the server.
void disconnect()
Use concrete handler to isconnect media.
Pathname dirname() const
Return all but the last component od this path.
Definition: Pathname.h:126
#define WAR
Definition: Logger.h:101
The NetworkRequestError class Represents a error that occured in.
zyppng::NetworkRequestDispatcherRef _nwDispatcher
Definition: MediaCurl2.h:132
shared_ptr< AuthData > AuthData_Ptr
Definition: authdata.h:81
const long & ZYPP_MEDIA_CURL_DEBUG()
const long& for setting CURLOPT_DEBUGDATA Returns a reference to a static variable, so it&#39;s safe to pass ...
Definition: curlhelper.cc:36
void getDirectoryYast(std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const
Retrieve and if available scan dirname/directory.yast.
void fillSettingsFromUrl(const Url &url, media::TransferSettings &s)
Fills the settings structure using options passed on the url for example ?timeout=x&proxy=foo.
Definition: curlhelper.cc:183
bool checkAttachPoint(const Pathname &apoint) const override
Verify if the specified directory as attach point (root) as requires by the particular media handler ...
Definition: MediaCurl2.cc:195
void getDirInfo(std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const override
Call concrete handler to provide a content list of directory on media via retlist.
Definition: MediaCurl2.cc:521
bool isValid() const
Verifies the Url.
Definition: Url.cc:507
static Ptr create()
const Pathname & filename() const
The path to the resource on the medium.
int unlink(const Pathname &path)
Like &#39;unlink&#39;.
Definition: PathInfo.cc:705
to not add a IFMODSINCE header if target exists
Definition: MediaCurl2.h:52
const zypp::Pathname & targetFilePath() const
Returns the target filename path.
Definition: request.cc:919
Media source internally used by MediaManager and MediaHandler.
Definition: MediaSource.h:37
void getDir(const Pathname &dirname, bool recurse_r) const override
Call concrete handler to provide directory content (not recursive!) below attach point.
Definition: MediaCurl2.cc:488
void attachTo(bool next=false) override
Call concrete handler to attach the media.
Definition: MediaCurl2.cc:170
const Pathname & deltafile() const
The existing deltafile that can be used to reduce download size ( zchunk or metalink ) ...
#define WAR_MEDIA
Definition: mediadebug_p.h:30
Pathname absolutename() const
Return this path, adding a leading &#39;/&#39; if relative.
Definition: Pathname.h:141
Base class for Exception.
Definition: Exception.h:146
Pathname attachPoint() const
Return the currently used attach point.
Url url() const
Url used.
Definition: MediaHandler.h:503
shared_ptr< CurlAuthData > CurlAuthData_Ptr
Definition: curlauthdata.h:102
static bool validateZckFile(const zypp::Pathname &file, std::string &error)
Definition: zckhelper.cc:169
std::string getPathName(EEncoding eflag=zypp::url::E_DECODED) const
Returns the path name from the URL.
Definition: Url.cc:622
std::string getHost(EEncoding eflag=zypp::url::E_DECODED) const
Returns the hostname or IP from the URL authority.
Definition: Url.cc:606
Wrapper class for ::stat/::lstat.
Definition: PathInfo.h:225
Url clearQueryString(const Url &url) const
Definition: MediaCurl2.cc:111
SignalProxy< void(NetworkRequest &req, const NetworkRequestError &err)> sigFinished()
Signals that the download finished.
Definition: request.cc:1066
void fillSettingsSystemProxy(const Url &url, media::TransferSettings &s)
Reads the system proxy configuration and fills the settings structure proxy information.
Definition: curlhelper.cc:338
mode_t applyUmaskTo(mode_t mode_r)
Modify mode_r according to the current umask ( mode_r & ~getUmask() ).
Definition: PathInfo.h:806
int rename(const Pathname &oldpath, const Pathname &newpath)
Like &#39;rename&#39;.
Definition: PathInfo.cc:747
Pathname createAttachPoint() const
Try to create a default / temporary attach point.
void addCred(const AuthData &cred)
Add new credentials with user callbacks.
static bool authenticate(const Url &url, CredentialManager &cm, TransferSettings &settings, const std::string &availAuthTypes, bool firstTry)
Definition: MediaCurl2.cc:682
Easy-to use interface to the ZYPP dependency resolver.
Definition: Application.cc:19
Curl HTTP authentication data.
Definition: curlauthdata.h:22
virtual void doGetFileCopy(const OnMediaLocation &srcFile, const Pathname &targetFilename, callback::SendReport< DownloadProgressReport > &_report, RequestOptions options=OPTION_NONE) const
Definition: MediaCurl2.cc:302
const std::string & proxy() const
proxy host
void checkProtocol(const Url &url) const
check the url is supported by the curl library
Definition: MediaCurl2.cc:118
SignalProxy< void(NetworkRequest &req, off_t dltotal, off_t dlnow, off_t ultotal, off_t ulnow)> sigProgress()
Signals if there was data read from the download.
Definition: request.cc:1061
int rmdir(const Pathname &path)
Like &#39;rmdir&#39;.
Definition: PathInfo.cc:371
bool optional() const
Whether this is an optional resource.
bool userMayRWX() const
Definition: PathInfo.h:361
Url manipulation class.
Definition: Url.h:92
void releaseFrom(const std::string &ejectDev) override
Call concrete handler to release the media.
Definition: MediaCurl2.cc:208
#define DBG
Definition: Logger.h:99
const CheckSum & headerChecksum() const
The checksum of the header prepending the resource (e.g.
static PrepareResult prepareZck(const zypp::Pathname &delta, const zypp::Pathname &target, const zypp::ByteCount &expectedFileSize)
Definition: zckhelper.cc:34
void getFile(const OnMediaLocation &file) const override
Call concrete handler to provide file below attach point.
Definition: MediaCurl2.cc:215
std::string getUsername(EEncoding eflag=zypp::url::E_DECODED) const
Returns the username from the URL authority.
Definition: Url.cc:590