libzypp 17.37.3
provideitem.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
9
12#include "private/provide_p.h"
15#include "provide-configvars.h"
16#include <zypp-media/MediaException>
17#include <zypp-core/base/UserRequestException>
18#include "mediaverifier.h"
20
21using namespace std::literals;
22
23namespace 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
49 {
50 if ( urls.empty() )
51 return expected<ProvideRequestRef>::error( ZYPP_EXCPT_PTR ( zypp::media::MediaException("List of URLs can not be empty") ) );
52
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
76 {
78 return expected<ProvideRequestRef>::success( ProvideRequestRef( new ProvideRequest( nullptr, { url }, std::move(m) ) ) );
79 }
80
82
86
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 {
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
174 if ( msg.code() == ProvideMessage::Code::ProvideStarted ) {
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
277 } else if ( code >= ProvideMessage::Code::FirstClientErrCode && code <= ProvideMessage::Code::LastSrvErrCode ) {
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 ) {
287 case ProvideMessage::Code::BadRequest:
288 errPtr = ZYPP_EXCPT_PTR( zypp::media::MediaException (zypp::str::Str() << "Bad request for URL: " << reqUrl << " " << reason ) );
289 break;
290 case ProvideMessage::Code::PeerCertificateInvalid:
291 errPtr = ZYPP_EXCPT_PTR( zypp::media::MediaException(zypp::str::Str() << "PeerCertificateInvalid Error for URL: " << reqUrl << " " << reason) );
292 break;
293 case ProvideMessage::Code::ConnectionFailed:
294 errPtr = ZYPP_EXCPT_PTR( zypp::media::MediaException(zypp::str::Str() << "ConnectionFailed Error for URL: " << reqUrl << " " << reason ) );
295 break;
296 case ProvideMessage::Code::ExpectedSizeExceeded: {
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 }
313 case ProvideMessage::Code::Cancelled:
314 errPtr = ZYPP_EXCPT_PTR( zypp::media::MediaException( zypp::str::Str() << "Request was cancelled: " << reqUrl << " " << reason ) );
315 break;
316 case ProvideMessage::Code::InvalidChecksum:
317 errPtr = ZYPP_EXCPT_PTR( zypp::media::MediaException( zypp::str::Str() << "InvalidChecksum Error for URL: " << reqUrl << " " << reason ) );
318 break;
319 case ProvideMessage::Code::Timeout:
321 break;
322 case ProvideMessage::Code::NotFound:
324 break;
325 case ProvideMessage::Code::Forbidden:
326 case ProvideMessage::Code::Unauthorized: {
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 }
343 case ProvideMessage::Code::MountFailed:
344 errPtr = ZYPP_EXCPT_PTR( zypp::media::MediaException( zypp::str::Str() << "MountFailed Error for URL: " << reqUrl << " " << reason ) );
345 break;
346 case ProvideMessage::Code::Jammed:
348 break;
349 case ProvideMessage::Code::MediaChangeSkip:
350 errPtr = ZYPP_EXCPT_PTR( zypp::SkipRequestException ( zypp::str::Str() << "User-requested skipping for URL: " << reqUrl << " " << reason ) );
351 break;
352 case ProvideMessage::Code::MediaChangeAbort:
353 errPtr = ZYPP_EXCPT_PTR( zypp::AbortRequestException( zypp::str::Str() <<"Aborting requested by user for URL: " << reqUrl << " " << reason ) );
354 break;
355 case ProvideMessage::Code::InternalError:
356 errPtr = ZYPP_EXCPT_PTR( zypp::media::MediaException( zypp::str::Str() << "WorkerSpecific Error for URL: " << reqUrl << " " << reason ) );
357 break;
358 case ProvideMessage::Code::NotAFile:
360 break;
361 case ProvideMessage::Code::MediumNotDesired:
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;
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 () ) {
514 case ProvideMessage::Code::Attach:
516 break;
517 case ProvideMessage::Code::Detach:
519 break;
520 case ProvideMessage::Code::Prov:
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
542
543 switch ( this->_message.code () ) {
544 case ProvideMessage::Code::Attach:
545 this->_message.setValue( AttachMsgFields::Url, urlToUse.asCompleteString() );
546 break;
547 case ProvideMessage::Code::Detach:
548 this->_message.setValue( DetachMsgFields::Url, urlToUse.asCompleteString() );
549 break;
550 case ProvideMessage::Code::Prov:
551 this->_message.setValue( ProvideMsgFields::Url, urlToUse.asCompleteString() );
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)
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 ) ) {
584 _expectedBytes = _initialSpec.downloadSize();
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
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
620 if ( msg.code() == ProvideMessage::Code::ProvideStarted ) {
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
655 if ( msg.code () == ProvideMessage::Code::ProvideFinished ) {
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 }
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 {
853 return (_initialSpec.checkExistsOnly() ? zypp::ByteCount(0) : _expectedBytes);
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() ) {
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;
1000 spec.customHeaders() = _initialSpec.customHeaders();
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 }
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;
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 }
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
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
1152 if ( msg.code() == ProvideMessage::Code::ProvideFinished ) {
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
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
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();
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}
Store and operate with byte count.
Definition ByteCount.h:32
Base class for Exception.
Definition Exception.h:153
Url manipulation class.
Definition Url.h:93
std::string asCompleteString() const
Returns a complete string representation of the Url object.
Definition Url.cc:523
std::string getPathName(EEncoding eflag=zypp::url::E_DECODED) const
Returns the path name from the URL.
Definition Url.cc:622
void setPathName(const std::string &path, EEncoding eflag=zypp::url::E_DECODED)
Set the path name.
Definition Url.cc:782
Wrapper class for stat/lstat.
Definition PathInfo.h:226
bool isExist() const
Return whether valid stat info exists.
Definition PathInfo.h:286
Pathname dirname() const
Return all but the last component od this path.
Definition Pathname.h:126
const std::string & asString() const
String representation.
Definition Pathname.h:93
bool empty() const
Test for an empty path.
Definition Pathname.h:116
void save()
Saves any unsaved credentials added via addUserCred() or addGlobalCred() methods.
time_t timestampForCredDatabase(const zypp::Url &url)
AuthData_Ptr getCred(const Url &url)
Get credentials for the specified url.
void addCred(const AuthData &cred)
Add new credentials with user callbacks.
Just inherits Exception to separate media exceptions.
void initialize() override
Signal< void(const zyppng::expected< AttachedMediaInfo * > &)> _sigReady
void finishReq(ProvideQueue &queue, ProvideRequestRef finishedReq, const ProvideMessage &msg) override
ProvidePromiseRef< Provide::MediaHandle > promise()
SignalProxy< void(const zyppng::expected< AttachedMediaInfo * > &) > sigReady()
void finishWithSuccess(AttachedMediaInfo_Ptr medium)
MediaDataVerifierRef _verifier
ProvidePromiseWeakRef< Provide::MediaHandle > _promise
AttachMediaItem(const std::vector< zypp::Url > &urls, const ProvideMediaSpec &request, ProvidePrivate &parent)
ProvideQueue::Config::WorkerType _workerType
ProvideMediaSpec _initialSpec
static AttachMediaItemRef create(const std::vector< zypp::Url > &urls, const ProvideMediaSpec &request, ProvidePrivate &parent)
std::vector< zypp::Url > _mirrorList
void cancelWithError(std::exception_ptr error) override
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
void onMasterItemReady(const zyppng::expected< AttachedMediaInfo * > &result)
bool isSameMedium(const std::vector< zypp::Url > &urls, const ProvideMediaSpec &spec)
std::shared_ptr< T > shared_this() const
Definition base.h:113
WeakPtr parent() const
Definition base.cc:26
static auto connect(typename internal::MemberFunction< SenderFunc >::ClassType &s, SenderFunc &&sFun, typename internal::MemberFunction< ReceiverFunc >::ClassType &recv, ReceiverFunc &&rFunc)
Definition base.h:142
std::weak_ptr< T > weak_this() const
Definition base.h:123
void set(const std::string &key, Value val)
const std::string & asString() const
static MediaDataVerifierRef createVerifier(const std::string &verifierType)
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
zypp::Pathname _stagingFile
void cancelWithError(std::exception_ptr error) override
zypp::ByteCount bytesExpected() const override
void setMediaRef(Provide::MediaHandle &&hdl)
Provide::MediaHandle & mediaRef()
Provide::MediaHandle _handleRef
void initialize() override
static ProvideFileItemRef create(const std::vector< zypp::Url > &urls, const ProvideFileSpec &request, ProvidePrivate &parent)
ProvideFileItem(const std::vector< zypp::Url > &urls, const ProvideFileSpec &request, ProvidePrivate &parent)
ProvideFileSpec _initialSpec
ProvidePromiseRef< ProvideRes > promise()
std::vector< zypp::Url > _mirrorList
zypp::ByteCount _expectedBytes
zypp::Pathname _targetFile
ItemStats makeStats() override
void informalMessage(ProvideQueue &, ProvideRequestRef req, const ProvideMessage &msg) override
ProvidePromiseWeakRef< ProvideRes > _promise
HeaderValueMap & customHeaders()
const zypp::Pathname & destFilenameHint() const
const zypp::ByteCount & downloadSize() const
The size of the resource on the server.
const zypp::Pathname & deltafile() const
The existing deltafile that can be used to reduce download size ( zchunk or metalink )
bool checkExistsOnly() const
bool safeRedirectTo(ProvideRequestRef startedReq, const zypp::Url &url)
virtual std::chrono::steady_clock::time_point startTime() const
virtual void cacheMiss(ProvideRequestRef req)
ProvideItem(ProvidePrivate &parent)
ProvidePrivate & provider()
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)
virtual ItemStats makeStats()
friend class Provide
Definition provideitem.h:31
virtual bool canRedirectTo(ProvideRequestRef startedReq, const zypp::Url &url)
virtual std::chrono::steady_clock::time_point finishedTime() const
virtual zypp::ByteCount bytesExpected() const
ProvideRequestRef _runningReq
void redirectTo(ProvideRequestRef startedReq, const zypp::Url &url)
State state() const
virtual void informalMessage(ProvideQueue &, ProvideRequestRef req, const ProvideMessage &msg)
const std::optional< ItemStats > & previousStats() const
friend class ProvidePrivate
Definition provideitem.h:32
virtual void released()
virtual void finishReq(ProvideQueue &queue, ProvideRequestRef finishedReq, const ProvideMessage &msg)
virtual void cancelWithError(std::exception_ptr error)=0
const std::optional< ItemStats > & currentStats() const
void updateState(const State newState)
friend class ProvideQueue
Definition provideitem.h:33
virtual bool enqueueRequest(ProvideRequestRef request)
HeaderValueMap & customHeaders()
unsigned medianr() const
zypp::Pathname mediaFile() const
const std::string & label() const
const HeaderValueMap & headers() const
FieldVal value(const std::string_view &str, const FieldVal &defaultVal=FieldVal()) const
const std::vector< ProvideMessage::FieldVal > & values(const std::string_view &str) const
static ProvideMessage createProvide(const uint32_t reqId, const zypp::Url &url, const std::optional< std::string > &filename={}, const std::optional< std::string > &deltaFile={}, const std::optional< int64_t > &expFilesize={}, bool checkExistOnly=false)
static ProvideMessage createDetach(const uint32_t reqId, const zypp::Url &attachUrl)
static ProvideMessage createAttach(const uint32_t reqId, const zypp::Url &url, const std::string attachId, const std::string &label, const std::optional< std::string > &verifyType={}, const std::optional< std::string > &verifyData={}, const std::optional< int32_t > &mediaNr={})
bool dequeueRequest(ProvideRequestRef req, std::exception_ptr error)
Definition provide.cc:837
std::string nextMediaId() const
Definition provide.cc:803
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
std::vector< AttachedMediaInfo_Ptr > & attachedMediaInfos()
Definition provide.cc:739
void schedule(ScheduleReason reason)
Definition provide.cc:38
ProvideStatusRef log()
Definition provide_p.h:90
const Config & workerConfig() const
static constexpr uint32_t InvalidId
void setActiveUrl(const zypp::Url &urlToUse)
ProvideQueueWeakRef _myQueue
const std::vector< zypp::Url > & urls() const
static expected< ProvideRequestRef > createDetach(const zypp::Url &url)
static expected< ProvideRequestRef > create(ProvideItem &owner, const std::vector< zypp::Url > &urls, const std::string &id, ProvideMediaSpec &spec)
ProvideMessage _message
zypp::Url url() const
void setCurrentQueue(ProvideQueueRef ref)
ProvideItem * owner()
ProvideQueueRef currentQueue()
const std::optional< zypp::Url > activeUrl() const
Returns the currenty active URL as set by the scheduler.
ProvideRequest(ProvideItem *owner, const std::vector< zypp::Url > &urls, ProvideMessage &&msg)
A ProvideRes object is a reference counted ownership of a resource in the cache provided by a Provide...
Definition provideres.h:36
ProvideMediaHandle MediaHandle
Definition provide.h:123
WorkerType worker_type() const
static expected success(ConsParams &&...params)
Definition expected.h:115
static expected error(ConsParams &&...params)
Definition expected.h:126
int unlink(const Pathname &path)
Like 'unlink'.
Definition PathInfo.cc:705
Url details namespace.
Definition UrlBase.cc:58
AutoDispose< const Pathname > ManagedFile
A Pathname plus associated cleanup code to be executed when path is no longer needed.
Definition ManagedFile.h:27
intrusive_ptr< T > make_intrusive(Args &&... __args)
Definition PtrTypes.h:103
constexpr std::string_view LocalMountPoint("local_mountpoint")
constexpr std::string_view AttachId("attach_id")
constexpr std::string_view VerifyData("verify_data")
constexpr std::string_view VerifyType("verify_type")
constexpr std::string_view MediaNr("media_nr")
constexpr std::string_view Url("url")
constexpr std::string_view LastUser("username")
constexpr std::string_view Url("url")
constexpr std::string_view Reason("reason")
constexpr std::string_view NewUrl("new_url")
constexpr std::string_view LocalFilename("local_filename")
constexpr std::string_view CacheHit("cacheHit")
constexpr std::string_view Url("url")
constexpr std::string_view MetalinkEnabled("metalink_enabled")
constexpr std::string_view ExpectedFilesize("expected_filesize")
constexpr std::string_view DeltaFile("delta_file")
constexpr std::string_view CheckExistOnly("check_existance_only")
constexpr std::string_view Filename("filename")
constexpr std::string_view StagingFilename("staging_filename")
constexpr std::string_view Url("url")
constexpr std::string_view LocalFilename("local_filename")
constexpr std::string_view NewUrl("new_url")
constexpr std::string_view NETWORK_METALINK_ENABLED("zypp-nw-metalink-enabled")
@ PeerCertificateInvalid
static constexpr std::string_view DEFAULT_MEDIA_VERIFIER("SuseMediaV1")
std::shared_ptr< ProvidePromise< T > > ProvidePromiseRef
std::unordered_map< std::string, boost::any > AnyMap
Definition provide.h:47
#define MIL_PRV
Convenient building of std::string with boost::format.
Definition String.h:254
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...
Definition String.h:213
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
Definition Exception.h:475
#define ZYPP_EXCPT_PTR(EXCPT)
Drops a logline and returns Exception as a std::exception_ptr.
Definition Exception.h:463
#define ZYPP_FWD_CURRENT_EXCPT()
Drops a logline and returns the current Exception as a std::exception_ptr.
Definition Exception.h:471
#define DBG
Definition Logger.h:99
#define MIL
Definition Logger.h:100
#define ERR
Definition Logger.h:102
#define WAR
Definition Logger.h:101
#define ZYPP_IMPL_PRIVATE(Class)
Definition zyppglobal.h:92
#define Z_D()
Definition zyppglobal.h:105