16#include <zypp-media/MediaException>
17#include <zypp-core/base/UserRequestException>
21using namespace std::literals;
41 for (
const auto &val :
i->second )
42 m.addValue(
i->first, val );
60 if ( !deltaFile.empty() )
68 for (
const auto &val :
i->second )
69 m.addValue(
i->first, val );
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;
174 if ( msg.
code() == ProvideMessage::Code::ProvideStarted ) {
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();
201 if ( code == ProvideMessage::Code::Redirect ) {
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 );
231 }
else if ( code == ProvideMessage::Code::Metalink ) {
236 MIL <<
"Request finished with mirrorlist from server." << std::endl;
241 std::vector<zypp::Url> urls;
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;
268 if ( log ) log->requestDone( *
this, msg.
requestId() );
274 MIL <<
"End of mirrorlist handling"<< std::endl;
277 }
else if ( code >= ProvideMessage::Code::FirstClientErrCode && code <= ProvideMessage::Code::LastSrvErrCode ) {
282 std::exception_ptr
errPtr;
287 case ProvideMessage::Code::BadRequest:
290 case ProvideMessage::Code::PeerCertificateInvalid:
293 case ProvideMessage::Code::ConnectionFailed:
296 case ProvideMessage::Code::ExpectedSizeExceeded: {
298 std::optional<int64_t> filesize;
299 finishedReq->provideMessage ().forEachVal( [&](
const std::string &key,
const auto &val ){
301 filesize = val.asInt64();
312 case ProvideMessage::Code::Cancelled:
315 case ProvideMessage::Code::InvalidChecksum:
318 case ProvideMessage::Code::Timeout:
321 case ProvideMessage::Code::NotFound:
324 case ProvideMessage::Code::Forbidden:
325 case ProvideMessage::Code::Unauthorized: {
342 case ProvideMessage::Code::MountFailed:
345 case ProvideMessage::Code::Jammed:
348 case ProvideMessage::Code::MediaChangeSkip:
351 case ProvideMessage::Code::MediaChangeAbort:
354 case ProvideMessage::Code::InternalError:
357 case ProvideMessage::Code::NotAFile:
360 case ProvideMessage::Code::MediumNotDesired:
385 WAR <<
"Received event for unknown request, ignoring" << std::endl;
391 if ( log ) log->requestFailed( *
this,
finishedReq->provideMessage().requestId(),
excpt );
402 WAR <<
"Received authenticationRequired for unknown request, rejecting" << std::endl;
413 MIL <<
"Found existing auth data for " <<
effectiveUrl <<
"ts: " <<
credPtr->lastDatabaseUpdate() << std::endl;
419 std::string username;
421 username =
i->second;
425 MIL <<
"NO Auth data found, asking user. Last tried username was: " << username << std::endl;
429 MIL <<
"User rejected to give auth" << std::endl;
467 d->_sigStateChanged( *
this,
oldState,
d->_itemState );
470 d->_itemStarted = std::chrono::steady_clock::now();
472 if ( log ) log->itemStart( *
this );
476 d->_itemFinished = std::chrono::steady_clock::now();
478 if ( log) log->itemDone( *
this );
479 d->_parent.dequeueItem(
this);
490 MIL <<
"Item Cleanup due to released Promise in state:" <<
state() << std::endl;
496 return d_func()->_itemState;
513 case ProvideMessage::Code::Attach:
516 case ProvideMessage::Code::Detach:
519 case ProvideMessage::Code::Prov:
524 throw std::logic_error(
"Invalid message type in ProvideRequest");
526 if ( !
url.valid() ) {
543 case ProvideMessage::Code::Attach:
546 case ProvideMessage::Code::Detach:
549 case ProvideMessage::Code::Prov:
554 throw std::logic_error(
"Invalid message type in ProvideRequest");
560 , _mirrorList ( urls )
572 WAR <<
"Double init of ProvideFileItem!" << std::endl;
615 WAR <<
"Received event for unknown request, ignoring" << std::endl;
619 if ( msg.
code() == ProvideMessage::Code::ProvideStarted ) {
620 MIL <<
"Provide File Request: "<< req->url() <<
" was started" << std::endl;
650 WAR <<
"Received event for unknown request, ignoring" << std::endl;
654 if ( msg.
code () == ProvideMessage::Code::ProvideFinished ) {
656 auto log = provider().log();
659 m[
"spec"] = _initialSpec;
660 if ( log ) log->requestDone( *
this, msg.
requestId(), m );
663 MIL <<
"Request was successfully finished!" << std::endl;
667 std::optional<zypp::ManagedFile> resFile;
677 if ( doesDownload ) {
679 resFile = provider().addToFileCache ( locFilename );
682 MIL <<
"CACHE MISS, file " << locFilename <<
" was already removed, queueing again" << std::endl;
683 cacheMiss ( finishedReq );
684 finishedReq->clearForRestart();
685 enqueueRequest( finishedReq );
698 if ( fileNeedsCleanup )
701 resFile->resetDispose();
704 _targetFile = locFilename;
708 cancelWithError( std::current_exception() );
709 }
catch (
const std::exception &e ) {
711 cancelWithError( std::current_exception() );
713 cancelWithError( std::current_exception() );
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();
724 std::exception_ptr excpt;
730 ERR <<
"Caught unhandled pipline exception:" << e << std::endl;
732 excpt = std::current_exception ();
733 }
catch (
const std::exception &e ) {
734 ERR <<
"Caught unhandled pipline exception:" << e.what() << std::endl;
736 excpt = std::current_exception ();
738 ERR <<
"Caught unhandled unknown exception:" << std::endl;
739 excpt = std::current_exception ();
743 updateState( Finished );
746 ERR <<
"Rethrowing pipeline exception, this is a BUG!" << std::endl;
747 std::rethrow_exception ( excpt );
760 provider().dequeueRequest ( _runningReq, error );
775 updateState( Finished );
785 if ( std::find( attachedMedia.begin(), attachedMedia.end(),
_handleRef.
mediaInfo() ) == attachedMedia.end() )
799 if (
inf.isExist() &&
inf.isFile() )
807 if (
inf.isExist() &&
inf.isFile() )
824 , _mirrorList ( urls )
830 MIL <<
"Killing the AttachMediaItem" << std::endl;
847 WAR <<
"Double init of AttachMediaItem!" << std::endl;
862 std::optional<ProvideQueue::Config> scheme;
865 const auto &
s =
prov.schemeConfig(
prov.effectiveScheme(
mirrIt->getScheme() ) );
867 WAR <<
"URL: " << *
mirrIt <<
" is not supported, ignoring!" << std::endl;
874 if ( scheme->worker_type () ==
s->worker_type () ) {
877 WAR <<
"URL: " << *
mirrIt <<
" has different worker type than the primary URL: "<<
usableMirrs.front() <<
", ignoring!" << std::endl;
899 auto &attachedMedia =
prov.attachedMediaInfos ();
901 for (
auto &
medium : attachedMedia ) {
927 MIL <<
"Found item providing the same medium, attaching to finished signal and waiting for it to be finished" << std::endl;
960 std::vector<zypp::Url> urls;
997 ERR <<
"Failed to queue request" << std::endl;
1032 }
catch (
const std::exception &
e ) {
1033 ERR <<
"WTF " <<
e.what () << std::endl;
1035 ERR <<
"WTF " << std::endl;
1043 MIL <<
"Before setFinished" << std::endl;
1050 MIL <<
"Cancelling Item with error" << std::endl;
1088 std::rethrow_exception ( result.error() );
1093 MIL_PRV <<
"Master item was cancelled, reverting to Uninitialized state and waiting for scheduler to run again" << std::endl;
1116 WAR <<
"Received event for unknown request, ignoring" << std::endl;
1122 if ( msg.
code() == ProvideMessage::Code::ProvideFinished ) {
1156 }
else if ( msg.
code() == ProvideMessage::Code::NotFound ) {
1173 if ( msg.
code() == ProvideMessage::Code::AttachFinished ) {
1175 std::optional<zypp::Pathname>
mntPoint;
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
void reset()
Reset to default Ctor values.
Store and operate with byte count.
Base class for Exception.
std::string asCompleteString() const
Returns a complete string representation of the Url object.
std::string asString() const
Returns a default string representation of the Url object.
std::string getPathName(EEncoding eflag=zypp::url::E_DECODED) const
Returns the path name from the URL.
void setPathName(const std::string &path, EEncoding eflag=zypp::url::E_DECODED)
Set the path name.
Wrapper class for stat/lstat.
Pathname dirname() const
Return all but the last component od this path.
const std::string & asString() const
String representation.
bool empty() const
Test for an empty path.
static auto connect(typename internal::MemberFunction< SenderFunc >::ClassType &s, SenderFunc &&sFun, typename internal::MemberFunction< ReceiverFunc >::ClassType &recv, ReceiverFunc &&rFunc)
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)
virtual void informalMessage(ProvideQueue &, ProvideRequestRef req, const ProvideMessage &msg)
const std::optional< ItemStats > & previousStats() const
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)
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)
std::string nextMediaId() const
std::vector< AttachedMediaInfo_Ptr > & attachedMediaInfos()
void schedule(ScheduleReason reason)
Signal< std::optional< zypp::media::AuthData >(const zypp::Url &reqUrl, const std::string &triedUsername, const std::map< std::string, std::string > &extraValues) _sigAuthRequired)
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)
void setCurrentQueue(ProvideQueueRef ref)
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)
int unlink(const Pathname &path)
Like 'unlink'.
AutoDispose< const Pathname > ManagedFile
A Pathname plus associated cleanup code to be executed when path is no longer needed.
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 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::unordered_map< std::string, boost::any > AnyMap
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...
std::chrono::steady_clock::time_point _pulseTime
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
#define ZYPP_EXCPT_PTR(EXCPT)
Drops a logline and returns Exception as a std::exception_ptr.
#define ZYPP_IMPL_PRIVATE(Class)