libzypp 17.34.1
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
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
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
84 : Base( *new ProvideItemPrivate( parent, *this ) )
85 { }
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 finishedReq->provideMessage ().forEachVal( [&]( const std::string &key, const auto &val ){
300 if ( key == ProvideMsgFields::ExpectedFilesize && val.valid() )
301 filesize = val.asInt64();
302 return true;
303 });
304
305 if ( !filesize ) {
306 errPtr = ZYPP_EXCPT_PTR( zypp::media::MediaException( zypp::str::Str() << "ExceededExpectedSize Error for URL: " << reqUrl << " " << reason ) );
307 } else {
308 errPtr = ZYPP_EXCPT_PTR( zypp::media::MediaFileSizeExceededException(reqUrl, *filesize ) );
309 }
310 break;
311 }
312 case ProvideMessage::Code::Cancelled:
313 errPtr = ZYPP_EXCPT_PTR( zypp::media::MediaException( zypp::str::Str() << "Request was cancelled: " << reqUrl << " " << reason ) );
314 break;
315 case ProvideMessage::Code::InvalidChecksum:
316 errPtr = ZYPP_EXCPT_PTR( zypp::media::MediaException( zypp::str::Str() << "InvalidChecksum Error for URL: " << reqUrl << " " << reason ) );
317 break;
318 case ProvideMessage::Code::Timeout:
320 break;
321 case ProvideMessage::Code::NotFound:
323 break;
324 case ProvideMessage::Code::Forbidden:
325 case ProvideMessage::Code::Unauthorized: {
326
327 const auto &hintVal = msg.value( "authHint"sv );
328 std::string hint;
329 if ( hintVal.valid() && hintVal.isString() ) {
330 hint = hintVal.asString();
331 }
332
333 //@TODO retry here with timestamp from cred store check
334 // we let the request fail after it checked the store
335
337 reqUrl, reason, "", hint
338 ));
339 break;
340
341 }
342 case ProvideMessage::Code::MountFailed:
343 errPtr = ZYPP_EXCPT_PTR( zypp::media::MediaException( zypp::str::Str() << "MountFailed Error for URL: " << reqUrl << " " << reason ) );
344 break;
345 case ProvideMessage::Code::Jammed:
347 break;
348 case ProvideMessage::Code::MediaChangeSkip:
349 errPtr = ZYPP_EXCPT_PTR( zypp::SkipRequestException ( zypp::str::Str() << "User-requested skipping for URL: " << reqUrl << " " << reason ) );
350 break;
351 case ProvideMessage::Code::MediaChangeAbort:
352 errPtr = ZYPP_EXCPT_PTR( zypp::AbortRequestException( zypp::str::Str() <<"Aborting requested by user for URL: " << reqUrl << " " << reason ) );
353 break;
354 case ProvideMessage::Code::InternalError:
355 errPtr = ZYPP_EXCPT_PTR( zypp::media::MediaException( zypp::str::Str() << "WorkerSpecific Error for URL: " << reqUrl << " " << reason ) );
356 break;
357 case ProvideMessage::Code::NotAFile:
359 break;
360 case ProvideMessage::Code::MediumNotDesired:
362 break;
363 default:
364 errPtr = ZYPP_EXCPT_PTR( zypp::media::MediaException( zypp::str::Str() << "Unknown Error for URL: " << reqUrl << " " << reason ) );
365 break;
366 }
367 } catch (...) {
368 errPtr = ZYPP_EXCPT_PTR( zypp::media::MediaException( zypp::str::Str() << "Invalid error message received for URL: " << *finishedReq->activeUrl() << " code: " << code ) );
369 }
370
371 if ( log ) log->requestFailed( *this, msg.requestId(), errPtr );
372 // finish the request
373 cancelWithError( errPtr );
374 return;
375 }
376
377 // if we reach here we don't know how to handle the message
378 _runningReq.reset();
379 cancelWithError( ZYPP_EXCPT_PTR (zypp::media::MediaException("Unhandled message received for ProvideFileItem")) );
380 }
381
382 void ProvideItem::finishReq(ProvideQueue *, ProvideRequestRef finishedReq , const std::exception_ptr excpt)
383 {
384 if ( finishedReq != _runningReq ) {
385 WAR << "Received event for unknown request, ignoring" << std::endl;
386 return;
387 }
388
389 if ( _runningReq ) {
390 auto log = provider().log();
391 if ( log ) log->requestFailed( *this, finishedReq->provideMessage().requestId(), excpt );
392 }
393
394 _runningReq.reset();
395 cancelWithError(excpt);
396 }
397
398 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 )
399 {
400
401 if ( req != _runningReq ) {
402 WAR << "Received authenticationRequired for unknown request, rejecting" << std::endl;
403 return expected<zypp::media::AuthData>::error( ZYPP_EXCPT_PTR( zypp::media::MediaException("Unknown request in authenticationRequired, this is a bug.") ) );
404 }
405
406 try {
407 zypp::media::CredentialManager mgr ( provider().credManagerOptions() );
408
409 MIL << "Looking for existing auth data for " << effectiveUrl << "more recent then " << lastTimestamp << std::endl;
410
411 auto credPtr = mgr.getCred( effectiveUrl );
412 if ( credPtr && credPtr->lastDatabaseUpdate() > lastTimestamp ) {
413 MIL << "Found existing auth data for " << effectiveUrl << "ts: " << credPtr->lastDatabaseUpdate() << std::endl;
415 }
416
417 if ( credPtr ) MIL << "Found existing auth data for " << effectiveUrl << "but too old ts: " << credPtr->lastDatabaseUpdate() << std::endl;
418
419 std::string username;
420 if ( auto i = extraFields.find( std::string(AuthDataRequestMsgFields::LastUser) ); i != extraFields.end() ) {
421 username = i->second;
422 }
423
424
425 MIL << "NO Auth data found, asking user. Last tried username was: " << username << std::endl;
426
427 auto userAuth = provider()._sigAuthRequired.emit( effectiveUrl, username, extraFields );
428 if ( !userAuth || !userAuth->valid() ) {
429 MIL << "User rejected to give auth" << std::endl;
431 }
432
433 mgr.addCred( *userAuth );
434 mgr.save();
435
436 // rather ugly, but update the timestamp to the last mtime of the cred database our URL belongs to
437 // otherwise we'd need to reload the cred database
438 userAuth->setLastDatabaseUpdate( mgr.timestampForCredDatabase( effectiveUrl ) );
439
441 } catch ( const zypp::Exception &e ) {
442 ZYPP_CAUGHT(e);
443 return expected<zypp::media::AuthData>::error( std::current_exception() );
444 }
445 }
446
447 bool ProvideItem::enqueueRequest( ProvideRequestRef request )
448 {
449 // base item just supports one running request at a time
450 if ( _runningReq )
451 return ( _runningReq == request );
452
453 _runningReq = request;
454 return d_func()->_parent.queueRequest( request );
455 }
456
457 void ProvideItem::updateState( const State newState )
458 {
459 Z_D();
460 if ( d->_itemState != newState ) {
461
462 bool started = ( d->_itemState == Uninitialized && ( newState != Finished ));
463 auto log = provider().log();
464
465 const auto oldState = d->_itemState;
466 d->_itemState = newState;
467 d->_sigStateChanged( *this, oldState, d->_itemState );
468
469 if ( started ) {
470 d->_itemStarted = std::chrono::steady_clock::now();
471 pulse();
472 if ( log ) log->itemStart( *this );
473 }
474
475 if ( newState == Finished ) {
476 d->_itemFinished = std::chrono::steady_clock::now();
477 pulse();
478 if ( log) log->itemDone( *this );
479 d->_parent.dequeueItem(this);
480 }
481 // CAREFUL, 'this' might be invalid from here on
482 }
483 }
484
486 {
487 if ( state() == Finished || state() == Finalizing )
488 return;
489
490 MIL << "Item Cleanup due to released Promise in state:" << state() << std::endl;
492 }
493
495 {
496 return d_func()->_itemState;
497 }
498
499 void ProvideRequest::setCurrentQueue( ProvideQueueRef ref )
500 {
501 _myQueue = ref;
502 }
503
505 {
506 return _myQueue.lock();
507 }
508
509 const std::optional<zypp::Url> ProvideRequest::activeUrl() const
510 {
512 switch ( this->_message.code () ) {
513 case ProvideMessage::Code::Attach:
515 break;
516 case ProvideMessage::Code::Detach:
518 break;
519 case ProvideMessage::Code::Prov:
521 break;
522 default:
523 // should never happen because we guard the constructor
524 throw std::logic_error("Invalid message type in ProvideRequest");
525 }
526 if ( !url.valid() ) {
527 return {};
528 }
529
530 try {
531 auto u = zypp::Url( url.asString() );
532 return u;
533 } catch ( const zypp::Exception &e ) {
534 ZYPP_CAUGHT(e);
535 }
536
537 return {};
538 }
539
541
542 switch ( this->_message.code () ) {
543 case ProvideMessage::Code::Attach:
545 break;
546 case ProvideMessage::Code::Detach:
548 break;
549 case ProvideMessage::Code::Prov:
551 break;
552 default:
553 // should never happen because we guard the constructor
554 throw std::logic_error("Invalid message type in ProvideRequest");
555 }
556 }
557
558 ProvideFileItem::ProvideFileItem(const std::vector<zypp::Url> &urls, const ProvideFileSpec &request, ProvidePrivate &parent)
559 : ProvideItem( parent )
560 , _mirrorList ( urls )
561 , _initialSpec ( request )
562 { }
563
564 ProvideFileItemRef ProvideFileItem::create(const std::vector<zypp::Url> &urls, const ProvideFileSpec &request, ProvidePrivate &parent )
565 {
566 return ProvideFileItemRef( new ProvideFileItem( urls, request, parent ) );
567 }
568
570 {
571 if ( state() != Uninitialized || _runningReq ) {
572 WAR << "Double init of ProvideFileItem!" << std::endl;
573 return;
574 }
575
576 auto req = ProvideRequest::create( *this, _mirrorList, _initialSpec );
577 if ( !req ){
578 cancelWithError( req.error() );
579 return ;
580 }
581
582 if ( enqueueRequest( *req ) ) {
585 } else {
586 cancelWithError( ZYPP_EXCPT_PTR(zypp::media::MediaException("Failed to queue request")) );
587 return ;
588 }
589 }
590
592 {
593 if ( !_promiseCreated ) {
594 _promiseCreated = true;
595 auto promiseRef = std::make_shared<ProvidePromise<ProvideRes>>( shared_this<ProvideItem>() );
596 _promise = promiseRef;
597 return promiseRef;
598 }
599 return _promise.lock();
600 }
601
603 {
604 _handleRef = std::move(hdl);
605 }
606
611
612 void ProvideFileItem::informalMessage ( ProvideQueue &, ProvideRequestRef req, const ProvideMessage &msg )
613 {
614 if ( req != _runningReq ) {
615 WAR << "Received event for unknown request, ignoring" << std::endl;
616 return;
617 }
618
619 if ( msg.code() == ProvideMessage::Code::ProvideStarted ) {
620 MIL << "Provide File Request: "<< req->url() << " was started" << std::endl;
621 auto log = provider().log();
622
623 auto locPath = msg.value( ProvideStartedMsgFields::LocalFilename, std::string() ).asString();
624 if ( !locPath.empty() )
625 _targetFile = zypp::Pathname(locPath);
626
627 locPath = msg.value( ProvideStartedMsgFields::StagingFilename, std::string() ).asString();
628 if ( !locPath.empty() )
629 _stagingFile = zypp::Pathname(locPath);
630
631 if ( log ) {
632 auto effUrl = req->activeUrl().value_or( zypp::Url() );
633 try {
635 } catch( const zypp::Exception &e ) {
636 ZYPP_CAUGHT(e);
637 }
638
639 AnyMap m;
640 m["spec"] = _initialSpec;
641 if ( log ) log->requestStart( *this, msg.requestId(), effUrl, m );
643 }
644 }
645 }
646
647 void zyppng::ProvideFileItem::ProvideFileItem::finishReq( zyppng::ProvideQueue &queue, ProvideRequestRef finishedReq, const ProvideMessage &msg )
648 {
649 if ( finishedReq != _runningReq ) {
650 WAR << "Received event for unknown request, ignoring" << std::endl;
651 return;
652 }
653
654 if ( msg.code () == ProvideMessage::Code::ProvideFinished ) {
655
656 auto log = provider().log();
657 if ( log ) {
658 AnyMap m;
659 m["spec"] = _initialSpec;
660 if ( log ) log->requestDone( *this, msg.requestId(), m );
661 }
662
663 MIL << "Request was successfully finished!" << std::endl;
664 // request is def done
665 _runningReq.reset();
666
667 std::optional<zypp::ManagedFile> resFile;
668
669 try {
670 const auto locFilename = msg.value( ProvideFinishedMsgFields::LocalFilename ).asString();
671 const auto cacheHit = msg.value( ProvideFinishedMsgFields::CacheHit ).asBool();
672 const auto &wConf = queue.workerConfig();
673
674 const bool doesDownload = wConf.worker_type() == ProvideQueue::Config::Downloading;
675 const bool fileNeedsCleanup = doesDownload || ( wConf.worker_type() == ProvideQueue::Config::CPUBound && wConf.cfg_flags() & ProvideQueue::Config::FileArtifacts );
676
677 if ( doesDownload ) {
678
679 resFile = provider().addToFileCache ( locFilename );
680 if ( !resFile ) {
681 if ( cacheHit ) {
682 MIL << "CACHE MISS, file " << locFilename << " was already removed, queueing again" << std::endl;
683 cacheMiss ( finishedReq );
684 finishedReq->clearForRestart();
685 enqueueRequest( finishedReq );
686 return;
687 } else {
688 // if we reach here it seems that a new file, that was not in cache before, vanished between
689 // providing it and receiving the finished message.
690 // unlikely this can happen but better be safe than sorry
691 cancelWithError( ZYPP_EXCPT_PTR( zypp::media::MediaException("File vanished between downloading and adding it to cache.")) );
692 return;
693 }
694 }
695
696 } else {
697 resFile = zypp::ManagedFile( zypp::filesystem::Pathname(locFilename) );
698 if ( fileNeedsCleanup )
699 resFile->setDispose( zypp::filesystem::unlink );
700 else
701 resFile->resetDispose();
702 }
703
704 _targetFile = locFilename;
705
706 } catch ( const zypp::Exception &e ) {
707 ZYPP_CAUGHT(e);
708 cancelWithError( std::current_exception() );
709 } catch ( const std::exception &e ) {
710 ZYPP_CAUGHT(e);
711 cancelWithError( std::current_exception() );
712 } catch ( ...) {
713 cancelWithError( std::current_exception() );
714 }
715
716 // keep the media handle around as long as the file is used by the code
717 auto resObj = std::make_shared<ProvideResourceData>();
718 resObj->_mediaHandle = this->_handleRef;
719 resObj->_myFile = *resFile;
720 resObj->_resourceUrl = *(finishedReq->activeUrl());
721 resObj->_responseHeaders = msg.headers();
722
723 // if there is a exception escaping the pipeline we need to rethrow it after cleaning up
724 std::exception_ptr excpt;
725 auto p = promise();
726 if ( p ) {
727 try {
728 p->setReady( expected<ProvideRes>::success( ProvideRes( resObj )) );
729 } catch( const zypp::Exception &e ) {
730 ERR << "Caught unhandled pipline exception:" << e << std::endl;
731 ZYPP_CAUGHT(e);
732 excpt = std::current_exception ();
733 } catch ( const std::exception &e ) {
734 ERR << "Caught unhandled pipline exception:" << e.what() << std::endl;
735 ZYPP_CAUGHT(e);
736 excpt = std::current_exception ();
737 } catch ( ...) {
738 ERR << "Caught unhandled unknown exception:" << std::endl;
739 excpt = std::current_exception ();
740 }
741 }
742
743 updateState( Finished );
744
745 if ( excpt ) {
746 ERR << "Rethrowing pipeline exception, this is a BUG!" << std::endl;
747 std::rethrow_exception ( excpt );
748 }
749
750 } else {
751 ProvideItem::finishReq ( queue, finishedReq, msg );
752 }
753 }
754
755
756 void zyppng::ProvideFileItem::cancelWithError( std::exception_ptr error )
757 {
758 if ( _runningReq ) {
759 auto weakThis = weak_from_this ();
760 provider().dequeueRequest ( _runningReq, error );
761 if ( weakThis.expired () )
762 return;
763 }
764
765 // if we reach this place for some reason finishReq was not called, lets clean up manually
766 _runningReq.reset();
767 auto p = promise();
768 if ( p ) {
769 try {
770 p->setReady( expected<ProvideRes>::error( error ) );
771 } catch( const zypp::Exception &e ) {
772 ZYPP_CAUGHT(e);
773 }
774 }
775 updateState( Finished );
776 }
777
778 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 )
779 {
780 zypp::Url urlToUse = effectiveUrl;
781 if ( _handleRef.isValid() ) {
782 // 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
783 // i guess there were never password protected repositories that have different credentials on the redirection targets
784 auto &attachedMedia = provider().attachedMediaInfos();
785 if ( std::find( attachedMedia.begin(), attachedMedia.end(), _handleRef.mediaInfo() ) == attachedMedia.end() )
786 return expected<zypp::media::AuthData>::error( ZYPP_EXCPT_PTR( zypp::media::MediaException("Attachment handle vanished during request.") ) );
787 urlToUse = _handleRef.mediaInfo()->_attachedUrl;
788 }
789 return ProvideItem::authenticationRequired( queue, req, urlToUse, lastTimestamp, extraFields );
790 }
791
793 {
794 zypp::ByteCount providedByNow;
795
796 bool checkStaging = false;
797 if ( !_targetFile.empty() ) {
799 if ( inf.isExist() && inf.isFile() )
800 providedByNow = zypp::ByteCount( inf.size() );
801 else
802 checkStaging = true;
803 }
804
805 if ( checkStaging && !_stagingFile.empty() ) {
807 if ( inf.isExist() && inf.isFile() )
808 providedByNow = zypp::ByteCount( inf.size() );
809 }
810
811 auto baseStats = ProvideItem::makeStats();
812 baseStats._bytesExpected = bytesExpected();
813 baseStats._bytesProvided = providedByNow;
814 return baseStats;
815 }
816
821
822 AttachMediaItem::AttachMediaItem( const std::vector<zypp::Url> &urls, const ProvideMediaSpec &request, ProvidePrivate &parent )
823 : ProvideItem ( parent )
824 , _mirrorList ( urls )
825 , _initialSpec ( request )
826 { }
827
829 {
830 MIL << "Killing the AttachMediaItem" << std::endl;
831 }
832
834 {
835 if ( !_promiseCreated ) {
836 _promiseCreated = true;
837 auto promiseRef = std::make_shared<ProvidePromise<Provide::MediaHandle>>( shared_this<ProvideItem>() );
838 _promise = promiseRef;
839 return promiseRef;
840 }
841 return _promise.lock();
842 }
843
845 {
846 if ( state() != Uninitialized ) {
847 WAR << "Double init of AttachMediaItem!" << std::endl;
848 return;
849 }
851
852 if ( _mirrorList.empty() ) {
853 cancelWithError( ZYPP_EXCPT_PTR( zypp::media::MediaException("No usable mirrors in mirrorlist.")) );
854 return;
855 }
856
857 // shortcut to the provider instance
858 auto &prov= provider();
859
860 // sanitize the mirrors to contain only URLs that have same worker types
861 std::vector<zypp::Url> usableMirrs;
862 std::optional<ProvideQueue::Config> scheme;
863
864 for ( auto mirrIt = _mirrorList.begin() ; mirrIt != _mirrorList.end(); mirrIt++ ) {
865 const auto &s = prov.schemeConfig( prov.effectiveScheme( mirrIt->getScheme() ) );
866 if ( !s ) {
867 WAR << "URL: " << *mirrIt << " is not supported, ignoring!" << std::endl;
868 continue;
869 }
870 if ( !scheme ) {
871 scheme = *s;
872 usableMirrs.push_back ( *mirrIt );
873 } else {
874 if ( scheme->worker_type () == s->worker_type () ) {
875 usableMirrs.push_back( *mirrIt );
876 } else {
877 WAR << "URL: " << *mirrIt << " has different worker type than the primary URL: "<< usableMirrs.front() <<", ignoring!" << std::endl;
878 }
879 }
880 }
881
882 // save the sanitized mirrors
883 _mirrorList = usableMirrs;
884
885 if ( !scheme || _mirrorList.empty() ) {
886 auto prom = promise();
887 if ( prom ) {
888 try {
889 prom->setReady( expected<Provide::MediaHandle>::error( ZYPP_EXCPT_PTR ( zypp::media::MediaException("No valid mirrors available") )) );
890 } catch( const zypp::Exception &e ) {
891 ZYPP_CAUGHT(e);
892 }
893 }
895 return;
896 }
897
898 // first check if there is a already attached medium we can use as well
899 auto &attachedMedia = prov.attachedMediaInfos ();
900
901 for ( auto &medium : attachedMedia ) {
902 if ( medium->isSameMedium ( _mirrorList, _initialSpec ) ) {
903 finishWithSuccess ( medium );
904 return;
905 }
906 }
907
908 for ( auto &otherItem : prov.items() ) {
909 auto attachIt = std::dynamic_pointer_cast<AttachMediaItem>(otherItem);
910 if ( !attachIt // not the right type
911 || attachIt.get() == this // do not attach to ourselves
912 || attachIt->state () == Uninitialized // item was not initialized
913 || attachIt->state () == Finalizing // item cleaning up
914 || attachIt->state () == Finished ) // item done
915 continue;
916
917 // does this Item attach the same medium?
918 const auto sameMedium = attachIt->_initialSpec.isSameMedium( _initialSpec);
919 if ( zypp::indeterminate(sameMedium) ) {
920 // check the primary URLs ( should we do a full list compare? )
921 if ( attachIt->_mirrorList.front() != _mirrorList.front() )
922 continue;
923 }
924 else if ( !(bool)sameMedium )
925 continue;
926
927 MIL << "Found item providing the same medium, attaching to finished signal and waiting for it to be finished" << std::endl;
928
929 // it does, connect to its ready signal and just wait
931 return;
932 }
933
934 _workerType = scheme->worker_type();
935
936 switch( _workerType ) {
938
939 // if the media file is empty in the spec we can not do anything
940 // simply pretend attach worked
941 if( _initialSpec.mediaFile().empty() ) {
943 return;
944 }
945
946 // prepare the verifier with the data
947 auto smvDataLocal = MediaDataVerifier::createVerifier("SuseMediaV1");
948 if ( !smvDataLocal ) {
949 cancelWithError( ZYPP_EXCPT_PTR( zypp::media::MediaException("Unable to verify the medium, no verifier instance was returned.")) );
950 return;
951 }
952
953 if ( !smvDataLocal->load( _initialSpec.mediaFile() ) ) {
954 cancelWithError( ZYPP_EXCPT_PTR( zypp::media::MediaException("Unable to verify the medium, unable to load local verify data.")) );
955 return;
956 }
957
958 _verifier = smvDataLocal;
959
960 std::vector<zypp::Url> urls;
961 urls.reserve( _mirrorList.size () );
962
963 for ( zypp::Url url : _mirrorList ) {
964 url.appendPathName ( ( zypp::str::Format("/media.%d/media") % _initialSpec.medianr() ).asString() );
965 urls.push_back(url);
966 }
967
968 // for downloading schemes we ask for the /media.x/media file and check the data manually
969 ProvideFileSpec spec;
971
972 // disable metalink
973 spec.customHeaders().set( std::string(NETWORK_METALINK_ENABLED), false );
974
975 auto req = ProvideRequest::create( *this, urls, spec );
976 if ( !req ) {
977 cancelWithError( req.error() );
978 return;
979 }
980 if ( !enqueueRequest( *req ) ) {
981 cancelWithError( ZYPP_EXCPT_PTR(zypp::media::MediaException("Failed to queue request")) );
982 return;
983 }
985 break;
986 }
989
990 const auto &newId = provider().nextMediaId();
991 auto req = ProvideRequest::create( *this, _mirrorList, newId, _initialSpec );
992 if ( !req ) {
993 cancelWithError( req.error() );
994 return;
995 }
996 if ( !enqueueRequest( *req ) ) {
997 ERR << "Failed to queue request" << std::endl;
998 cancelWithError( ZYPP_EXCPT_PTR(zypp::media::MediaException("Failed to queue request")) );
999 return;
1000 }
1001 break;
1002 }
1003 default: {
1004 auto prom = promise();
1005 if ( prom ) {
1006 try {
1007 prom->setReady( expected<Provide::MediaHandle>::error( ZYPP_EXCPT_PTR ( zypp::media::MediaException("URL scheme does not support attaching.") )) );
1008 } catch( const zypp::Exception &e ) {
1009 ZYPP_CAUGHT(e);
1010 }
1011 }
1013 return;
1014 }
1015 }
1016 }
1017
1018 void AttachMediaItem::finishWithSuccess( AttachedMediaInfo_Ptr medium )
1019 {
1020
1022
1023 auto prom = promise();
1024 try {
1025 if ( prom ) {
1026 try {
1027 prom->setReady( expected<Provide::MediaHandle>::success( Provide::MediaHandle( *static_cast<Provide*>( provider().z_func() ), medium ) ) );
1028 } catch( const zypp::Exception &e ) {
1029 ZYPP_CAUGHT(e);
1030 }
1031 }
1032 } catch ( const std::exception &e ) {
1033 ERR << "WTF " << e.what () << std::endl;
1034 } catch ( ... ) {
1035 ERR << "WTF " << std::endl;
1036 }
1037
1038 // tell others as well
1040
1041 prom->isReady ();
1042
1043 MIL << "Before setFinished" << std::endl;
1045 return;
1046 }
1047
1048 void AttachMediaItem::cancelWithError( std::exception_ptr error )
1049 {
1050 MIL << "Cancelling Item with error" << std::endl;
1052
1053 // tell children
1055
1056 if ( _runningReq ) {
1057 // we might get deleted when calling dequeueRequest
1058 auto weakThis = weak_from_this ();
1059 provider().dequeueRequest ( _runningReq, error );
1060 if ( weakThis.expired () )
1061 return;
1062 }
1063
1064 // if we reach this place we had no runningReq, clean up manually
1065 _runningReq.reset();
1066 _masterItemConn.disconnect();
1067
1068 auto p = promise();
1069 if ( p ) {
1070 try {
1071 p->setReady( expected<zyppng::Provide::MediaHandle>::error( error ) );
1072 } catch( const zypp::Exception &e ) {
1073 ZYPP_CAUGHT(e);
1074 }
1075 }
1077 }
1078
1080 {
1081
1082 _masterItemConn.disconnect();
1083
1084 if ( result ) {
1085 finishWithSuccess( AttachedMediaInfo_Ptr(result.get()) );
1086 } else {
1087 try {
1088 std::rethrow_exception ( result.error() );
1089 } catch ( const zypp::media::MediaRequestCancelledException & e) {
1090 // in case a item was cancelled, we revert to Pending state and trigger the scheduler.
1091 // This will make sure that all our sibilings that also depend on the master
1092 // can revert to pending state and we only get one new master in the next schedule run
1093 MIL_PRV << "Master item was cancelled, reverting to Uninitialized state and waiting for scheduler to run again" << std::endl;
1096
1097 } catch ( ... ) {
1098 cancelWithError( std::current_exception() );
1099 }
1100 }
1101 }
1102
1103 AttachMediaItemRef AttachMediaItem::create( const std::vector<zypp::Url> &urls, const ProvideMediaSpec &request, ProvidePrivate &parent )
1104 {
1105 return AttachMediaItemRef( new AttachMediaItem(urls, request, parent) );
1106 }
1107
1112
1113 void AttachMediaItem::finishReq ( ProvideQueue &queue, ProvideRequestRef finishedReq, const ProvideMessage &msg )
1114 {
1115 if ( finishedReq != _runningReq ) {
1116 WAR << "Received event for unknown request, ignoring" << std::endl;
1117 return;
1118 }
1119
1121 // success
1122 if ( msg.code() == ProvideMessage::Code::ProvideFinished ) {
1123
1125
1126 zypp::Url baseUrl = *finishedReq->activeUrl();
1127 // remove /media.n/media
1128 baseUrl.setPathName( zypp::Pathname(baseUrl.getPathName()).dirname().dirname() );
1129
1130 // we got the file, lets parse it
1131 auto smvDataRemote = MediaDataVerifier::createVerifier("SuseMediaV1");
1132 if ( !smvDataRemote ) {
1133 return cancelWithError( ZYPP_EXCPT_PTR( zypp::media::MediaException("Unable to verify the medium, no verifier instance was returned.")) );
1134 }
1135
1136 if ( !smvDataRemote->load( msg.value( ProvideFinishedMsgFields::LocalFilename ).asString() ) ) {
1137 return cancelWithError( ZYPP_EXCPT_PTR( zypp::media::MediaException("Unable to verify the medium, unable to load remote verify data.")) );
1138 }
1139
1140 // check if we got a valid media file
1141 if ( !smvDataRemote->valid () ) {
1142 return cancelWithError( ZYPP_EXCPT_PTR( zypp::media::MediaException("Unable to verify the medium, unable to load local verify data.")) );
1143 }
1144
1145 // check if the received file matches with the one we have in the spec
1146 if (! _verifier->matches( smvDataRemote ) ) {
1147 DBG << "expect: " << _verifier << " medium " << _initialSpec.medianr() << std::endl;
1148 DBG << "remote: " << smvDataRemote << std::endl;
1149 return cancelWithError( ZYPP_EXCPT_PTR( zypp::media::MediaNotDesiredException( *finishedReq->activeUrl() ) ) );
1150 }
1151
1152 // all good, register the medium and tell all child items
1153 _runningReq.reset();
1154 return finishWithSuccess( provider().addMedium( zypp::make_intrusive<AttachedMediaInfo>( provider().nextMediaId(), _workerType, baseUrl, _initialSpec) ) );
1155
1156 } else if ( msg.code() == ProvideMessage::Code::NotFound ) {
1157
1158 // simple downloading attachment we need to check the media file contents
1159 // in case of a error we might tolerate a file not found error in certain situations
1160 if ( _verifier->totalMedia () == 1 ) {
1161 // relaxed , tolerate a vanished media file
1162 _runningReq.reset();
1163
1165 } else {
1166 return ProvideItem::finishReq ( queue, finishedReq, msg );
1167 }
1168 } else {
1169 return ProvideItem::finishReq ( queue, finishedReq, msg );
1170 }
1171 } else {
1172 // real device attach
1173 if ( msg.code() == ProvideMessage::Code::AttachFinished ) {
1174
1175 std::optional<zypp::Pathname> mntPoint;
1177 if ( mountPtVal.valid() && mountPtVal.isString() ) {
1178 mntPoint = zypp::Pathname(mountPtVal.asString());
1179 }
1180
1181 _runningReq.reset();
1183 finishedReq->provideMessage().value( AttachMsgFields::AttachId ).asString()
1184 , queue.weak_this<ProvideQueue>()
1185 , _workerType
1186 , *finishedReq->activeUrl()
1187 , _initialSpec
1188 , mntPoint ) ) );
1189 }
1190 }
1191
1192 // unhandled message , let the base impl do it
1193 return ProvideItem::finishReq ( queue, finishedReq, msg );
1194 }
1195
1196 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 )
1197 {
1198 zypp::Url baseUrl = effectiveUrl;
1200 // remove /media.n/media
1201 baseUrl.setPathName( zypp::Pathname(baseUrl.getPathName()).dirname().dirname() );
1202 }
1203 return ProvideItem::authenticationRequired( queue, req, baseUrl, lastTimestamp, extraFields );
1204 }
1205
1206}
Store and operate with byte count.
Definition ByteCount.h:32
Base class for Exception.
Definition Exception.h:147
Url manipulation class.
Definition Url.h:92
std::string asCompleteString() const
Returns a complete string representation of the Url object.
Definition Url.cc:509
std::string asString() const
Returns a default string representation of the Url object.
Definition Url.cc:501
std::string getPathName(EEncoding eflag=zypp::url::E_DECODED) const
Returns the path name from the URL.
Definition Url.cc:608
void setPathName(const std::string &path, EEncoding eflag=zypp::url::E_DECODED)
Set the path name.
Definition Url.cc:768
Wrapper class for stat/lstat.
Definition PathInfo.h:222
bool isExist() const
Return whether valid stat info exists.
Definition PathInfo.h:282
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)
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, const 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()
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
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)
virtual bool enqueueRequest(ProvideRequestRef request)
zyppng::AttachedMediaInfo_constPtr mediaInfo() const
Definition provide.cc:960
HeaderValueMap & customHeaders()
unsigned medianr() const
zypp::Pathname mediaFile() const
const std::string & label() const
HeaderValueMap headers() const
std::vector< FieldVal > values(const std::string_view &str) const
FieldVal value(const std::string_view &str, const FieldVal &defaultVal=FieldVal()) const
void setValue(const std::string &name, const FieldVal &value)
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:807
std::string nextMediaId() const
Definition provide.cc:773
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:99
std::vector< AttachedMediaInfo_Ptr > & attachedMediaInfos()
Definition provide.cc:709
void schedule(ScheduleReason reason)
Definition provide.cc:38
ProvideStatusRef log()
Definition provide_p.h:92
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
ProvideRequest(ProvideItem *owner, const std::vector< zypp::Url > &urls, ProvideMessage &&msg)
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
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")
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:44
#define MIL_PRV
Convenient building of std::string with boost::format.
Definition String.h:253
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...
Definition String.h:212
std::chrono::steady_clock::time_point _pulseTime
Definition provideitem.h:46
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
Definition Exception.h:437
#define ZYPP_EXCPT_PTR(EXCPT)
Drops a logline and returns Exception as a std::exception_ptr.
Definition Exception.h:433
#define DBG
Definition Logger.h:97
#define MIL
Definition Logger.h:98
#define ERR
Definition Logger.h:100
#define WAR
Definition Logger.h:99
#define ZYPP_IMPL_PRIVATE(Class)
Definition zyppglobal.h:91
#define Z_D()
Definition zyppglobal.h:104