25 inline bool preloadEnabled()
28 if ( indeterminate(envstate) ) {
29 #if APIConfig(LIBZYPP_CONFIG_USE_SERIAL_PACKAGE_DOWNLOAD_BY_DEFAULT) 35 return bool(envstate);
39 if ( pck.isKind<Package>() ) {
41 }
else if ( pck.isKind<SrcPackage>() ) {
88 MIL <<
"No more jobs pending, exiting worker" << std::endl;
110 ERR <<
"Failed to create target dir for file: " <<
_targetPath << std::endl;
122 ERR <<
"Failed to create job URL for file: " <<
_targetPath <<
" ("<<e<<
")" << std::endl;
132 if ( !pathInfo.
isFile() ) {
133 if ( pathInfo.
isDir () )
155 _req = std::make_shared<zyppng::NetworkRequest>( url,
_tmpFile );
160 _req->resetRequestRanges();
168 _req->transferSettings() = settings;
181 const auto &pi =
_job;
230 std::vector<RepoUrl>::iterator curr = repoDlInfo._baseUrls.end();
231 int currentSmallestRef = INT_MAX;
233 for (
auto i = repoDlInfo._baseUrls.begin(); i != repoDlInfo._baseUrls.end(); i++ ) {
234 auto mirrorPtr = &(*i);
236 if ( skip == mirrorPtr )
244 if ( ( i->refs + i->miss ) < currentSmallestRef ) {
245 currentSmallestRef = ( i->refs + i->miss );
250 if ( curr == repoDlInfo._baseUrls.end() )
256 MIL <<
"Request for " << req.
url() <<
" started" << std::endl;
264 userData.
set(
"Url",
_req->url() );
279 MIL <<
"Request for " << req.
url() <<
" finished. (" << err.
toString() <<
")" << std::endl;
291 const auto &error = req.
error();
292 switch ( error.type() ) {
309 ERR <<
"Download from mirror failed for file " << req.
url () <<
" trying to taint mirror and move on" << std::endl;
323 MIL <<
"Found new mirror: " << url <<
" recovering, retry count: " <<
_notFoundRetry << std::endl;
326 _req->transferSettings () = settings;
332 ERR <<
"Failed to setup mirror: ( " << e <<
" ), trying next!" << std::endl;
339 ERR <<
"No mirror found, giving up on file: " << req.
url() << std::endl;
347 std::string authHint = error.extraInfoValue(
"authHint", std::string());
366 DBG <<
"BUG: Download error flag is set , but Error code is NoError" << std::endl;
377 userData.
set(
"Url", *url );
379 userData.
set(
"description", *errorMessage );
398 if ( loc.medianr() > 1 )
406 std::string header { el.first };
409 MIL <<
"Added custom header -> " << header << std::endl;
414 resultSet = settings;
420 zyppng::NetworkRequestRef
_req;
444 if ( !preloadEnabled() ) {
445 MIL <<
"CommitPackagePreloader disabled" << std::endl;
451 MIL <<
"No receiver for the CommitPreloadReport, skipping preload phase" << std::endl;
456 _dispatcher = std::make_shared<zyppng::NetworkRequestDispatcher>();
465 _pTracker = std::make_shared<internal::ProgressTracker>();
476 for (
const auto &step : steps ) {
477 switch ( step.stepType() )
496 if ( pi->lookupLocation().checksum().empty() )
500 if( !pckCachedLocation(pi).empty() )
503 auto repoDlsIter =
_dlRepoInfo.find( pi.repository().id() );
508 ERR <<
"Failed to create predownload cache for repo " << pi.repoInfo().alias() << std::endl;
513 std::vector<RepoUrl> repoUrls;
514 const auto origins = pi.repoInfo().repoOrigins();
515 for (
const auto &origin: origins ) {
526 if ( rewriteUrl.isValid () )
530 if ( !pi.repoInfo().path().emptyOrRoot() )
533 MIL <<
"Adding Url: " << url <<
" to the mirror set" << std::endl;
537 .headers = std::move(custom_headers)
543 if( repoUrls.empty() ) {
544 MIL <<
"Skipping predownload for " << step.satSolvable() <<
" no downloading URL" << std::endl;
550 if ( repoUrls.begin()->baseUrl.getHost() ==
"download.opensuse.org" ){
555 pi.repository().id(),
573 const auto &workerDone = [&,
this](){
574 if ( std::all_of(
_workers.begin(),
_workers.end(), [](
const auto &w ) {
return w->finished();} ) )
590 auto worker = std::make_shared<PreloadWorker>(*this);
591 worker->sigWorkerFinished().connect(workerDone);
593 _workers.push_back( std::move(worker) );
597 MIL <<
"Running preload event loop!" << std::endl;
601 MIL <<
"Preloading done, mirror stats: " << std::endl;
603 std::for_each ( elem.second._baseUrls.begin (), elem.second._baseUrls.end(), [](
const RepoUrl &repoUrl ){
604 MIL <<
"url: " << repoUrl.baseUrl <<
" misses: " << repoUrl.miss << std::endl;
607 MIL <<
"Preloading done, mirror stats end" << std::endl;
612 if ( !preloadEnabled() ) {
613 MIL <<
"CommitPackagePreloader disabled" << std::endl;
629 const auto now = clock::now();
630 bool canUpdate =
false;
632 const auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(now - *
_lastProgressUpdate);
633 canUpdate = (duration >= std::chrono::milliseconds(500));
645 userData.
set(
"dbps_avg" , static_cast<double>(
_pTracker->_drateTotal ) );
646 userData.
set(
"dbps_current", static_cast<double>(
_pTracker->_drateLast ) );
647 userData.
set(
"bytesReceived", static_cast<double>(
_pTracker->_dnlNow ) );
648 userData.
set(
"bytesRequired", static_cast<double>(
_pTracker->_dnlTotal ) );
RepoUrl * findUsableMirror(RepoUrl *skip=nullptr, bool allowTainted=true)
Tries to find a usable mirror
Repository::IdType _currentRepoId
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
Pathname cachedLocation(const OnMediaLocation &loc_r, const RepoInfo &repo_r)
void onRequestStarted(zyppng::NetworkRequest &req)
[M] Install(multiversion) item (
static ZConfig & instance()
Singleton ctor.
int clean_dir(const Pathname &path)
Like 'rm -r DIR/ *'.
SignalProxy< void(NetworkRequest &req, zypp::ByteCount count)> sigBytesDownloaded()
Signals that new data has been downloaded, this is only the payload and does not include control data...
zyppng::NetworkRequestRef _req
std::string asString(const Patch::Category &obj)
relates: Patch::Category string representation.
void appendPathName(const Pathname &path_r, EEncoding eflag_r=zypp::url::E_DECODED)
Extend the path name.
void finishCurrentJob(const zypp::Pathname &localPath, const std::optional< zypp::Url > &url, media::CommitPreloadReport::Error e, const std::optional< std::string > &errorMessage, bool fatal)
void reset()
Reset to default Ctor values.
Store and operate with byte count.
static const RepoIdType noRepoId(0)
Id to denote Repo::noRepository.
std::optional< clock::time_point > _lastProgressUpdate
CommitPackagePreloader & _parent
zyppng::Signal< void()> _sigFinished
std::set< RepoUrl * > _taintedMirrors
std::string toString() const
toString Returns a string representation of the error
String related utilities and Regular expression matching.
media::UrlResolverPlugin::HeaderList headers
const std::string & asString(const std::string &t)
Global asString() that works with std::string too.
media::UrlResolverPlugin::HeaderList headers
zyppng::NetworkRequestDispatcherRef _dispatcher
std::string basename() const
Return the last component of this path.
TransferSettings & transferSettings()
callback::SendReport< media::CommitPreloadReport > _report
void preloadTransaction(const std::vector< sat::Transaction::Step > &steps)
OnMediaLocation lookupLocation() const
bool hasError() const
Checks if there was a error with the request.
void prepareSettingsAndUrl(zypp::Url &url_r, zypp::media::TransferSettings &s)
boost::logic::tribool TriBool
3-state boolean logic (true, false and indeterminate).
void onRequestFinished(zyppng::NetworkRequest &req, const zyppng::NetworkRequestError &err)
bool taintCurrentMirror()
Taints the current mirror, returns true if a alternative was found
void makeJobUrl(zypp::Url &resultUrl, media::TransferSettings &resultSet)
TriBool getenvBool(const C_Str &var_r)
If the environment variable var_r is set to a legal true or false string return bool, else indeterminate.
zypp::Pathname _targetPath
ByteCount _downloadedBytes
bool set(const std::string &key_r, AnyType val_r)
Set the value for key (nonconst version always returns true).
zyppng::Ref< internal::ProgressTracker > _pTracker
bool isExist() const
Return whether valid stat info exists.
std::vector< zyppng::Ref< PreloadWorker > > _workers
std::string asUserString() const
Translated error message as string suitable for the user.
RepoInfo repoInfo() const
Pathname dirname() const
Return all but the last component od this path.
void onRequestProgress(zyppng::NetworkRequest &req, zypp::ByteCount count)
RepoInfo info() const
Return any associated RepoInfo.
The NetworkRequestError class Represents a error that occured in.
NetworkRequestError error() const
Returns the last set Error.
std::string extendedErrorString() const
In some cases, curl can provide extended error information collected at runtime.
std::deque< PoolItem > _requiredDls
sat::detail::RepoIdType IdType
std::map< Repository::IdType, RepoDownloadData > _dlRepoInfo
std::vector< RepoUrl > _baseUrls
int unlink(const Pathname &path)
Like 'unlink'.
void resetDispose()
Set no dispose function.
Pathname predownloadPath() const
Path where this repo packages are predownloaded.
zyppng::SignalProxy< void()> sigWorkerFinished()
Base class for Exception.
bool any_of(const Container &c, Fnc &&cb)
Typesafe passing of user data via callbacks.
int chmodApplyUmask(const Pathname &path, mode_t mode)
Similar to 'chmod', but mode is modified by the process's umask in the usual way. ...
Wrapper class for ::stat/::lstat.
void reportBytesDownloaded(ByteCount newBytes)
Combining sat::Solvable and ResStatus.
SignalProxy< void(NetworkRequest &req, const NetworkRequestError &err)> sigFinished()
Signals that the download finished.
bool isKind(const ResKind &kind_r) const
SignalProxy< void(NetworkRequest &req)> sigStarted()
Signals that the dispatcher dequeued the request and actually starts downloading data.
int rename(const Pathname &oldpath, const Pathname &newpath)
Like 'rename'.
IdType id() const
Expert backdoor.
Easy-to use interface to the ZYPP dependency resolver.
Represents a single, configurable network endpoint, combining a URL with specific access settings...
int rmdir(const Pathname &path)
Like 'rmdir'.
Repository repository() const
static Ptr create(GMainContext *ctx=nullptr)
bool is_checksum(const Pathname &file, const CheckSum &checksum)
check files checksum
PreloadWorker(CommitPackagePreloader &parent)
static ManagedFile asManagedFile()
Create a temporary file and convert it to a automatically cleaned up ManagedFile. ...