16 #include <zypp-media/MediaException> 17 #include <zypp-core/base/UserRequestException> 32 auto m = ProvideMessage::createAttach( ProvideQueue::InvalidId, urls.front(), id, spec.
label() );
40 for (
auto i = cHeaders.beginList (); i != cHeaders.endList(); i++) {
41 for (
const auto &val : i->second )
42 m.addValue( i->first, val );
53 auto m = ProvideMessage::createProvide ( ProvideQueue::InvalidId, urls.front() );
58 if ( !destFile.empty() )
60 if ( !deltaFile.empty() )
67 for (
auto i = cHeaders.beginList (); i != cHeaders.endList(); i++) {
68 for (
const auto &val : i->second )
69 m.addValue( i->first, val );
77 auto m = ProvideMessage::createDetach ( ProvideQueue::InvalidId , url );
92 return d_func()->_parent;
107 startedReq->_pastRedirects.push_back ( url );
113 if ( !startedReq->_pastRedirects.size() )
116 if ( std::find( startedReq->_pastRedirects.begin(), startedReq->_pastRedirects.end(), url ) != startedReq->_pastRedirects.end() )
124 return d_func()->_currStats;
129 return d_func()->_prevStats;
134 return d_func()->_itemStarted;
138 return d_func()->_itemFinished;
145 d->_prevStats = d->_currStats;
151 d->_currStats->_pulseTime = d->_itemFinished;
162 .
_pulseTime = std::chrono::steady_clock::now(),
163 ._runningRequests =
_runningReq ? (uint)1 : (uint)0
170 WAR <<
"Received event for unknown request, ignoring" << std::endl;
175 MIL <<
"Request: "<< req->url() <<
" was started" << std::endl;
183 WAR <<
"Received event for unknown request, ignoring" << std::endl;
187 MIL <<
"Request: "<< req->url() <<
" CACHE MISS, request will be restarted by queue." << std::endl;
193 WAR <<
"Received event for unknown request, ignoring" << std::endl;
200 const auto code = msg.
code();
208 MIL <<
"Request finished with redirect." << std::endl;
216 MIL <<
"Request redirected to: " << newUrl << std::endl;
218 if ( log ) log->requestRedirect( *
this, msg.
requestId(), newUrl );
220 finishedReq->setUrl( newUrl );
236 MIL <<
"Request finished with mirrorlist from server." << std::endl;
241 std::vector<zypp::Url> urls;
243 for(
auto i = mirrors.cbegin(); i != mirrors.cend(); i++ ) {
248 urls.push_back ( newUrl );
251 WAR <<
"Received invalid URL from worker: " << i->asString() <<
" ignoring!" << std::endl;
253 WAR <<
"Received invalid value for newUrl from worker ignoring!" << std::endl;
257 if ( urls.size () == 0 ) {
262 MIL <<
"Found usable nr of mirrors: " << urls.size () << std::endl;
263 finishedReq->setUrls( urls );
268 if ( log ) log->requestDone( *
this, msg.
requestId() );
274 MIL <<
"End of mirrorlist handling"<< std::endl;
282 std::exception_ptr errPtr;
284 const auto reqUrl = finishedReq->activeUrl().value();
298 std::optional<int64_t> filesize;
299 const auto &hdrs = finishedReq->provideMessage ().headers ();
303 filesize = val.asInt64();
328 const auto &hintVal = msg.
value(
"authHint"sv );
330 if ( hintVal.valid() && hintVal.isString() ) {
338 reqUrl, reason,
"", hint
350 errPtr =
ZYPP_EXCPT_PTR( zypp::SkipRequestException (
zypp::str::Str() <<
"User-requested skipping for URL: " << reqUrl <<
" " << reason ) );
353 errPtr =
ZYPP_EXCPT_PTR( zypp::AbortRequestException(
zypp::str::Str() <<
"Aborting requested by user for URL: " << reqUrl <<
" " << reason ) );
372 if ( log ) log->requestFailed( *
this, msg.
requestId(), errPtr );
386 WAR <<
"Received event for unknown request, ignoring" << std::endl;
392 if ( log ) log->requestFailed( *
this, finishedReq->provideMessage().requestId(), excpt );
403 WAR <<
"Received authenticationRequired for unknown request, rejecting" << std::endl;
410 MIL <<
"Looking for existing auth data for " << effectiveUrl <<
"more recent then " << lastTimestamp << std::endl;
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;
418 if ( credPtr )
MIL <<
"Found existing auth data for " << effectiveUrl <<
"but too old ts: " << credPtr->lastDatabaseUpdate() << std::endl;
420 std::string username;
422 username = i->second;
426 MIL <<
"NO Auth data found, asking user. Last tried username was: " << username << std::endl;
429 if ( !userAuth || !userAuth->valid() ) {
430 MIL <<
"User rejected to give auth" << std::endl;
455 return d_func()->_parent.queueRequest( request );
461 if ( d->_itemState != newState ) {
466 const auto oldState = d->_itemState;
467 d->_itemState = newState;
468 d->_sigStateChanged( *
this, oldState, d->_itemState );
471 d->_itemStarted = std::chrono::steady_clock::now();
473 if ( log ) log->itemStart( *
this );
477 d->_itemFinished = std::chrono::steady_clock::now();
479 if ( log) log->itemDone( *
this );
480 d->_parent.dequeueItem(
this);
491 MIL <<
"Item Cleanup due to released Promise in state:" <<
state() << std::endl;
497 return d_func()->_itemState;
525 throw std::logic_error(
"Invalid message type in ProvideRequest");
527 if ( !
url.valid() ) {
555 throw std::logic_error(
"Invalid message type in ProvideRequest");
561 , _mirrorList ( urls )
562 , _initialSpec ( request )
573 WAR <<
"Double init of ProvideFileItem!" << std::endl;
596 auto promiseRef = std::make_shared<ProvidePromise<ProvideRes>>( shared_this<ProvideItem>() );
616 WAR <<
"Received event for unknown request, ignoring" << std::endl;
621 MIL <<
"Provide File Request: "<< req->url() <<
" was started" << std::endl;
625 if ( !locPath.empty() )
629 if ( !locPath.empty() )
633 auto effUrl = req->activeUrl().value_or(
zypp::Url() );
642 if ( log ) log->requestStart( *
this, msg.
requestId(), effUrl, m );
650 if ( finishedReq != _runningReq ) {
651 WAR <<
"Received event for unknown request, ignoring" << std::endl;
657 auto log = provider().log();
660 m[
"spec"] = _initialSpec;
661 if ( log ) log->requestDone( *
this, msg.
requestId(), m );
664 MIL <<
"Request was successfully finished!" << std::endl;
668 std::optional<zypp::ManagedFile> resFile;
675 const bool checkExistsOnly = _initialSpec.checkExistsOnly();
679 if ( doesDownload && !checkExistsOnly ) {
681 resFile = provider().addToFileCache ( locFilename );
684 MIL <<
"CACHE MISS, file " << locFilename <<
" was already removed, queueing again" << std::endl;
685 cacheMiss ( finishedReq );
686 finishedReq->clearForRestart();
687 enqueueRequest( finishedReq );
700 if ( fileNeedsCleanup && !checkExistsOnly )
703 resFile->resetDispose();
706 _targetFile = locFilename;
710 cancelWithError( std::current_exception() );
711 }
catch (
const std::exception &e ) {
713 cancelWithError( std::current_exception() );
715 cancelWithError( std::current_exception() );
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();
726 std::exception_ptr excpt;
732 ERR <<
"Caught unhandled pipline exception:" << e << std::endl;
734 excpt = std::current_exception ();
735 }
catch (
const std::exception &e ) {
736 ERR <<
"Caught unhandled pipline exception:" << e.what() << std::endl;
738 excpt = std::current_exception ();
740 ERR <<
"Caught unhandled unknown exception:" << std::endl;
741 excpt = std::current_exception ();
745 updateState( Finished );
748 ERR <<
"Rethrowing pipeline exception, this is a BUG!" << std::endl;
749 std::rethrow_exception ( excpt );
754 switch( msg.
code() ) {
760 auto log = provider().log();
761 MIL <<
"Request failed trying to recover." << std::endl;
764 std::vector<zypp::Url> usableUrls;
765 std::for_each( _mirrorList.begin (), _mirrorList.end(), [&](
const zypp::Url &url ){
766 if ( !canRedirectTo ( finishedReq, url ) )
768 usableUrls.push_back(url);
771 if ( usableUrls.size() ) {
772 MIL <<
"Trying to recover by redirecting to a mirror" << std::endl;
773 finishedReq->setUrls(usableUrls);
775 if ( enqueueRequest( finishedReq ) )
778 MIL <<
"No mirror found or no mirror usable, giving up" << std::endl;
793 auto weakThis = weak_from_this ();
794 provider().dequeueRequest ( _runningReq, error );
795 if ( weakThis.expired () )
809 updateState( Finished );
819 if ( std::find( attachedMedia.begin(), attachedMedia.end(),
_handleRef.
mediaInfo() ) == attachedMedia.end() )
830 bool checkStaging =
false;
847 baseStats._bytesProvided = providedByNow;
858 , _mirrorList ( urls )
859 , _initialSpec ( request )
864 MIL <<
"Killing the AttachMediaItem" << std::endl;
871 auto promiseRef = std::make_shared<ProvidePromise<Provide::MediaHandle>>( shared_this<ProvideItem>() );
881 WAR <<
"Double init of AttachMediaItem!" << std::endl;
895 std::vector<zypp::Url> usableMirrs;
896 std::optional<ProvideQueue::Config> scheme;
899 const auto &s = prov.schemeConfig( prov.effectiveScheme( mirrIt->getScheme() ) );
901 WAR <<
"URL: " << *mirrIt <<
" is not supported, ignoring!" << std::endl;
906 usableMirrs.push_back ( *mirrIt );
908 if ( scheme->worker_type () == s->worker_type () ) {
909 usableMirrs.push_back( *mirrIt );
911 WAR <<
"URL: " << *mirrIt <<
" has different worker type than the primary URL: "<< usableMirrs.front() <<
", ignoring!" << std::endl;
933 auto &attachedMedia = prov.attachedMediaInfos ();
936 for (
auto &medium : attachedMedia ) {
943 for (
auto &otherItem : prov.items() ) {
946 || attachIt.get() ==
this 957 MIL <<
"Found item providing the same medium, attaching to finished signal and waiting for it to be finished" << std::endl;
978 if ( !smvDataLocal ) {
990 std::vector<zypp::Url> urls;
1027 ERR <<
"Failed to queue request" << std::endl;
1062 }
catch (
const std::exception &e ) {
1063 ERR <<
"WTF " << e.what () << std::endl;
1065 ERR <<
"WTF " << std::endl;
1073 MIL <<
"Before setFinished" << std::endl;
1080 MIL <<
"Cancelling Item with error" << std::endl;
1088 auto weakThis = weak_from_this ();
1090 if ( weakThis.expired () )
1118 std::rethrow_exception ( result.
error() );
1123 MIL_PRV <<
"Master item was cancelled, reverting to Uninitialized state and waiting for scheduler to run again" << std::endl;
1146 WAR <<
"Received event for unknown request, ignoring" << std::endl;
1156 zypp::Url baseUrl = *finishedReq->activeUrl();
1162 if ( !smvDataRemote ) {
1171 if ( !smvDataRemote->valid () ) {
1176 if (!
_verifier->matches( smvDataRemote ) ) {
1178 DBG <<
"remote: " << smvDataRemote << std::endl;
1202 std::optional<zypp::Pathname> mntPoint;
1204 if ( mountPtVal.valid() && mountPtVal.isString() ) {
1213 , *finishedReq->activeUrl()
1214 , std::vector<zypp::Url>{}
bool safeRedirectTo(ProvideRequestRef startedReq, const zypp::Url &url)
virtual bool enqueueRequest(ProvideRequestRef request)
constexpr std::string_view Url("url")
constexpr std::string_view LocalFilename("local_filename")
static ProvideFileItemRef create(const std::vector< zypp::Url > &urls, const ProvideFileSpec &request, ProvidePrivate &parent)
constexpr std::string_view AttachId("attach_id")
static constexpr std::string_view DEFAULT_MEDIA_VERIFIER("SuseMediaV1")
constexpr std::string_view NETWORK_METALINK_ENABLED("zypp-nw-metalink-enabled")
constexpr std::string_view VerifyData("verify_data")
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
ProvideQueueWeakRef _myQueue
constexpr std::string_view Filename("filename")
Signal< std::optional< zypp::media::AuthData > const zypp::Url &reqUrl, const std::string &triedUsername, const std::map< std::string, std::string > &extraValues) > _sigAuthRequired
Store and operate with byte count.
#define ZYPP_IMPL_PRIVATE(Class)
virtual void cacheMiss(ProvideRequestRef req)
ProvidePromiseRef< ProvideRes > promise()
std::string nextMediaId() const
virtual void finishReq(ProvideQueue &queue, ProvideRequestRef finishedReq, const ProvideMessage &msg)
std::shared_ptr< ProvidePromise< T > > ProvidePromiseRef
const zypp::Pathname & deltafile() const
The existing deltafile that can be used to reduce download size ( zchunk or metalink ) ...
virtual ItemStats makeStats()
std::chrono::steady_clock::time_point _pulseTime
static expected error(ConsParams &&...params)
constexpr std::string_view VerifyType("verify_type")
void initialize() override
#define ZYPP_EXCPT_PTR(EXCPT)
Drops a logline and returns Exception as a std::exception_ptr.
std::vector< AttachedMediaInfo_Ptr > & attachedMediaInfos()
AutoDispose< const Pathname > ManagedFile
A Pathname plus associated cleanup code to be executed when path is no longer needed.
const std::optional< zypp::Url > activeUrl() const
Returns the currenty active URL as set by the scheduler.
void updateState(const State newState)
constexpr std::string_view CheckExistOnly("check_existance_only")
std::string asString(TInt val, char zero='0', char one='1')
For printing bits.
constexpr std::string_view NewUrl("new_url")
bool empty() const
Test for an empty path.
ProvideFileSpec _initialSpec
void setPathName(const std::string &path, EEncoding eflag=zypp::url::E_DECODED)
Set the path name.
std::string asString() const
Returns a default string representation of the Url object.
constexpr std::string_view LocalFilename("local_filename")
FieldVal value(const std::string_view &str, const FieldVal &defaultVal=FieldVal()) const
void redirectTo(ProvideRequestRef startedReq, const zypp::Url &url)
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...
static auto connect(typename internal::MemberFunction< SenderFunc >::ClassType &s, SenderFunc &&sFun, typename internal::MemberFunction< ReceiverFunc >::ClassType &recv, ReceiverFunc &&rFunc)
const std::string & asString() const
String representation.
const Config & workerConfig() const
bool isExist() const
Return whether valid stat info exists.
virtual void informalMessage(ProvideQueue &, ProvideRequestRef req, const ProvideMessage &msg)
Pathname dirname() const
Return all but the last component od this path.
std::string asCompleteString() const
Returns a complete string representation of the Url object.
void informalMessage(ProvideQueue &, ProvideRequestRef req, const ProvideMessage &msg) override
const std::optional< ItemStats > & currentStats() const
std::weak_ptr< T > weak_this() const
void cancelWithError(std::exception_ptr error) override
ItemStats makeStats() override
void schedule(ScheduleReason reason)
ProvideFileItem(const std::vector< zypp::Url > &urls, const ProvideFileSpec &request, ProvidePrivate &parent)
static expected< ProvideRequestRef > create(ProvideItem &owner, const std::vector< zypp::Url > &urls, const std::string &id, ProvideMediaSpec &spec)
WorkerType worker_type() const
zypp::ByteCount bytesExpected() const override
const zypp::ByteCount & downloadSize() const
The size of the resource on the server.
constexpr std::string_view Reason("reason")
int unlink(const Pathname &path)
Like 'unlink'.
const zypp::Pathname & destFilenameHint() const
ProvidePrivate & provider()
static expected success(ConsParams &&...params)
void setCurrentQueue(ProvideQueueRef ref)
void setValue(const std::string &name, const FieldVal &value)
constexpr std::string_view DeltaFile("delta_file")
virtual bool canRedirectTo(ProvideRequestRef startedReq, const zypp::Url &url)
const std::vector< ProvideMessage::FieldVal > & values(const std::string_view &str) const
zypp::Pathname _targetFile
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
bool dequeueRequest(ProvideRequestRef req, std::exception_ptr error)
Base class for Exception.
void setActiveUrl(const zypp::Url &urlToUse)
constexpr std::string_view Url("url")
constexpr std::string_view LocalMountPoint("local_mountpoint")
virtual expected< zypp::media::AuthData > authenticationRequired(ProvideQueue &queue, ProvideRequestRef req, const zypp::Url &effectiveUrl, int64_t lastTimestamp, const std::map< std::string, std::string > &extraFields)
std::string getPathName(EEncoding eflag=zypp::url::E_DECODED) const
Returns the path name from the URL.
constexpr std::string_view Url("url")
zypp::ByteCount _expectedBytes
ProvideQueueRef currentQueue()
constexpr std::string_view MetalinkEnabled("metalink_enabled")
Wrapper class for ::stat/::lstat.
Provide::MediaHandle _handleRef
virtual void cancelWithError(std::exception_ptr error)=0
constexpr std::string_view StagingFilename("staging_filename")
Provide::MediaHandle & mediaRef()
std::vector< zypp::Url > _mirrorList
constexpr std::string_view Url("url")
#define ZYPP_FWD_CURRENT_EXCPT()
Drops a logline and returns the current Exception as a std::exception_ptr.
std::unordered_map< std::string, boost::any > AnyMap
const HeaderValueMap & headers() const
virtual zypp::ByteCount bytesExpected() const
void setMediaRef(Provide::MediaHandle &&hdl)
const std::optional< ItemStats > & previousStats() const
ProvidePromiseWeakRef< ProvideRes > _promise
HeaderValueMap & customHeaders()
constexpr std::string_view CacheHit("cacheHit")
virtual std::chrono::steady_clock::time_point startTime() const
constexpr std::string_view LastUser("username")
zypp::Pathname _stagingFile
virtual std::chrono::steady_clock::time_point finishedTime() const
bool checkExistsOnly() const
ProvideRequestRef _runningReq
constexpr std::string_view ExpectedFilesize("expected_filesize")