libzypp  17.37.5
provideitem.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
9 
10 #include "private/providedbg_p.h"
11 #include "private/provideitem_p.h"
12 #include "private/provide_p.h"
14 #include "private/provideres_p.h"
15 #include "provide-configvars.h"
16 #include <zypp-media/MediaException>
17 #include <zypp-core/base/UserRequestException>
18 #include "mediaverifier.h"
19 #include <zypp-core/fs/PathInfo.h>
20 
21 using namespace std::literals;
22 
23 namespace zyppng {
24 
25  static constexpr std::string_view DEFAULT_MEDIA_VERIFIER("SuseMediaV1");
26 
27  expected<ProvideRequestRef> ProvideRequest::create(ProvideItem &owner, const std::vector<zypp::Url> &urls, const std::string &id, ProvideMediaSpec &spec )
28  {
29  if ( urls.empty() )
30  return expected<ProvideRequestRef>::error( ZYPP_EXCPT_PTR ( zypp::media::MediaException("List of URLs can not be empty") ) );
31 
32  auto m = ProvideMessage::createAttach( ProvideQueue::InvalidId, urls.front(), id, spec.label() );
33  if ( !spec.mediaFile().empty() ) {
34  m.setValue( AttachMsgFields::VerifyType, std::string(DEFAULT_MEDIA_VERIFIER.data()) );
35  m.setValue( AttachMsgFields::VerifyData, spec.mediaFile().asString() );
36  m.setValue( AttachMsgFields::MediaNr, int32_t(spec.medianr()) );
37  }
38 
39  const auto &cHeaders = spec.customHeaders();
40  for ( auto i = cHeaders.beginList (); i != cHeaders.endList(); i++) {
41  for ( const auto &val : i->second )
42  m.addValue( i->first, val );
43  }
44 
45  return expected<ProvideRequestRef>::success( ProvideRequestRef( new ProvideRequest(&owner, urls, std::move(m))) );
46  }
47 
48  expected<ProvideRequestRef> ProvideRequest::create( ProvideItem &owner, const std::vector<zypp::Url> &urls, ProvideFileSpec &spec )
49  {
50  if ( urls.empty() )
51  return expected<ProvideRequestRef>::error( ZYPP_EXCPT_PTR ( zypp::media::MediaException("List of URLs can not be empty") ) );
52 
53  auto m = ProvideMessage::createProvide ( ProvideQueue::InvalidId, urls.front() );
54  const auto &destFile = spec.destFilenameHint();
55  const auto &deltaFile = spec.deltafile();
56  const int64_t fSize = spec.downloadSize();;
57 
58  if ( !destFile.empty() )
59  m.setValue( ProvideMsgFields::Filename, destFile.asString() );
60  if ( !deltaFile.empty() )
61  m.setValue( ProvideMsgFields::DeltaFile, deltaFile.asString() );
62  if ( fSize )
63  m.setValue( ProvideMsgFields::ExpectedFilesize, fSize );
65 
66  const auto &cHeaders = spec.customHeaders();
67  for ( auto i = cHeaders.beginList (); i != cHeaders.endList(); i++) {
68  for ( const auto &val : i->second )
69  m.addValue( i->first, val );
70  }
71 
72  return expected<ProvideRequestRef>::success( ProvideRequestRef( new ProvideRequest(&owner, urls, std::move(m)) ) );
73  }
74 
75  expected<ProvideRequestRef> ProvideRequest::createDetach( const zypp::Url &url )
76  {
77  auto m = ProvideMessage::createDetach ( ProvideQueue::InvalidId , url );
78  return expected<ProvideRequestRef>::success( ProvideRequestRef( new ProvideRequest( nullptr, { url }, std::move(m) ) ) );
79  }
80 
82 
83  ProvideItem::ProvideItem( ProvidePrivate &parent )
84  : Base( *new ProvideItemPrivate( parent, *this ) )
85  { }
86 
88  { }
89 
91  {
92  return d_func()->_parent;
93  }
94 
95  bool ProvideItem::safeRedirectTo( ProvideRequestRef startedReq, const zypp::Url &url )
96  {
97  if ( !canRedirectTo( startedReq, url ) )
98  return false;
99 
100  redirectTo( startedReq, url );
101  return true;
102  }
103 
104  void ProvideItem::redirectTo( ProvideRequestRef startedReq, const zypp::Url &url )
105  {
106  //@TODO strip irrelevant stuff from URL
107  startedReq->_pastRedirects.push_back ( url );
108  }
109 
110  bool ProvideItem::canRedirectTo( ProvideRequestRef startedReq, const zypp::Url &url )
111  {
112  // make sure there is no redirect loop
113  if ( !startedReq->_pastRedirects.size() )
114  return true;
115 
116  if ( std::find( startedReq->_pastRedirects.begin(), startedReq->_pastRedirects.end(), url ) != startedReq->_pastRedirects.end() )
117  return false;
118 
119  return true;
120  }
121 
122  const std::optional<ProvideItem::ItemStats> &ProvideItem::currentStats() const
123  {
124  return d_func()->_currStats;
125  }
126 
127  const std::optional<ProvideItem::ItemStats> &ProvideItem::previousStats() const
128  {
129  return d_func()->_prevStats;
130  }
131 
132  std::chrono::steady_clock::time_point ProvideItem::startTime() const
133  {
134  return d_func()->_itemStarted;
135  }
136 
137  std::chrono::steady_clock::time_point ProvideItem::finishedTime() const {
138  return d_func()->_itemFinished;
139  }
140 
142  {
143  Z_D();
144  if ( d->_currStats )
145  d->_prevStats = d->_currStats;
146 
147  d->_currStats = makeStats();
148 
149  // once the item is finished the pulse time is always the finish time
150  if ( d->_itemState == Finished )
151  d->_currStats->_pulseTime = d->_itemFinished;
152  }
153 
155  {
156  return 0;
157  }
158 
160  {
161  return ItemStats {
162  ._pulseTime = std::chrono::steady_clock::now(),
163  ._runningRequests = _runningReq ? (uint)1 : (uint)0
164  };
165  }
166 
167  void ProvideItem::informalMessage ( ProvideQueue &, ProvideRequestRef req, const ProvideMessage &msg )
168  {
169  if ( req != _runningReq ) {
170  WAR << "Received event for unknown request, ignoring" << std::endl;
171  return;
172  }
173 
175  MIL << "Request: "<< req->url() << " was started" << std::endl;
176  }
177 
178  }
179 
180  void ProvideItem::cacheMiss( ProvideRequestRef req )
181  {
182  if ( req != _runningReq ) {
183  WAR << "Received event for unknown request, ignoring" << std::endl;
184  return;
185  }
186 
187  MIL << "Request: "<< req->url() << " CACHE MISS, request will be restarted by queue." << std::endl;
188  }
189 
190  void ProvideItem::finishReq(ProvideQueue &, ProvideRequestRef finishedReq, const ProvideMessage &msg )
191  {
192  if ( finishedReq != _runningReq ) {
193  WAR << "Received event for unknown request, ignoring" << std::endl;
194  return;
195  }
196 
197  auto log = provider().log();
198 
199  // explicitely handled codes
200  const auto code = msg.code();
201  if ( code == ProvideMessage::Code::Redirect ) {
202 
203  // remove the old request
204  _runningReq.reset();
205 
206  try {
207 
208  MIL << "Request finished with redirect." << std::endl;
209 
211  if ( !safeRedirectTo( finishedReq, newUrl ) ) {
213  return;
214  }
215 
216  MIL << "Request redirected to: " << newUrl << std::endl;
217 
218  if ( log ) log->requestRedirect( *this, msg.requestId(), newUrl );
219 
220  finishedReq->setUrl( newUrl );
221 
222  if ( !enqueueRequest( finishedReq ) ) {
223  cancelWithError( ZYPP_EXCPT_PTR(zypp::media::MediaException("Failed to queue request")) );
224  }
225  } catch ( ... ) {
226  cancelWithError( std::current_exception() );
227  return;
228  }
229  return;
230 
231  } else if ( code == ProvideMessage::Code::Metalink ) {
232 
233  // remove the old request
234  _runningReq.reset();
235 
236  MIL << "Request finished with mirrorlist from server." << std::endl;
237 
238  //@TODO do we need to merge this with the mirrorlist we got from the user?
239  // or does a mirrorlist from d.o.o invalidate that?
240 
241  std::vector<zypp::Url> urls;
242  const auto &mirrors = msg.values( MetalinkRedirectMsgFields::NewUrl );
243  for( auto i = mirrors.cbegin(); i != mirrors.cend(); i++ ) {
244  try {
245  zypp::Url newUrl( i->asString() );
246  if ( !canRedirectTo( finishedReq, newUrl ) )
247  continue;
248  urls.push_back ( newUrl );
249  } catch ( ... ) {
250  if ( i->isString() )
251  WAR << "Received invalid URL from worker: " << i->asString() << " ignoring!" << std::endl;
252  else
253  WAR << "Received invalid value for newUrl from worker ignoring!" << std::endl;
254  }
255  }
256 
257  if ( urls.size () == 0 ) {
258  cancelWithError( ZYPP_EXCPT_PTR ( zypp::media::MediaException("No mirrors left to redirect to.")) );
259  return;
260  }
261 
262  MIL << "Found usable nr of mirrors: " << urls.size () << std::endl;
263  finishedReq->setUrls( urls );
264 
265  // disable metalink
266  finishedReq->provideMessage().setValue( ProvideMsgFields::MetalinkEnabled, false );
267 
268  if ( log ) log->requestDone( *this, msg.requestId() );
269 
270  if ( !enqueueRequest( finishedReq ) ) {
271  cancelWithError( ZYPP_EXCPT_PTR(zypp::media::MediaException("Failed to queue request")) );
272  }
273 
274  MIL << "End of mirrorlist handling"<< std::endl;
275  return;
276 
278 
279  // remove the old request
280  _runningReq.reset();
281 
282  std::exception_ptr errPtr;
283  try {
284  const auto reqUrl = finishedReq->activeUrl().value();
285  const auto reason = msg.value( ErrMsgFields::Reason ).asString();
286  switch ( code ) {
288  errPtr = ZYPP_EXCPT_PTR( zypp::media::MediaException (zypp::str::Str() << "Bad request for URL: " << reqUrl << " " << reason ) );
289  break;
291  errPtr = ZYPP_EXCPT_PTR( zypp::media::MediaException(zypp::str::Str() << "PeerCertificateInvalid Error for URL: " << reqUrl << " " << reason) );
292  break;
294  errPtr = ZYPP_EXCPT_PTR( zypp::media::MediaException(zypp::str::Str() << "ConnectionFailed Error for URL: " << reqUrl << " " << reason ) );
295  break;
297 
298  std::optional<int64_t> filesize;
299  const auto &hdrs = finishedReq->provideMessage ().headers ();
300  if ( hdrs.contains( ProvideMsgFields::ExpectedFilesize ) ) {
301  const auto &val = hdrs.value ( ProvideMsgFields::ExpectedFilesize );
302  if ( val.valid() )
303  filesize = val.asInt64();
304  }
305 
306  if ( !filesize ) {
307  errPtr = ZYPP_EXCPT_PTR( zypp::media::MediaException( zypp::str::Str() << "ExceededExpectedSize Error for URL: " << reqUrl << " " << reason ) );
308  } else {
309  errPtr = ZYPP_EXCPT_PTR( zypp::media::MediaFileSizeExceededException(reqUrl, *filesize ) );
310  }
311  break;
312  }
314  errPtr = ZYPP_EXCPT_PTR( zypp::media::MediaException( zypp::str::Str() << "Request was cancelled: " << reqUrl << " " << reason ) );
315  break;
317  errPtr = ZYPP_EXCPT_PTR( zypp::media::MediaException( zypp::str::Str() << "InvalidChecksum Error for URL: " << reqUrl << " " << reason ) );
318  break;
321  break;
324  break;
327 
328  const auto &hintVal = msg.value( "authHint"sv );
329  std::string hint;
330  if ( hintVal.valid() && hintVal.isString() ) {
331  hint = hintVal.asString();
332  }
333 
334  //@TODO retry here with timestamp from cred store check
335  // we let the request fail after it checked the store
336 
338  reqUrl, reason, "", hint
339  ));
340  break;
341 
342  }
344  errPtr = ZYPP_EXCPT_PTR( zypp::media::MediaException( zypp::str::Str() << "MountFailed Error for URL: " << reqUrl << " " << reason ) );
345  break;
348  break;
350  errPtr = ZYPP_EXCPT_PTR( zypp::SkipRequestException ( zypp::str::Str() << "User-requested skipping for URL: " << reqUrl << " " << reason ) );
351  break;
353  errPtr = ZYPP_EXCPT_PTR( zypp::AbortRequestException( zypp::str::Str() <<"Aborting requested by user for URL: " << reqUrl << " " << reason ) );
354  break;
356  errPtr = ZYPP_EXCPT_PTR( zypp::media::MediaException( zypp::str::Str() << "WorkerSpecific Error for URL: " << reqUrl << " " << reason ) );
357  break;
359  errPtr = ZYPP_EXCPT_PTR( zypp::media::MediaNotAFileException(reqUrl, "") );
360  break;
363  break;
364  default:
365  errPtr = ZYPP_EXCPT_PTR( zypp::media::MediaException( zypp::str::Str() << "Unknown Error for URL: " << reqUrl << " " << reason ) );
366  break;
367  }
368  } catch (...) {
369  errPtr = ZYPP_EXCPT_PTR( zypp::media::MediaException( zypp::str::Str() << "Invalid error message received for URL: " << *finishedReq->activeUrl() << " code: " << code ) );
370  }
371 
372  if ( log ) log->requestFailed( *this, msg.requestId(), errPtr );
373  // finish the request
374  cancelWithError( errPtr );
375  return;
376  }
377 
378  // if we reach here we don't know how to handle the message
379  _runningReq.reset();
380  cancelWithError( ZYPP_EXCPT_PTR (zypp::media::MediaException("Unhandled message received for ProvideFileItem")) );
381  }
382 
383  void ProvideItem::finishReq(ProvideQueue *, ProvideRequestRef finishedReq , const std::exception_ptr excpt)
384  {
385  if ( finishedReq != _runningReq ) {
386  WAR << "Received event for unknown request, ignoring" << std::endl;
387  return;
388  }
389 
390  if ( _runningReq ) {
391  auto log = provider().log();
392  if ( log ) log->requestFailed( *this, finishedReq->provideMessage().requestId(), excpt );
393  }
394 
395  _runningReq.reset();
396  cancelWithError(excpt);
397  }
398 
399  expected<zypp::media::AuthData> ProvideItem::authenticationRequired ( ProvideQueue &queue, ProvideRequestRef req, const zypp::Url &effectiveUrl, int64_t lastTimestamp, const std::map<std::string, std::string> &extraFields )
400  {
401 
402  if ( req != _runningReq ) {
403  WAR << "Received authenticationRequired for unknown request, rejecting" << std::endl;
404  return expected<zypp::media::AuthData>::error( ZYPP_EXCPT_PTR( zypp::media::MediaException("Unknown request in authenticationRequired, this is a bug.") ) );
405  }
406 
407  try {
408  zypp::media::CredentialManager mgr ( provider().credManagerOptions() );
409 
410  MIL << "Looking for existing auth data for " << effectiveUrl << "more recent then " << lastTimestamp << std::endl;
411 
412  auto credPtr = mgr.getCred( effectiveUrl );
413  if ( credPtr && credPtr->lastDatabaseUpdate() > lastTimestamp ) {
414  MIL << "Found existing auth data for " << effectiveUrl << "ts: " << credPtr->lastDatabaseUpdate() << std::endl;
415  return expected<zypp::media::AuthData>::success( *credPtr );
416  }
417 
418  if ( credPtr ) MIL << "Found existing auth data for " << effectiveUrl << "but too old ts: " << credPtr->lastDatabaseUpdate() << std::endl;
419 
420  std::string username;
421  if ( auto i = extraFields.find( std::string(AuthDataRequestMsgFields::LastUser) ); i != extraFields.end() ) {
422  username = i->second;
423  }
424 
425 
426  MIL << "NO Auth data found, asking user. Last tried username was: " << username << std::endl;
427 
428  auto userAuth = provider()._sigAuthRequired.emit( effectiveUrl, username, extraFields );
429  if ( !userAuth || !userAuth->valid() ) {
430  MIL << "User rejected to give auth" << std::endl;
432  }
433 
434  mgr.addCred( *userAuth );
435  mgr.save();
436 
437  // rather ugly, but update the timestamp to the last mtime of the cred database our URL belongs to
438  // otherwise we'd need to reload the cred database
439  userAuth->setLastDatabaseUpdate( mgr.timestampForCredDatabase( effectiveUrl ) );
440 
442  } catch ( const zypp::Exception &e ) {
443  ZYPP_CAUGHT(e);
445  }
446  }
447 
448  bool ProvideItem::enqueueRequest( ProvideRequestRef request )
449  {
450  // base item just supports one running request at a time
451  if ( _runningReq )
452  return ( _runningReq == request );
453 
454  _runningReq = request;
455  return d_func()->_parent.queueRequest( request );
456  }
457 
458  void ProvideItem::updateState( const State newState )
459  {
460  Z_D();
461  if ( d->_itemState != newState ) {
462 
463  bool started = ( d->_itemState == Uninitialized && ( newState != Finished ));
464  auto log = provider().log();
465 
466  const auto oldState = d->_itemState;
467  d->_itemState = newState;
468  d->_sigStateChanged( *this, oldState, d->_itemState );
469 
470  if ( started ) {
471  d->_itemStarted = std::chrono::steady_clock::now();
472  pulse();
473  if ( log ) log->itemStart( *this );
474  }
475 
476  if ( newState == Finished ) {
477  d->_itemFinished = std::chrono::steady_clock::now();
478  pulse();
479  if ( log) log->itemDone( *this );
480  d->_parent.dequeueItem(this);
481  }
482  // CAREFUL, 'this' might be invalid from here on
483  }
484  }
485 
487  {
488  if ( state() == Finished || state() == Finalizing )
489  return;
490 
491  MIL << "Item Cleanup due to released Promise in state:" << state() << std::endl;
493  }
494 
496  {
497  return d_func()->_itemState;
498  }
499 
500  void ProvideRequest::setCurrentQueue( ProvideQueueRef ref )
501  {
502  _myQueue = ref;
503  }
504 
506  {
507  return _myQueue.lock();
508  }
509 
510  const std::optional<zypp::Url> ProvideRequest::activeUrl() const
511  {
513  switch ( this->_message.code () ) {
516  break;
519  break;
522  break;
523  default:
524  // should never happen because we guard the constructor
525  throw std::logic_error("Invalid message type in ProvideRequest");
526  }
527  if ( !url.valid() ) {
528  return {};
529  }
530 
531  try {
532  auto u = zypp::Url( url.asString() );
533  return u;
534  } catch ( const zypp::Exception &e ) {
535  ZYPP_CAUGHT(e);
536  }
537 
538  return {};
539  }
540 
541  void ProvideRequest::setActiveUrl(const zypp::Url &urlToUse) {
542 
543  switch ( this->_message.code () ) {
546  break;
549  break;
552  break;
553  default:
554  // should never happen because we guard the constructor
555  throw std::logic_error("Invalid message type in ProvideRequest");
556  }
557  }
558 
559  ProvideFileItem::ProvideFileItem(const std::vector<zypp::Url> &urls, const ProvideFileSpec &request, ProvidePrivate &parent)
560  : ProvideItem( parent )
561  , _mirrorList ( urls )
562  , _initialSpec ( request )
563  { }
564 
565  ProvideFileItemRef ProvideFileItem::create(const std::vector<zypp::Url> &urls, const ProvideFileSpec &request, ProvidePrivate &parent )
566  {
567  return ProvideFileItemRef( new ProvideFileItem( urls, request, parent ) );
568  }
569 
571  {
572  if ( state() != Uninitialized || _runningReq ) {
573  WAR << "Double init of ProvideFileItem!" << std::endl;
574  return;
575  }
576 
577  auto req = ProvideRequest::create( *this, _mirrorList, _initialSpec );
578  if ( !req ){
579  cancelWithError( req.error() );
580  return ;
581  }
582 
583  if ( enqueueRequest( *req ) ) {
585  updateState( Pending );
586  } else {
587  cancelWithError( ZYPP_EXCPT_PTR(zypp::media::MediaException("Failed to queue request")) );
588  return ;
589  }
590  }
591 
593  {
594  if ( !_promiseCreated ) {
595  _promiseCreated = true;
596  auto promiseRef = std::make_shared<ProvidePromise<ProvideRes>>( shared_this<ProvideItem>() );
597  _promise = promiseRef;
598  return promiseRef;
599  }
600  return _promise.lock();
601  }
602 
604  {
605  _handleRef = std::move(hdl);
606  }
607 
609  {
610  return _handleRef;
611  }
612 
613  void ProvideFileItem::informalMessage ( ProvideQueue &, ProvideRequestRef req, const ProvideMessage &msg )
614  {
615  if ( req != _runningReq ) {
616  WAR << "Received event for unknown request, ignoring" << std::endl;
617  return;
618  }
619 
621  MIL << "Provide File Request: "<< req->url() << " was started" << std::endl;
622  auto log = provider().log();
623 
624  auto locPath = msg.value( ProvideStartedMsgFields::LocalFilename, std::string() ).asString();
625  if ( !locPath.empty() )
626  _targetFile = zypp::Pathname(locPath);
627 
628  locPath = msg.value( ProvideStartedMsgFields::StagingFilename, std::string() ).asString();
629  if ( !locPath.empty() )
630  _stagingFile = zypp::Pathname(locPath);
631 
632  if ( log ) {
633  auto effUrl = req->activeUrl().value_or( zypp::Url() );
634  try {
636  } catch( const zypp::Exception &e ) {
637  ZYPP_CAUGHT(e);
638  }
639 
640  AnyMap m;
641  m["spec"] = _initialSpec;
642  if ( log ) log->requestStart( *this, msg.requestId(), effUrl, m );
644  }
645  }
646  }
647 
648  void zyppng::ProvideFileItem::ProvideFileItem::finishReq( zyppng::ProvideQueue &queue, ProvideRequestRef finishedReq, const ProvideMessage &msg )
649  {
650  if ( finishedReq != _runningReq ) {
651  WAR << "Received event for unknown request, ignoring" << std::endl;
652  return;
653  }
654 
656 
657  auto log = provider().log();
658  if ( log ) {
659  AnyMap m;
660  m["spec"] = _initialSpec;
661  if ( log ) log->requestDone( *this, msg.requestId(), m );
662  }
663 
664  MIL << "Request was successfully finished!" << std::endl;
665  // request is def done
666  _runningReq.reset();
667 
668  std::optional<zypp::ManagedFile> resFile;
669 
670  try {
671  const auto locFilename = msg.value( ProvideFinishedMsgFields::LocalFilename ).asString();
672  const auto cacheHit = msg.value( ProvideFinishedMsgFields::CacheHit ).asBool();
673  const auto &wConf = queue.workerConfig();
674 
675  const bool checkExistsOnly = _initialSpec.checkExistsOnly();
676  const bool doesDownload = wConf.worker_type() == ProvideQueue::Config::Downloading;
677  const bool fileNeedsCleanup = doesDownload || ( wConf.worker_type() == ProvideQueue::Config::CPUBound && wConf.cfg_flags() & ProvideQueue::Config::FileArtifacts );
678 
679  if ( doesDownload && !checkExistsOnly ) {
680 
681  resFile = provider().addToFileCache ( locFilename );
682  if ( !resFile ) {
683  if ( cacheHit ) {
684  MIL << "CACHE MISS, file " << locFilename << " was already removed, queueing again" << std::endl;
685  cacheMiss ( finishedReq );
686  finishedReq->clearForRestart();
687  enqueueRequest( finishedReq );
688  return;
689  } else {
690  // if we reach here it seems that a new file, that was not in cache before, vanished between
691  // providing it and receiving the finished message.
692  // unlikely this can happen but better be safe than sorry
693  cancelWithError( ZYPP_EXCPT_PTR( zypp::media::MediaException("File vanished between downloading and adding it to cache.")) );
694  return;
695  }
696  }
697 
698  } else {
699  resFile = zypp::ManagedFile( zypp::filesystem::Pathname(locFilename) );
700  if ( fileNeedsCleanup && !checkExistsOnly )
701  resFile->setDispose( zypp::filesystem::unlink );
702  else
703  resFile->resetDispose();
704  }
705 
706  _targetFile = locFilename;
707 
708  } catch ( const zypp::Exception &e ) {
709  ZYPP_CAUGHT(e);
710  cancelWithError( std::current_exception() );
711  } catch ( const std::exception &e ) {
712  ZYPP_CAUGHT(e);
713  cancelWithError( std::current_exception() );
714  } catch ( ...) {
715  cancelWithError( std::current_exception() );
716  }
717 
718  // keep the media handle around as long as the file is used by the code
719  auto resObj = std::make_shared<ProvideResourceData>();
720  resObj->_mediaHandle = this->_handleRef;
721  resObj->_myFile = *resFile;
722  resObj->_resourceUrl = *(finishedReq->activeUrl());
723  resObj->_responseHeaders = msg.headers();
724 
725  // if there is a exception escaping the pipeline we need to rethrow it after cleaning up
726  std::exception_ptr excpt;
727  auto p = promise();
728  if ( p ) {
729  try {
730  p->setReady( expected<ProvideRes>::success( ProvideRes( resObj )) );
731  } catch( const zypp::Exception &e ) {
732  ERR << "Caught unhandled pipline exception:" << e << std::endl;
733  ZYPP_CAUGHT(e);
734  excpt = std::current_exception ();
735  } catch ( const std::exception &e ) {
736  ERR << "Caught unhandled pipline exception:" << e.what() << std::endl;
737  ZYPP_CAUGHT(e);
738  excpt = std::current_exception ();
739  } catch ( ...) {
740  ERR << "Caught unhandled unknown exception:" << std::endl;
741  excpt = std::current_exception ();
742  }
743  }
744 
745  updateState( Finished );
746 
747  if ( excpt ) {
748  ERR << "Rethrowing pipeline exception, this is a BUG!" << std::endl;
749  std::rethrow_exception ( excpt );
750  }
751 
752  } else {
753  // on errors we could recover from if we have mirrors we try to redirect
754  switch( msg.code() ) {
756  case NotFound:
757  case ConnectionFailed:
758  //case Timeout:
759  case InvalidChecksum: {
760  auto log = provider().log();
761  MIL << "Request failed trying to recover." << std::endl;
762 
763  // prefilter usable URLs, so the scheduler does not have to
764  std::vector<zypp::Url> usableUrls;
765  std::for_each( _mirrorList.begin (), _mirrorList.end(), [&]( const zypp::Url &url ){
766  if ( !canRedirectTo ( finishedReq, url ) )
767  return;
768  usableUrls.push_back(url);
769  });
770 
771  if ( usableUrls.size() ) {
772  MIL << "Trying to recover by redirecting to a mirror" << std::endl;
773  finishedReq->setUrls(usableUrls);
774 
775  if ( enqueueRequest( finishedReq ) )
776  return;
777  }
778  MIL << "No mirror found or no mirror usable, giving up" << std::endl;
779  break;
780  }
781  default:
782  //all other codes handled by default code
783  break;
784  }
785  ProvideItem::finishReq ( queue, finishedReq, msg );
786  }
787  }
788 
789 
790  void zyppng::ProvideFileItem::cancelWithError( std::exception_ptr error )
791  {
792  if ( _runningReq ) {
793  auto weakThis = weak_from_this ();
794  provider().dequeueRequest ( _runningReq, error );
795  if ( weakThis.expired () )
796  return;
797  }
798 
799  // if we reach this place for some reason finishReq was not called, lets clean up manually
800  _runningReq.reset();
801  auto p = promise();
802  if ( p ) {
803  try {
804  p->setReady( expected<ProvideRes>::error( error ) );
805  } catch( const zypp::Exception &e ) {
806  ZYPP_CAUGHT(e);
807  }
808  }
809  updateState( Finished );
810  }
811 
812  expected<zypp::media::AuthData> ProvideFileItem::authenticationRequired ( ProvideQueue &queue, ProvideRequestRef req, const zypp::Url &effectiveUrl, int64_t lastTimestamp, const std::map<std::string, std::string> &extraFields )
813  {
814  zypp::Url urlToUse = effectiveUrl;
815  if ( _handleRef.isValid() ) {
816  // if we have a attached medium this overrules the URL we are going to ask the user about... this is how the old media backend did handle this
817  // i guess there were never password protected repositories that have different credentials on the redirection targets
818  auto &attachedMedia = provider().attachedMediaInfos();
819  if ( std::find( attachedMedia.begin(), attachedMedia.end(), _handleRef.mediaInfo() ) == attachedMedia.end() )
820  return expected<zypp::media::AuthData>::error( ZYPP_EXCPT_PTR( zypp::media::MediaException("Attachment handle vanished during request.") ) );
821  urlToUse = _handleRef.mediaInfo()->attachedUrl();
822  }
823  return ProvideItem::authenticationRequired( queue, req, urlToUse, lastTimestamp, extraFields );
824  }
825 
827  {
828  zypp::ByteCount providedByNow;
829 
830  bool checkStaging = false;
831  if ( !_targetFile.empty() ) {
833  if ( inf.isExist() && inf.isFile() )
834  providedByNow = zypp::ByteCount( inf.size() );
835  else
836  checkStaging = true;
837  }
838 
839  if ( checkStaging && !_stagingFile.empty() ) {
841  if ( inf.isExist() && inf.isFile() )
842  providedByNow = zypp::ByteCount( inf.size() );
843  }
844 
845  auto baseStats = ProvideItem::makeStats();
846  baseStats._bytesExpected = bytesExpected();
847  baseStats._bytesProvided = providedByNow;
848  return baseStats;
849  }
850 
852  {
854  }
855 
856  AttachMediaItem::AttachMediaItem( const std::vector<zypp::Url> &urls, const ProvideMediaSpec &request, ProvidePrivate &parent )
857  : ProvideItem ( parent )
858  , _mirrorList ( urls )
859  , _initialSpec ( request )
860  { }
861 
863  {
864  MIL << "Killing the AttachMediaItem" << std::endl;
865  }
866 
868  {
869  if ( !_promiseCreated ) {
870  _promiseCreated = true;
871  auto promiseRef = std::make_shared<ProvidePromise<Provide::MediaHandle>>( shared_this<ProvideItem>() );
872  _promise = promiseRef;
873  return promiseRef;
874  }
875  return _promise.lock();
876  }
877 
879  {
880  if ( state() != Uninitialized ) {
881  WAR << "Double init of AttachMediaItem!" << std::endl;
882  return;
883  }
885 
886  if ( _mirrorList.empty() ) {
887  cancelWithError( ZYPP_EXCPT_PTR( zypp::media::MediaException("No usable mirrors in mirrorlist.")) );
888  return;
889  }
890 
891  // shortcut to the provider instance
892  auto &prov= provider();
893 
894  // sanitize the mirrors to contain only URLs that have same worker types
895  std::vector<zypp::Url> usableMirrs;
896  std::optional<ProvideQueue::Config> scheme;
897 
898  for ( auto mirrIt = _mirrorList.begin() ; mirrIt != _mirrorList.end(); mirrIt++ ) {
899  const auto &s = prov.schemeConfig( prov.effectiveScheme( mirrIt->getScheme() ) );
900  if ( !s ) {
901  WAR << "URL: " << *mirrIt << " is not supported, ignoring!" << std::endl;
902  continue;
903  }
904  if ( !scheme ) {
905  scheme = *s;
906  usableMirrs.push_back ( *mirrIt );
907  } else {
908  if ( scheme->worker_type () == s->worker_type () ) {
909  usableMirrs.push_back( *mirrIt );
910  } else {
911  WAR << "URL: " << *mirrIt << " has different worker type than the primary URL: "<< usableMirrs.front() <<", ignoring!" << std::endl;
912  }
913  }
914  }
915 
916  // save the sanitized mirrors
917  _mirrorList = usableMirrs;
918 
919  if ( !scheme || _mirrorList.empty() ) {
920  auto prom = promise();
921  if ( prom ) {
922  try {
923  prom->setReady( expected<Provide::MediaHandle>::error( ZYPP_EXCPT_PTR ( zypp::media::MediaException("No valid mirrors available") )) );
924  } catch( const zypp::Exception &e ) {
925  ZYPP_CAUGHT(e);
926  }
927  }
929  return;
930  }
931 
932  // first check if there is a already attached medium we can use as well
933  auto &attachedMedia = prov.attachedMediaInfos ();
934 
935  // @TODO should we extend the mirrors here if some are not in the mirror list?
936  for ( auto &medium : attachedMedia ) {
937  if ( medium->isSameMedium ( _mirrorList, _initialSpec ) ) {
938  finishWithSuccess ( medium );
939  return;
940  }
941  }
942 
943  for ( auto &otherItem : prov.items() ) {
944  auto attachIt = std::dynamic_pointer_cast<AttachMediaItem>(otherItem);
945  if ( !attachIt // not the right type
946  || attachIt.get() == this // do not attach to ourselves
947  || attachIt->state () == Uninitialized // item was not initialized
948  || attachIt->state () == Finalizing // item cleaning up
949  || attachIt->state () == Finished ) // item done
950  continue;
951 
952  // does this Item attach the same medium?
953  const bool sameMedium = AttachedMediaInfo::isSameMedium( attachIt->_mirrorList, attachIt->_initialSpec, _mirrorList, _initialSpec );
954  if ( !sameMedium )
955  continue;
956 
957  MIL << "Found item providing the same medium, attaching to finished signal and waiting for it to be finished" << std::endl;
958 
959  // it does, connect to its ready signal and just wait
961  return;
962  }
963 
964  _workerType = scheme->worker_type();
965 
966  switch( _workerType ) {
968 
969  // if the media file is empty in the spec we can not do anything
970  // simply pretend attach worked
971  if( _initialSpec.mediaFile().empty() ) {
972  finishWithSuccess( prov.addMedium( zypp::make_intrusive<AttachedMediaInfo>( provider().nextMediaId(), _workerType, _mirrorList.front(), _mirrorList, _initialSpec ) ) );
973  return;
974  }
975 
976  // prepare the verifier with the data
977  auto smvDataLocal = MediaDataVerifier::createVerifier("SuseMediaV1");
978  if ( !smvDataLocal ) {
979  cancelWithError( ZYPP_EXCPT_PTR( zypp::media::MediaException("Unable to verify the medium, no verifier instance was returned.")) );
980  return;
981  }
982 
983  if ( !smvDataLocal->load( _initialSpec.mediaFile() ) ) {
984  cancelWithError( ZYPP_EXCPT_PTR( zypp::media::MediaException("Unable to verify the medium, unable to load local verify data.")) );
985  return;
986  }
987 
988  _verifier = smvDataLocal;
989 
990  std::vector<zypp::Url> urls;
991  urls.reserve( _mirrorList.size () );
992 
993  for ( zypp::Url url : _mirrorList ) {
994  url.appendPathName ( ( zypp::str::Format("/media.%d/media") % _initialSpec.medianr() ).asString() );
995  urls.push_back(url);
996  }
997 
998  // for downloading schemes we ask for the /media.x/media file and check the data manually
999  ProvideFileSpec spec;
1001 
1002  // disable metalink
1003  spec.customHeaders().set( std::string(NETWORK_METALINK_ENABLED), false );
1004 
1005  auto req = ProvideRequest::create( *this, urls, spec );
1006  if ( !req ) {
1007  cancelWithError( req.error() );
1008  return;
1009  }
1010  if ( !enqueueRequest( *req ) ) {
1011  cancelWithError( ZYPP_EXCPT_PTR(zypp::media::MediaException("Failed to queue request")) );
1012  return;
1013  }
1015  break;
1016  }
1019 
1020  const auto &newId = provider().nextMediaId();
1021  auto req = ProvideRequest::create( *this, _mirrorList, newId, _initialSpec );
1022  if ( !req ) {
1023  cancelWithError( req.error() );
1024  return;
1025  }
1026  if ( !enqueueRequest( *req ) ) {
1027  ERR << "Failed to queue request" << std::endl;
1028  cancelWithError( ZYPP_EXCPT_PTR(zypp::media::MediaException("Failed to queue request")) );
1029  return;
1030  }
1031  break;
1032  }
1033  default: {
1034  auto prom = promise();
1035  if ( prom ) {
1036  try {
1037  prom->setReady( expected<Provide::MediaHandle>::error( ZYPP_EXCPT_PTR ( zypp::media::MediaException("URL scheme does not support attaching.") )) );
1038  } catch( const zypp::Exception &e ) {
1039  ZYPP_CAUGHT(e);
1040  }
1041  }
1042  updateState( Finished );
1043  return;
1044  }
1045  }
1046  }
1047 
1048  void AttachMediaItem::finishWithSuccess( AttachedMediaInfo_Ptr medium )
1049  {
1050 
1052 
1053  auto prom = promise();
1054  try {
1055  if ( prom ) {
1056  try {
1057  prom->setReady( expected<Provide::MediaHandle>::success( Provide::MediaHandle( *static_cast<Provide*>( provider().z_func() ), medium ) ) );
1058  } catch( const zypp::Exception &e ) {
1059  ZYPP_CAUGHT(e);
1060  }
1061  }
1062  } catch ( const std::exception &e ) {
1063  ERR << "WTF " << e.what () << std::endl;
1064  } catch ( ... ) {
1065  ERR << "WTF " << std::endl;
1066  }
1067 
1068  // tell others as well
1070 
1071  prom->isReady ();
1072 
1073  MIL << "Before setFinished" << std::endl;
1074  updateState( Finished );
1075  return;
1076  }
1077 
1078  void AttachMediaItem::cancelWithError( std::exception_ptr error )
1079  {
1080  MIL << "Cancelling Item with error" << std::endl;
1082 
1083  // tell children
1085 
1086  if ( _runningReq ) {
1087  // we might get deleted when calling dequeueRequest
1088  auto weakThis = weak_from_this ();
1089  provider().dequeueRequest ( _runningReq, error );
1090  if ( weakThis.expired () )
1091  return;
1092  }
1093 
1094  // if we reach this place we had no runningReq, clean up manually
1095  _runningReq.reset();
1096  _masterItemConn.disconnect();
1097 
1098  auto p = promise();
1099  if ( p ) {
1100  try {
1101  p->setReady( expected<zyppng::Provide::MediaHandle>::error( error ) );
1102  } catch( const zypp::Exception &e ) {
1103  ZYPP_CAUGHT(e);
1104  }
1105  }
1106  updateState( Finished );
1107  }
1108 
1110  {
1111 
1112  _masterItemConn.disconnect();
1113 
1114  if ( result ) {
1115  finishWithSuccess( AttachedMediaInfo_Ptr(result.get()) );
1116  } else {
1117  try {
1118  std::rethrow_exception ( result.error() );
1119  } catch ( const zypp::media::MediaRequestCancelledException & e) {
1120  // in case a item was cancelled, we revert to Pending state and trigger the scheduler.
1121  // This will make sure that all our sibilings that also depend on the master
1122  // can revert to pending state and we only get one new master in the next schedule run
1123  MIL_PRV << "Master item was cancelled, reverting to Uninitialized state and waiting for scheduler to run again" << std::endl;
1126 
1127  } catch ( ... ) {
1128  cancelWithError( std::current_exception() );
1129  }
1130  }
1131  }
1132 
1133  AttachMediaItemRef AttachMediaItem::create( const std::vector<zypp::Url> &urls, const ProvideMediaSpec &request, ProvidePrivate &parent )
1134  {
1135  return AttachMediaItemRef( new AttachMediaItem(urls, request, parent) );
1136  }
1137 
1139  {
1140  return _sigReady;
1141  }
1142 
1143  void AttachMediaItem::finishReq ( ProvideQueue &queue, ProvideRequestRef finishedReq, const ProvideMessage &msg )
1144  {
1145  if ( finishedReq != _runningReq ) {
1146  WAR << "Received event for unknown request, ignoring" << std::endl;
1147  return;
1148  }
1149 
1151  // success
1153 
1155 
1156  zypp::Url baseUrl = *finishedReq->activeUrl();
1157  // remove /media.n/media
1158  baseUrl.setPathName( zypp::Pathname(baseUrl.getPathName()).dirname().dirname() );
1159 
1160  // we got the file, lets parse it
1161  auto smvDataRemote = MediaDataVerifier::createVerifier("SuseMediaV1");
1162  if ( !smvDataRemote ) {
1163  return cancelWithError( ZYPP_EXCPT_PTR( zypp::media::MediaException("Unable to verify the medium, no verifier instance was returned.")) );
1164  }
1165 
1166  if ( !smvDataRemote->load( msg.value( ProvideFinishedMsgFields::LocalFilename ).asString() ) ) {
1167  return cancelWithError( ZYPP_EXCPT_PTR( zypp::media::MediaException("Unable to verify the medium, unable to load remote verify data.")) );
1168  }
1169 
1170  // check if we got a valid media file
1171  if ( !smvDataRemote->valid () ) {
1172  return cancelWithError( ZYPP_EXCPT_PTR( zypp::media::MediaException("Unable to verify the medium, unable to load local verify data.")) );
1173  }
1174 
1175  // check if the received file matches with the one we have in the spec
1176  if (! _verifier->matches( smvDataRemote ) ) {
1177  DBG << "expect: " << _verifier << " medium " << _initialSpec.medianr() << std::endl;
1178  DBG << "remote: " << smvDataRemote << std::endl;
1179  return cancelWithError( ZYPP_EXCPT_PTR( zypp::media::MediaNotDesiredException( *finishedReq->activeUrl() ) ) );
1180  }
1181 
1182  // all good, register the medium and tell all child items
1183  _runningReq.reset();
1184 
1185  return finishWithSuccess( provider().addMedium( zypp::make_intrusive<AttachedMediaInfo>( provider().nextMediaId(), _workerType, baseUrl, _mirrorList, _initialSpec) ) );
1186 
1187  } else if ( msg.code() == ProvideMessage::Code::NotFound ) {
1188 
1189  // simple downloading attachment we need to check the media file contents
1190  // in case of a error we might tolerate a file not found error in certain situations
1191  if ( _verifier->totalMedia () == 1 ) {
1192  // relaxed , tolerate a vanished media file
1193  _runningReq.reset();
1194 
1195  return finishWithSuccess( provider().addMedium( zypp::make_intrusive<AttachedMediaInfo>( provider().nextMediaId(), _workerType, _mirrorList.front(), _mirrorList, _initialSpec ) ) );
1196  }
1197  }
1198  } else {
1199  // real device attach
1200  if ( msg.code() == ProvideMessage::Code::AttachFinished ) {
1201 
1202  std::optional<zypp::Pathname> mntPoint;
1204  if ( mountPtVal.valid() && mountPtVal.isString() ) {
1205  mntPoint = zypp::Pathname(mountPtVal.asString());
1206  }
1207 
1208  _runningReq.reset();
1209  return finishWithSuccess( provider().addMedium( zypp::make_intrusive<AttachedMediaInfo>(
1210  finishedReq->provideMessage().value( AttachMsgFields::AttachId ).asString()
1211  , queue.weak_this<ProvideQueue>()
1212  , _workerType
1213  , *finishedReq->activeUrl()
1214  , std::vector<zypp::Url>{} // no mirrors
1215  , _initialSpec
1216  , mntPoint ) ) );
1217  }
1218  }
1219 
1220  // unhandled message , let the base impl do it
1221  return ProvideItem::finishReq ( queue, finishedReq, msg );
1222  }
1223 
1224  expected<zypp::media::AuthData> AttachMediaItem::authenticationRequired ( ProvideQueue &queue, ProvideRequestRef req, const zypp::Url &effectiveUrl, int64_t lastTimestamp, const std::map<std::string, std::string> &extraFields )
1225  {
1226  zypp::Url baseUrl = effectiveUrl;
1228  // remove /media.n/media
1229  baseUrl.setPathName( zypp::Pathname(baseUrl.getPathName()).dirname().dirname() );
1230  }
1231  return ProvideItem::authenticationRequired( queue, req, baseUrl, lastTimestamp, extraFields );
1232  }
1233 
1234 }
std::vector< zypp::Url > _mirrorList
bool safeRedirectTo(ProvideRequestRef startedReq, const zypp::Url &url)
Definition: provideitem.cc:95
expected< zypp::media::AuthData > authenticationRequired(ProvideQueue &queue, ProvideRequestRef req, const zypp::Url &effectiveUrl, int64_t lastTimestamp, const std::map< std::string, std::string > &extraFields) override
#define MIL
Definition: Logger.h:100
virtual bool enqueueRequest(ProvideRequestRef request)
Definition: provideitem.cc:448
constexpr std::string_view Url("url")
constexpr std::string_view LocalFilename("local_filename")
const std::string & asString() const
static ProvideFileItemRef create(const std::vector< zypp::Url > &urls, const ProvideFileSpec &request, ProvidePrivate &parent)
Definition: provideitem.cc:565
constexpr std::string_view AttachId("attach_id")
ProvideQueue::Config::WorkerType _workerType
ProvidePromiseWeakRef< Provide::MediaHandle > _promise
static constexpr std::string_view DEFAULT_MEDIA_VERIFIER("SuseMediaV1")
AttachMediaItem(const std::vector< zypp::Url > &urls, const ProvideMediaSpec &request, ProvidePrivate &parent)
Definition: provideitem.cc:856
constexpr std::string_view NETWORK_METALINK_ENABLED("zypp-nw-metalink-enabled")
constexpr std::string_view VerifyData("verify_data")
void finishWithSuccess(AttachedMediaInfo_Ptr medium)
expected< zypp::media::AuthData > authenticationRequired(ProvideQueue &queue, ProvideRequestRef req, const zypp::Url &effectiveUrl, int64_t lastTimestamp, const std::map< std::string, std::string > &extraFields) override
Definition: provideitem.cc:812
ProvideQueueWeakRef _myQueue
Definition: provideitem_p.h:90
constexpr std::string_view Filename("filename")
Signal< std::optional< zypp::media::AuthData > const zypp::Url &reqUrl, const std::string &triedUsername, const std::map< std::string, std::string > &extraValues) > _sigAuthRequired
Definition: provide_p.h:97
Store and operate with byte count.
Definition: ByteCount.h:31
#define ZYPP_IMPL_PRIVATE(Class)
Definition: zyppglobal.h:92
virtual void cacheMiss(ProvideRequestRef req)
Definition: provideitem.cc:180
ProvidePromiseRef< ProvideRes > promise()
Definition: provideitem.cc:592
void initialize() override
Definition: provideitem.cc:878
void save()
Saves any unsaved credentials added via addUserCred() or addGlobalCred() methods. ...
std::string nextMediaId() const
Definition: provide.cc:803
MediaDataVerifierRef _verifier
virtual void finishReq(ProvideQueue &queue, ProvideRequestRef finishedReq, const ProvideMessage &msg)
Definition: provideitem.cc:190
std::shared_ptr< ProvidePromise< T > > ProvidePromiseRef
Definition: providefwd_p.h:31
const zypp::Pathname & deltafile() const
The existing deltafile that can be used to reduce download size ( zchunk or metalink ) ...
Definition: providespec.cc:245
Signal< void(const zyppng::expected< AttachedMediaInfo * > &)> _sigReady
virtual ItemStats makeStats()
Definition: provideitem.cc:159
void onMasterItemReady(const zyppng::expected< AttachedMediaInfo *> &result)
AuthData_Ptr getCred(const Url &url)
Get credentials for the specified url.
const std::string & label() const
Definition: providespec.cc:100
std::chrono::steady_clock::time_point _pulseTime
Definition: provideitem.h:46
Convenient building of std::string with boost::format.
Definition: String.h:253
static expected error(ConsParams &&...params)
Definition: expected.h:126
constexpr std::string_view VerifyType("verify_type")
void initialize() override
Definition: provideitem.cc:570
#define ZYPP_EXCPT_PTR(EXCPT)
Drops a logline and returns Exception as a std::exception_ptr.
Definition: Exception.h:463
State state() const
Definition: provideitem.cc:495
ProvideMessage _message
Definition: provideitem_p.h:86
time_t timestampForCredDatabase(const zypp::Url &url)
zyppng::AttachedMediaInfo_constPtr mediaInfo() const
Definition: provide.cc:998
#define ERR
Definition: Logger.h:102
std::vector< AttachedMediaInfo_Ptr > & attachedMediaInfos()
Definition: provide.cc:739
#define Z_D()
Definition: zyppglobal.h:105
AutoDispose< const Pathname > ManagedFile
A Pathname plus associated cleanup code to be executed when path is no longer needed.
Definition: ManagedFile.h:27
const std::optional< zypp::Url > activeUrl() const
Returns the currenty active URL as set by the scheduler.
Definition: provideitem.cc:510
void updateState(const State newState)
Definition: provideitem.cc:458
constexpr std::string_view CheckExistOnly("check_existance_only")
WeakPtr parent() const
Definition: base.cc:26
std::string asString(TInt val, char zero='0', char one='1')
For printing bits.
Definition: Bit.h:57
constexpr std::string_view NewUrl("new_url")
bool empty() const
Test for an empty path.
Definition: Pathname.h:116
ProvideFileSpec _initialSpec
void setPathName(const std::string &path, EEncoding eflag=zypp::url::E_DECODED)
Set the path name.
Definition: Url.cc:782
std::string asString() const
Returns a default string representation of the Url object.
Definition: Url.cc:515
constexpr std::string_view LocalFilename("local_filename")
FieldVal value(const std::string_view &str, const FieldVal &defaultVal=FieldVal()) const
void redirectTo(ProvideRequestRef startedReq, const zypp::Url &url)
Definition: provideitem.cc:104
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...
Definition: String.h:212
unsigned medianr() const
Definition: providespec.cc:109
static auto connect(typename internal::MemberFunction< SenderFunc >::ClassType &s, SenderFunc &&sFun, typename internal::MemberFunction< ReceiverFunc >::ClassType &recv, ReceiverFunc &&rFunc)
Definition: base.h:142
zypp::Pathname mediaFile() const
Definition: providespec.cc:118
const std::string & asString() const
String representation.
Definition: Pathname.h:93
const Config & workerConfig() const
bool isSameMedium(const std::vector< zypp::Url > &urls, const ProvideMediaSpec &spec)
bool isExist() const
Return whether valid stat info exists.
Definition: PathInfo.h:286
Just inherits Exception to separate media exceptions.
virtual void informalMessage(ProvideQueue &, ProvideRequestRef req, const ProvideMessage &msg)
Definition: provideitem.cc:167
Pathname dirname() const
Return all but the last component od this path.
Definition: Pathname.h:126
zypp::Url url() const
Definition: provideitem_p.h:69
#define WAR
Definition: Logger.h:101
std::string asCompleteString() const
Returns a complete string representation of the Url object.
Definition: Url.cc:523
void informalMessage(ProvideQueue &, ProvideRequestRef req, const ProvideMessage &msg) override
Definition: provideitem.cc:613
const std::optional< ItemStats > & currentStats() const
Definition: provideitem.cc:122
std::weak_ptr< T > weak_this() const
Definition: base.h:123
ProvideStatusRef log()
Definition: provide_p.h:90
void cancelWithError(std::exception_ptr error) override
Definition: provideitem.cc:790
ItemStats makeStats() override
Definition: provideitem.cc:826
void schedule(ScheduleReason reason)
Definition: provide.cc:38
ProvideFileItem(const std::vector< zypp::Url > &urls, const ProvideFileSpec &request, ProvidePrivate &parent)
Definition: provideitem.cc:559
static expected< ProvideRequestRef > create(ProvideItem &owner, const std::vector< zypp::Url > &urls, const std::string &id, ProvideMediaSpec &spec)
Definition: provideitem.cc:27
WorkerType worker_type() const
zypp::ByteCount bytesExpected() const override
Definition: provideitem.cc:851
const zypp::ByteCount & downloadSize() const
The size of the resource on the server.
Definition: providespec.cc:209
constexpr std::string_view Reason("reason")
void set(const std::string &key, Value val)
void cancelWithError(std::exception_ptr error) override
SignalProxy< void(const zyppng::expected< AttachedMediaInfo * > &) > sigReady()
int unlink(const Pathname &path)
Like &#39;unlink&#39;.
Definition: PathInfo.cc:705
const zypp::Pathname & destFilenameHint() const
Definition: providespec.cc:191
ProvidePrivate & provider()
Definition: provideitem.cc:90
static expected success(ConsParams &&...params)
Definition: expected.h:115
constexpr std::string_view NewUrl("new_url")
void setCurrentQueue(ProvideQueueRef ref)
Definition: provideitem.cc:500
void setValue(const std::string &name, const FieldVal &value)
constexpr std::string_view DeltaFile("delta_file")
#define MIL_PRV
Definition: providedbg_p.h:35
static MediaDataVerifierRef createVerifier(const std::string &verifierType)
virtual bool canRedirectTo(ProvideRequestRef startedReq, const zypp::Url &url)
Definition: provideitem.cc:110
const std::vector< ProvideMessage::FieldVal > & values(const std::string_view &str) const
zypp::Pathname _targetFile
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
Definition: Exception.h:475
bool dequeueRequest(ProvideRequestRef req, std::exception_ptr error)
Definition: provide.cc:837
void finishReq(ProvideQueue &queue, ProvideRequestRef finishedReq, const ProvideMessage &msg) override
Base class for Exception.
Definition: Exception.h:152
HeaderValueMap & customHeaders()
Definition: providespec.cc:127
static AttachMediaItemRef create(const std::vector< zypp::Url > &urls, const ProvideMediaSpec &request, ProvidePrivate &parent)
void setActiveUrl(const zypp::Url &urlToUse)
Definition: provideitem.cc:541
constexpr std::string_view Url("url")
constexpr std::string_view LocalMountPoint("local_mountpoint")
virtual expected< zypp::media::AuthData > authenticationRequired(ProvideQueue &queue, ProvideRequestRef req, const zypp::Url &effectiveUrl, int64_t lastTimestamp, const std::map< std::string, std::string > &extraFields)
Definition: provideitem.cc:399
std::string getPathName(EEncoding eflag=zypp::url::E_DECODED) const
Returns the path name from the URL.
Definition: Url.cc:622
constexpr std::string_view Url("url")
unsigned int MediaNr
Definition: MediaManager.h:32
ProvidePromiseRef< Provide::MediaHandle > promise()
Definition: provideitem.cc:867
zypp::ByteCount _expectedBytes
virtual void released()
Definition: provideitem.cc:486
ProvideQueueRef currentQueue()
Definition: provideitem.cc:505
constexpr std::string_view MetalinkEnabled("metalink_enabled")
Wrapper class for ::stat/::lstat.
Definition: PathInfo.h:225
Provide::MediaHandle _handleRef
virtual void cancelWithError(std::exception_ptr error)=0
constexpr std::string_view StagingFilename("staging_filename")
Provide::MediaHandle & mediaRef()
Definition: provideitem.cc:608
std::vector< zypp::Url > _mirrorList
constexpr std::string_view Url("url")
#define ZYPP_FWD_CURRENT_EXCPT()
Drops a logline and returns the current Exception as a std::exception_ptr.
Definition: Exception.h:471
std::unordered_map< std::string, boost::any > AnyMap
Definition: provide.h:47
const HeaderValueMap & headers() const
virtual zypp::ByteCount bytesExpected() const
Definition: provideitem.cc:154
void addCred(const AuthData &cred)
Add new credentials with user callbacks.
ProvideMediaSpec _initialSpec
void setMediaRef(Provide::MediaHandle &&hdl)
Definition: provideitem.cc:603
const std::optional< ItemStats > & previousStats() const
Definition: provideitem.cc:127
ProvidePromiseWeakRef< ProvideRes > _promise
HeaderValueMap & customHeaders()
Definition: providespec.cc:251
constexpr std::string_view CacheHit("cacheHit")
virtual std::chrono::steady_clock::time_point startTime() const
Definition: provideitem.cc:132
constexpr std::string_view LastUser("username")
zypp::Pathname _stagingFile
Url manipulation class.
Definition: Url.h:92
virtual std::chrono::steady_clock::time_point finishedTime() const
Definition: provideitem.cc:137
bool checkExistsOnly() const
Definition: providespec.cc:197
#define DBG
Definition: Logger.h:99
ProvideRequestRef _runningReq
Definition: provideitem.h:189
constexpr std::string_view ExpectedFilesize("expected_filesize")