libzypp  17.36.1
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  ProvideItem::finishReq ( queue, finishedReq, msg );
754  }
755  }
756 
757 
758  void zyppng::ProvideFileItem::cancelWithError( std::exception_ptr error )
759  {
760  if ( _runningReq ) {
761  auto weakThis = weak_from_this ();
762  provider().dequeueRequest ( _runningReq, error );
763  if ( weakThis.expired () )
764  return;
765  }
766 
767  // if we reach this place for some reason finishReq was not called, lets clean up manually
768  _runningReq.reset();
769  auto p = promise();
770  if ( p ) {
771  try {
772  p->setReady( expected<ProvideRes>::error( error ) );
773  } catch( const zypp::Exception &e ) {
774  ZYPP_CAUGHT(e);
775  }
776  }
777  updateState( Finished );
778  }
779 
780  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 )
781  {
782  zypp::Url urlToUse = effectiveUrl;
783  if ( _handleRef.isValid() ) {
784  // 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
785  // i guess there were never password protected repositories that have different credentials on the redirection targets
786  auto &attachedMedia = provider().attachedMediaInfos();
787  if ( std::find( attachedMedia.begin(), attachedMedia.end(), _handleRef.mediaInfo() ) == attachedMedia.end() )
788  return expected<zypp::media::AuthData>::error( ZYPP_EXCPT_PTR( zypp::media::MediaException("Attachment handle vanished during request.") ) );
789  urlToUse = _handleRef.mediaInfo()->_attachedUrl;
790  }
791  return ProvideItem::authenticationRequired( queue, req, urlToUse, lastTimestamp, extraFields );
792  }
793 
795  {
796  zypp::ByteCount providedByNow;
797 
798  bool checkStaging = false;
799  if ( !_targetFile.empty() ) {
801  if ( inf.isExist() && inf.isFile() )
802  providedByNow = zypp::ByteCount( inf.size() );
803  else
804  checkStaging = true;
805  }
806 
807  if ( checkStaging && !_stagingFile.empty() ) {
809  if ( inf.isExist() && inf.isFile() )
810  providedByNow = zypp::ByteCount( inf.size() );
811  }
812 
813  auto baseStats = ProvideItem::makeStats();
814  baseStats._bytesExpected = bytesExpected();
815  baseStats._bytesProvided = providedByNow;
816  return baseStats;
817  }
818 
820  {
822  }
823 
824  AttachMediaItem::AttachMediaItem( const std::vector<zypp::Url> &urls, const ProvideMediaSpec &request, ProvidePrivate &parent )
825  : ProvideItem ( parent )
826  , _mirrorList ( urls )
827  , _initialSpec ( request )
828  { }
829 
831  {
832  MIL << "Killing the AttachMediaItem" << std::endl;
833  }
834 
836  {
837  if ( !_promiseCreated ) {
838  _promiseCreated = true;
839  auto promiseRef = std::make_shared<ProvidePromise<Provide::MediaHandle>>( shared_this<ProvideItem>() );
840  _promise = promiseRef;
841  return promiseRef;
842  }
843  return _promise.lock();
844  }
845 
847  {
848  if ( state() != Uninitialized ) {
849  WAR << "Double init of AttachMediaItem!" << std::endl;
850  return;
851  }
853 
854  if ( _mirrorList.empty() ) {
855  cancelWithError( ZYPP_EXCPT_PTR( zypp::media::MediaException("No usable mirrors in mirrorlist.")) );
856  return;
857  }
858 
859  // shortcut to the provider instance
860  auto &prov= provider();
861 
862  // sanitize the mirrors to contain only URLs that have same worker types
863  std::vector<zypp::Url> usableMirrs;
864  std::optional<ProvideQueue::Config> scheme;
865 
866  for ( auto mirrIt = _mirrorList.begin() ; mirrIt != _mirrorList.end(); mirrIt++ ) {
867  const auto &s = prov.schemeConfig( prov.effectiveScheme( mirrIt->getScheme() ) );
868  if ( !s ) {
869  WAR << "URL: " << *mirrIt << " is not supported, ignoring!" << std::endl;
870  continue;
871  }
872  if ( !scheme ) {
873  scheme = *s;
874  usableMirrs.push_back ( *mirrIt );
875  } else {
876  if ( scheme->worker_type () == s->worker_type () ) {
877  usableMirrs.push_back( *mirrIt );
878  } else {
879  WAR << "URL: " << *mirrIt << " has different worker type than the primary URL: "<< usableMirrs.front() <<", ignoring!" << std::endl;
880  }
881  }
882  }
883 
884  // save the sanitized mirrors
885  _mirrorList = usableMirrs;
886 
887  if ( !scheme || _mirrorList.empty() ) {
888  auto prom = promise();
889  if ( prom ) {
890  try {
891  prom->setReady( expected<Provide::MediaHandle>::error( ZYPP_EXCPT_PTR ( zypp::media::MediaException("No valid mirrors available") )) );
892  } catch( const zypp::Exception &e ) {
893  ZYPP_CAUGHT(e);
894  }
895  }
897  return;
898  }
899 
900  // first check if there is a already attached medium we can use as well
901  auto &attachedMedia = prov.attachedMediaInfos ();
902 
903  for ( auto &medium : attachedMedia ) {
904  if ( medium->isSameMedium ( _mirrorList, _initialSpec ) ) {
905  finishWithSuccess ( medium );
906  return;
907  }
908  }
909 
910  for ( auto &otherItem : prov.items() ) {
911  auto attachIt = std::dynamic_pointer_cast<AttachMediaItem>(otherItem);
912  if ( !attachIt // not the right type
913  || attachIt.get() == this // do not attach to ourselves
914  || attachIt->state () == Uninitialized // item was not initialized
915  || attachIt->state () == Finalizing // item cleaning up
916  || attachIt->state () == Finished ) // item done
917  continue;
918 
919  // does this Item attach the same medium?
920  const auto sameMedium = attachIt->_initialSpec.isSameMedium( _initialSpec);
921  if ( zypp::indeterminate(sameMedium) ) {
922  // check the primary URLs ( should we do a full list compare? )
923  if ( attachIt->_mirrorList.front() != _mirrorList.front() )
924  continue;
925  }
926  else if ( !(bool)sameMedium )
927  continue;
928 
929  MIL << "Found item providing the same medium, attaching to finished signal and waiting for it to be finished" << std::endl;
930 
931  // it does, connect to its ready signal and just wait
933  return;
934  }
935 
936  _workerType = scheme->worker_type();
937 
938  switch( _workerType ) {
940 
941  // if the media file is empty in the spec we can not do anything
942  // simply pretend attach worked
943  if( _initialSpec.mediaFile().empty() ) {
944  finishWithSuccess( prov.addMedium( zypp::make_intrusive<AttachedMediaInfo>( provider().nextMediaId(), _workerType, _mirrorList.front(), _initialSpec ) ) );
945  return;
946  }
947 
948  // prepare the verifier with the data
949  auto smvDataLocal = MediaDataVerifier::createVerifier("SuseMediaV1");
950  if ( !smvDataLocal ) {
951  cancelWithError( ZYPP_EXCPT_PTR( zypp::media::MediaException("Unable to verify the medium, no verifier instance was returned.")) );
952  return;
953  }
954 
955  if ( !smvDataLocal->load( _initialSpec.mediaFile() ) ) {
956  cancelWithError( ZYPP_EXCPT_PTR( zypp::media::MediaException("Unable to verify the medium, unable to load local verify data.")) );
957  return;
958  }
959 
960  _verifier = smvDataLocal;
961 
962  std::vector<zypp::Url> urls;
963  urls.reserve( _mirrorList.size () );
964 
965  for ( zypp::Url url : _mirrorList ) {
966  url.appendPathName ( ( zypp::str::Format("/media.%d/media") % _initialSpec.medianr() ).asString() );
967  urls.push_back(url);
968  }
969 
970  // for downloading schemes we ask for the /media.x/media file and check the data manually
971  ProvideFileSpec spec;
973 
974  // disable metalink
975  spec.customHeaders().set( std::string(NETWORK_METALINK_ENABLED), false );
976 
977  auto req = ProvideRequest::create( *this, urls, spec );
978  if ( !req ) {
979  cancelWithError( req.error() );
980  return;
981  }
982  if ( !enqueueRequest( *req ) ) {
983  cancelWithError( ZYPP_EXCPT_PTR(zypp::media::MediaException("Failed to queue request")) );
984  return;
985  }
987  break;
988  }
991 
992  const auto &newId = provider().nextMediaId();
993  auto req = ProvideRequest::create( *this, _mirrorList, newId, _initialSpec );
994  if ( !req ) {
995  cancelWithError( req.error() );
996  return;
997  }
998  if ( !enqueueRequest( *req ) ) {
999  ERR << "Failed to queue request" << std::endl;
1000  cancelWithError( ZYPP_EXCPT_PTR(zypp::media::MediaException("Failed to queue request")) );
1001  return;
1002  }
1003  break;
1004  }
1005  default: {
1006  auto prom = promise();
1007  if ( prom ) {
1008  try {
1009  prom->setReady( expected<Provide::MediaHandle>::error( ZYPP_EXCPT_PTR ( zypp::media::MediaException("URL scheme does not support attaching.") )) );
1010  } catch( const zypp::Exception &e ) {
1011  ZYPP_CAUGHT(e);
1012  }
1013  }
1014  updateState( Finished );
1015  return;
1016  }
1017  }
1018  }
1019 
1020  void AttachMediaItem::finishWithSuccess( AttachedMediaInfo_Ptr medium )
1021  {
1022 
1024 
1025  auto prom = promise();
1026  try {
1027  if ( prom ) {
1028  try {
1029  prom->setReady( expected<Provide::MediaHandle>::success( Provide::MediaHandle( *static_cast<Provide*>( provider().z_func() ), medium ) ) );
1030  } catch( const zypp::Exception &e ) {
1031  ZYPP_CAUGHT(e);
1032  }
1033  }
1034  } catch ( const std::exception &e ) {
1035  ERR << "WTF " << e.what () << std::endl;
1036  } catch ( ... ) {
1037  ERR << "WTF " << std::endl;
1038  }
1039 
1040  // tell others as well
1042 
1043  prom->isReady ();
1044 
1045  MIL << "Before setFinished" << std::endl;
1046  updateState( Finished );
1047  return;
1048  }
1049 
1050  void AttachMediaItem::cancelWithError( std::exception_ptr error )
1051  {
1052  MIL << "Cancelling Item with error" << std::endl;
1054 
1055  // tell children
1057 
1058  if ( _runningReq ) {
1059  // we might get deleted when calling dequeueRequest
1060  auto weakThis = weak_from_this ();
1061  provider().dequeueRequest ( _runningReq, error );
1062  if ( weakThis.expired () )
1063  return;
1064  }
1065 
1066  // if we reach this place we had no runningReq, clean up manually
1067  _runningReq.reset();
1068  _masterItemConn.disconnect();
1069 
1070  auto p = promise();
1071  if ( p ) {
1072  try {
1073  p->setReady( expected<zyppng::Provide::MediaHandle>::error( error ) );
1074  } catch( const zypp::Exception &e ) {
1075  ZYPP_CAUGHT(e);
1076  }
1077  }
1078  updateState( Finished );
1079  }
1080 
1082  {
1083 
1084  _masterItemConn.disconnect();
1085 
1086  if ( result ) {
1087  finishWithSuccess( AttachedMediaInfo_Ptr(result.get()) );
1088  } else {
1089  try {
1090  std::rethrow_exception ( result.error() );
1091  } catch ( const zypp::media::MediaRequestCancelledException & e) {
1092  // in case a item was cancelled, we revert to Pending state and trigger the scheduler.
1093  // This will make sure that all our sibilings that also depend on the master
1094  // can revert to pending state and we only get one new master in the next schedule run
1095  MIL_PRV << "Master item was cancelled, reverting to Uninitialized state and waiting for scheduler to run again" << std::endl;
1098 
1099  } catch ( ... ) {
1100  cancelWithError( std::current_exception() );
1101  }
1102  }
1103  }
1104 
1105  AttachMediaItemRef AttachMediaItem::create( const std::vector<zypp::Url> &urls, const ProvideMediaSpec &request, ProvidePrivate &parent )
1106  {
1107  return AttachMediaItemRef( new AttachMediaItem(urls, request, parent) );
1108  }
1109 
1111  {
1112  return _sigReady;
1113  }
1114 
1115  void AttachMediaItem::finishReq ( ProvideQueue &queue, ProvideRequestRef finishedReq, const ProvideMessage &msg )
1116  {
1117  if ( finishedReq != _runningReq ) {
1118  WAR << "Received event for unknown request, ignoring" << std::endl;
1119  return;
1120  }
1121 
1123  // success
1125 
1127 
1128  zypp::Url baseUrl = *finishedReq->activeUrl();
1129  // remove /media.n/media
1130  baseUrl.setPathName( zypp::Pathname(baseUrl.getPathName()).dirname().dirname() );
1131 
1132  // we got the file, lets parse it
1133  auto smvDataRemote = MediaDataVerifier::createVerifier("SuseMediaV1");
1134  if ( !smvDataRemote ) {
1135  return cancelWithError( ZYPP_EXCPT_PTR( zypp::media::MediaException("Unable to verify the medium, no verifier instance was returned.")) );
1136  }
1137 
1138  if ( !smvDataRemote->load( msg.value( ProvideFinishedMsgFields::LocalFilename ).asString() ) ) {
1139  return cancelWithError( ZYPP_EXCPT_PTR( zypp::media::MediaException("Unable to verify the medium, unable to load remote verify data.")) );
1140  }
1141 
1142  // check if we got a valid media file
1143  if ( !smvDataRemote->valid () ) {
1144  return cancelWithError( ZYPP_EXCPT_PTR( zypp::media::MediaException("Unable to verify the medium, unable to load local verify data.")) );
1145  }
1146 
1147  // check if the received file matches with the one we have in the spec
1148  if (! _verifier->matches( smvDataRemote ) ) {
1149  DBG << "expect: " << _verifier << " medium " << _initialSpec.medianr() << std::endl;
1150  DBG << "remote: " << smvDataRemote << std::endl;
1151  return cancelWithError( ZYPP_EXCPT_PTR( zypp::media::MediaNotDesiredException( *finishedReq->activeUrl() ) ) );
1152  }
1153 
1154  // all good, register the medium and tell all child items
1155  _runningReq.reset();
1156  return finishWithSuccess( provider().addMedium( zypp::make_intrusive<AttachedMediaInfo>( provider().nextMediaId(), _workerType, baseUrl, _initialSpec) ) );
1157 
1158  } else if ( msg.code() == ProvideMessage::Code::NotFound ) {
1159 
1160  // simple downloading attachment we need to check the media file contents
1161  // in case of a error we might tolerate a file not found error in certain situations
1162  if ( _verifier->totalMedia () == 1 ) {
1163  // relaxed , tolerate a vanished media file
1164  _runningReq.reset();
1165 
1166  return finishWithSuccess( provider().addMedium( zypp::make_intrusive<AttachedMediaInfo>( provider().nextMediaId(), _workerType, _mirrorList.front(), _initialSpec ) ) );
1167  } else {
1168  return ProvideItem::finishReq ( queue, finishedReq, msg );
1169  }
1170  } else {
1171  return ProvideItem::finishReq ( queue, finishedReq, msg );
1172  }
1173  } else {
1174  // real device attach
1175  if ( msg.code() == ProvideMessage::Code::AttachFinished ) {
1176 
1177  std::optional<zypp::Pathname> mntPoint;
1179  if ( mountPtVal.valid() && mountPtVal.isString() ) {
1180  mntPoint = zypp::Pathname(mountPtVal.asString());
1181  }
1182 
1183  _runningReq.reset();
1184  return finishWithSuccess( provider().addMedium( zypp::make_intrusive<AttachedMediaInfo>(
1185  finishedReq->provideMessage().value( AttachMsgFields::AttachId ).asString()
1186  , queue.weak_this<ProvideQueue>()
1187  , _workerType
1188  , *finishedReq->activeUrl()
1189  , _initialSpec
1190  , mntPoint ) ) );
1191  }
1192  }
1193 
1194  // unhandled message , let the base impl do it
1195  return ProvideItem::finishReq ( queue, finishedReq, msg );
1196  }
1197 
1198  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 )
1199  {
1200  zypp::Url baseUrl = effectiveUrl;
1202  // remove /media.n/media
1203  baseUrl.setPathName( zypp::Pathname(baseUrl.getPathName()).dirname().dirname() );
1204  }
1205  return ProvideItem::authenticationRequired( queue, req, baseUrl, lastTimestamp, extraFields );
1206  }
1207 
1208 }
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:824
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:780
ProvideQueueWeakRef _myQueue
Definition: provideitem_p.h:87
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:846
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:252
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:428
State state() const
Definition: provideitem.cc:495
ProvideMessage _message
Definition: provideitem_p.h:83
time_t timestampForCredDatabase(const zypp::Url &url)
zyppng::AttachedMediaInfo_constPtr mediaInfo() const
Definition: provide.cc:990
#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
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:211
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 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:66
#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
zypp::TriBool isSameMedium(const ProvideMediaSpec &other)
Definition: providespec.cc:145
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:758
ItemStats makeStats() override
Definition: provideitem.cc:794
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:819
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:440
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:146
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:835
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:436
std::unordered_map< std::string, boost::any > AnyMap
Definition: provide.h:45
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")