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