libzypp 17.31.23
MediaNetwork.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
13#include <iostream>
14#include <list>
15#include <chrono>
16
17#include <zypp/base/Logger.h>
18#include <zypp/base/String.h>
19#include <zypp/base/Gettext.h>
20
21#include <zypp-core/base/Regex.h>
22#include <zypp-core/fs/TmpPath.h>
23#include <zypp-core/zyppng/base/EventDispatcher>
24#include <zypp-core/zyppng/base/EventLoop>
25#include <zypp-core/zyppng/base/private/threaddata_p.h>
26
27#include <zypp-curl/ng/network/Downloader>
28#include <zypp-curl/ng/network/NetworkRequestDispatcher>
29#include <zypp-curl/ng/network/DownloadSpec>
30
31#include <zypp-media/MediaConfig>
33#include <zypp-media/auth/CredentialManager>
34
35#include <zypp/Target.h>
36#include <zypp/ZConfig.h>
37
38
39using std::endl;
40
41namespace internal {
42
43
44 constexpr std::string_view MEDIACACHE_REGEX("^\\/media\\.[1-9][0-9]*\\/media$");
45
47
48 using clock = std::chrono::steady_clock;
49
50 std::optional<clock::time_point> _timeStart;
51 std::optional<clock::time_point> _timeLast;
52
53 double _dnlTotal = 0.0;
54 double _dnlLast = 0.0;
55 double _dnlNow = 0.0;
56
57 int _dnlPercent= 0;
58
59 double _drateTotal= 0.0;
60 double _drateLast = 0.0;
61
62 void updateStats( double dltotal = 0.0, double dlnow = 0.0 )
63 {
64 clock::time_point now = clock::now();
65
66 if ( !_timeStart )
67 _timeStart = _timeLast = now;
68
69 // If called without args (0.0), recompute based on the last values seen
70 if ( dltotal && dltotal != _dnlTotal )
71 _dnlTotal = dltotal;
72
73 if ( dlnow && dlnow != _dnlNow ) {
74 _dnlNow = dlnow;
75 }
76
77 // percentage:
78 if ( _dnlTotal )
79 _dnlPercent = int(_dnlNow * 100 / _dnlTotal);
80
81 // download rates:
82 _drateTotal = _dnlNow / std::max( std::chrono::duration_cast<std::chrono::seconds>(now - *_timeStart).count(), int64_t(1) );
83
84 if ( _timeLast < now )
85 {
86 _drateLast = (_dnlNow - _dnlLast) / int( std::chrono::duration_cast<std::chrono::seconds>(now - *_timeLast).count() );
87 // start new period
88 _timeLast = now;
90 }
91 else if ( _timeStart == _timeLast )
93 }
94 };
95
96
97 // All media handler instances share the same EventDispatcher and Downloader
98 // This is released at application shutdown.
99 struct SharedData {
100
102 MIL << "Releasing internal::SharedData for MediaNetwork." << std::endl;
103 }
104
105 static std::shared_ptr<SharedData> instance () {
106 static std::shared_ptr<SharedData> data = std::shared_ptr<SharedData>( new SharedData() );
107 return data;
108 }
109
110 static const zypp::str::regex &mediaRegex () {
111 static zypp::str::regex reg( MEDIACACHE_REGEX.data() );
112 return reg;
113 }
114
115 // we need to keep a reference
116 zyppng::EventDispatcherRef _dispatcher;
117 zyppng::DownloaderRef _downloader;
118
120
121 MediaFileCacheEntry( zypp::ManagedFile &&file ) : _file( std::move(file) ) { }
122
123 std::chrono::steady_clock::time_point _creationTime = std::chrono::steady_clock::now();
125 };
126
127 auto findInCache( const std::string &mediaCacheKey ) {
128 auto i = _mediaCacheEntries.find( mediaCacheKey );
129 if ( i != _mediaCacheEntries.end() ) {
130 auto age = std::chrono::steady_clock::now() - i->second._creationTime;
131 if ( age > std::chrono::minutes( 30 ) ) {
132 MIL << "Found cached media file, but it's older than 30 mins, requesting a new one" << std::endl;
133 _mediaCacheEntries.erase(i);
134 } else {
135 return i;
136 }
137 }
138 return _mediaCacheEntries.end();
139 }
140
142 std::unordered_map<std::string, MediaFileCacheEntry> _mediaCacheEntries;
143
144 private:
146 MIL << "Initializing internal::SharedData for MediaNetwork" << std::endl;
147 _dispatcher = zyppng::ThreadData::current().ensureDispatcher();
148 _downloader = std::make_shared<zyppng::Downloader>();
149 _downloader->requestDispatcher()->setMaximumConcurrentConnections( zypp::MediaConfig::instance().download_max_concurrent_connections() );
150 }
151 };
152
153}
154
155using namespace internal;
156using namespace zypp::base;
157
158namespace zypp {
159
160 namespace media {
161
163 const Pathname & attach_point_hint_r )
164 : MediaNetworkCommonHandler( url_r, attach_point_hint_r,
165 "/", // urlpath at attachpoint
166 true ) // does_download
167 {
168 MIL << "MediaNetwork::MediaNetwork(" << url_r << ", " << attach_point_hint_r << ")" << endl;
169
170 // make sure there is a event loop and downloader instance
172
173 if( !attachPoint().empty())
174 {
175 PathInfo ainfo(attachPoint());
176 Pathname apath(attachPoint() + "XXXXXX");
177 char *atemp = ::strdup( apath.asString().c_str());
178 char *atest = NULL;
179 if( !ainfo.isDir() || !ainfo.userMayRWX() ||
180 atemp == NULL || (atest=::mkdtemp(atemp)) == NULL)
181 {
182 WAR << "attach point " << ainfo.path()
183 << " is not useable for " << url_r.getScheme() << endl;
184 setAttachPoint("", true);
185 }
186 else if( atest != NULL)
187 ::rmdir(atest);
188
189 if( atemp != NULL)
190 ::free(atemp);
191 }
192 }
193
194 void MediaNetwork::attachTo (bool next)
195 {
196 if ( next )
198
199 if ( !_url.isValid() )
201
202 // use networkdispatcher check if the scheme is supported
203 if ( !_shared->_downloader->requestDispatcher()->supportsProtocol( _url ) ) {
204 std::string msg("Unsupported protocol '");
205 msg += _url.getScheme();
206 msg += "'";
208 }
209
211 {
213 }
214
216
218 setMediaSource(media);
219 }
220
221 bool
223 {
224 return MediaHandler::checkAttachPoint( apoint, true, true);
225 }
226
228 {
229 }
230
231 void MediaNetwork::releaseFrom( const std::string & ejectDev )
232 {
233 disconnect();
234 }
235
237 {
238 bool retry = true;
239 unsigned internalTry = 0;
240 static constexpr unsigned maxInternalTry = 3;
241
242 while ( retry ) {
243 retry = false;
244 auto ev = zyppng::EventLoop::create();
245 std::vector<zyppng::connection> signalConnections;
246 OnScopeExit deferred([&](){
247 while( signalConnections.size() ) {
248 signalConnections.back().disconnect();
249 signalConnections.pop_back();
250 }
251 });
252
253 zyppng::DownloadRef dl = _shared->_downloader->downloadFile( spec );
254 std::optional<internal::ProgressTracker> progTracker;
255
256 const auto &startedSlot = [&]( zyppng::Download &req ){
257 if ( !report) return;
258 (*report)->start( spec.url(), spec.targetPath());
259 };
260
261 const auto &aliveSlot = [&]( zyppng::Download &req, off_t dlNow ){
262 if ( !report || !progTracker )
263 return;
264 progTracker->updateStats( 0.0, dlNow );
265 if ( !(*report)->progress( progTracker->_dnlPercent, spec.url(), progTracker-> _drateTotal, progTracker->_drateLast ) )
266 req.cancel();
267 };
268
269 const auto &progressSlot = [&]( zyppng::Download &req, off_t dlTotal, off_t dlNow ) {
270 if ( !report || !progTracker )
271 return;
272
273 progTracker->updateStats( dlTotal, dlNow );
274 if ( !(*report)->progress( progTracker->_dnlPercent, spec.url(), progTracker-> _drateTotal, progTracker->_drateLast ) )
275 req.cancel();
276 };
277
278 const auto &finishedSlot = [&]( zyppng::Download & ){
279 ev->quit();
280 };
281
282 bool firstTry = true;
283 const auto &authRequiredSlot = [&]( zyppng::Download &req, zyppng::NetworkAuthData &auth, const std::string &availAuth ){
284
287 CurlAuthData_Ptr credentials;
288
289 // get stored credentials
290 AuthData_Ptr cmcred = cm.getCred(_url);
291 if ( cmcred && auth.lastDatabaseUpdate() < cmcred->lastDatabaseUpdate() ) {
292 credentials.reset(new CurlAuthData(*cmcred));
293 DBG << "got stored credentials:" << endl << *credentials << endl;
294
295 } else {
296 // if not found, ask user
297 CurlAuthData_Ptr curlcred;
298 curlcred.reset(new CurlAuthData());
300
301 // preset the username if present in current url
302 if (!_url.getUsername().empty() && firstTry)
303 curlcred->setUsername(_url.getUsername());
304 // if CM has found some credentials, preset the username from there
305 else if (cmcred)
306 curlcred->setUsername(cmcred->username());
307
308 // indicate we have no good credentials from CM
309 cmcred.reset();
310
311 std::string prompt_msg = str::Format(_("Authentication required for '%s'")) % _url.asString();
312
313 // set available authentication types from the signal
314 // might be needed in prompt
315 curlcred->setAuthType( availAuth );
316
317 // ask user
318 if (auth_report->prompt(_url, prompt_msg, *curlcred))
319 {
320 DBG << "callback answer: retry" << endl
321 << "CurlAuthData: " << *curlcred << endl;
322
323 if (curlcred->valid())
324 {
325 credentials = curlcred;
326 // if (credentials->username() != _url.getUsername())
327 // _url.setUsername(credentials->username());
335 }
336 }
337 else
338 {
339 DBG << "callback answer: cancel" << endl;
340 }
341 }
342
343 if ( !credentials ) {
345 return;
346 }
347
348 auth = *credentials;
349 if (!cmcred) {
350 credentials->setUrl(_url);
351 cm.addCred(*credentials);
352 cm.save();
353 }
354 };
355
356 signalConnections.insert( signalConnections.end(), {
357 dl->connectFunc( &zyppng::Download::sigStarted, startedSlot),
358 dl->connectFunc( &zyppng::Download::sigFinished, finishedSlot ),
359 dl->connectFunc( &zyppng::Download::sigAuthRequired, authRequiredSlot )
360 });
361
362 if ( report ) {
363 progTracker = internal::ProgressTracker();
364 signalConnections.insert( signalConnections.end(), {
365 dl->connectFunc( &zyppng::Download::sigAlive, aliveSlot ),
366 dl->connectFunc( &zyppng::Download::sigProgress, progressSlot ),
367 });
368 }
369
370 dl->start();
371 ev->run();
372
373 std::for_each( signalConnections.begin(), signalConnections.end(), []( auto &conn ) { conn.disconnect(); });
374
375 if ( dl->hasError() ) {
377 std::exception_ptr excp;
378 const auto &error = dl->lastRequestError();
379 switch ( error.type() ) {
389 excp = ZYPP_EXCPT_PTR( zypp::media::MediaCurlException( spec.url(), error.toString(), error.nativeErrorString() ) );
390 break;
391 }
394 break;
395 }
398 break;
399 }
401 excp = ZYPP_EXCPT_PTR( zypp::media::MediaTemporaryProblemException( spec.url(), error.toString() ) );
402 break;
403 }
405 excp = ZYPP_EXCPT_PTR( zypp::media::MediaTimeoutException( spec.url(), error.toString() ) );
406 break;
407 }
409 excp = ZYPP_EXCPT_PTR( zypp::media::MediaForbiddenException( spec.url(), error.toString() ) );
410 break;
411 }
414
415 //@BUG using getPathName() can result in wrong error messages
417 break;
418 }
422 excp = ZYPP_EXCPT_PTR( zypp::media::MediaUnauthorizedException( spec.url(), error.toString(), error.nativeErrorString(), "" ) );
423 break;
424 }
426 // should never happen
427 DBG << "BUG: Download error flag is set , but Error code is NoError" << std::endl;
428 break;
431 ++internalTry;
432 if ( internalTry < maxInternalTry ) {
433 retry = true;
434 // just report (NO_ERROR); no interactive request to the user
435 (*report)->problem( spec.url(), media::DownloadProgressReport::NO_ERROR, error.toString()+" "+_("Will try again..."));
436 continue;
437 } else {
438 excp = ZYPP_EXCPT_PTR( zypp::media::MediaCurlException( spec.url(), error.toString(), error.nativeErrorString() ) );
439 }
440
441 break;
442 }
443 }
444
445 if ( excp && !retry ) {
446 if ( report ) (*report)->finish( spec.url(), errCode, error.toString() );
447 std::rethrow_exception( excp );
448 }
449 }
450 }
451 if ( report ) (*report)->finish( spec.url(), zypp::media::DownloadProgressReport::NO_ERROR, "" );
452 }
453
454 void MediaNetwork::getFile( const OnMediaLocation &file ) const
455 {
456 // Use absolute file name to prevent access of files outside of the
457 // hierarchy below the attach point.
458 getFileCopy( file, localPath(file.filename()).absolutename() );
459 }
460
461 void MediaNetwork::getFileCopy( const OnMediaLocation & file, const Pathname & targetFilename ) const
462 {
463 const auto &filename = file.filename();
464 Url fileurl(getFileUrl(filename));
465
466 const bool requestedMediaFile = _shared->mediaRegex().matches( filename.asString() );
467 auto &mediaFileCache = _shared->_mediaCacheEntries;
468 const auto &mediaCacheKey = fileurl.asCompleteString();
469
470 DBG << "FILEURL IS: " << fileurl << std::endl;
471 DBG << "Downloading to: " << targetFilename << std::endl;
472
473 if( assert_dir( targetFilename.dirname() ) ) {
474 DBG << "assert_dir " << targetFilename.dirname() << " failed" << endl;
475 ZYPP_THROW( MediaSystemException(getFileUrl(file.filename()), "System error on " + targetFilename.dirname().asString()) );
476 }
477
478 if ( requestedMediaFile ) {
479 MIL << "Requested " << filename << " trying media cache first" << std::endl;
480
481 auto i = _shared->findInCache( mediaCacheKey );
482 if ( i != mediaFileCache.end() ) {
483 MIL << "Found cached media file, returning a copy to the file" << std::endl;
484 if ( zypp::filesystem::hardlinkCopy( i->second._file, targetFilename ) == 0 )
485 return;
486
487 mediaFileCache.erase(i);
488 MIL << "Failed to copy the requested file, proceeding with download" << std::endl;
489 }
490
491 MIL << "Nothing in the file cache, requesting the file from the server." << std::endl;
492 }
493
494 zyppng::DownloadSpec spec = zyppng::DownloadSpec( fileurl, targetFilename, file.downloadSize() )
495 .setDeltaFile( file.deltafile() )
496 .setHeaderSize( file.headerSize())
499
501
502 try {
503 runRequest( spec, &report );
504 } catch ( const zypp::media::MediaFileNotFoundException &ex ) {
505 if ( requestedMediaFile ) {
506 MIL << "Media file was not found, remembering in the cache" << std::endl;
507 mediaFileCache.insert_or_assign( mediaCacheKey, internal::SharedData::MediaFileCacheEntry( zypp::ManagedFile() ) );
508 }
509 std::rethrow_exception( std::current_exception() );
510 }
511
512 // the request was successful
513 if ( requestedMediaFile ) {
514 const auto &cacheFileName = (_shared->_mediaCacheDir.path() / zypp::CheckSum::md5FromString( mediaCacheKey).asString() ).extend(".cache");
515 zypp::ManagedFile file( cacheFileName, zypp::filesystem::unlink );
516 if ( zypp::filesystem::hardlinkCopy( targetFilename, cacheFileName ) == 0 ) {
517 mediaFileCache.insert_or_assign( mediaCacheKey, internal::SharedData::MediaFileCacheEntry( std::move(file) ) );
518 MIL << "Saved requested media file in media cache for future use" << std::endl;
519 } else {
520 MIL << "Failed to save requested media file in cache, requesting again next time." << std::endl;
521 }
522 }
523 }
524
525 bool MediaNetwork::getDoesFileExist( const Pathname & filename ) const
526 {
527 MIL << "Checking if file " << filename << " does exist" << std::endl;
528 Url fileurl(getFileUrl(filename));
529 const bool requestMediaFile = _shared->mediaRegex().matches( filename.asString() );
530 auto &mediaFileCache = _shared->_mediaCacheEntries;
531 const auto &mediaCacheKey = fileurl.asCompleteString();
532
533 if ( requestMediaFile ) {
534 MIL << "Request for " << filename << " is a media file, trying the cache first" << std::endl;
535 auto i = _shared->findInCache( mediaCacheKey );
536 if ( i != mediaFileCache.end() ) {
537 MIL << "Found a cache entry for requested media file, returning right away" << std::endl;
538 if ( i->second._file->empty() ) {
539 return false;
540 } else {
541 return true;
542 }
543 }
544 }
545
546 bool result = false; //we are pessimists
547 try
548 {
549 const auto &targetFilePath = localPath(filename).absolutename();
550
551 zyppng::DownloadSpec spec = zyppng::DownloadSpec( fileurl, targetFilePath )
552 .setCheckExistsOnly( true )
554
555 runRequest( spec );
556 // if we get to here the request worked.
557 result = true;
558 }
559 catch ( const MediaFileNotFoundException &e ) {
560 // if the file did not exist then we can return false
561 ZYPP_CAUGHT(e);
562 result = false;
563 }
564 // unexpected exception
565 catch (MediaException & excpt_r)
566 {
567 ZYPP_RETHROW(excpt_r);
568 }
569
570 // if the file does not exist remember it right away in our cache
571 if ( !result && requestMediaFile ) {
572 MIL << filename << " does not exist on medium, remembering in the cache" << std::endl;
573 mediaFileCache.insert_or_assign( mediaCacheKey, internal::SharedData::MediaFileCacheEntry( zypp::ManagedFile() ) );
574 }
575
576 return result;
577 }
578
579 void MediaNetwork::getDir( const Pathname & dirname, bool recurse_r ) const
580 {
582 getDirInfo( content, dirname, /*dots*/false );
583
584 for ( filesystem::DirContent::const_iterator it = content.begin(); it != content.end(); ++it ) {
585 Pathname filename = dirname + it->name;
586 int res = 0;
587
588 switch ( it->type ) {
589 case filesystem::FT_NOT_AVAIL: // old directory.yast contains no typeinfo at all
591 getFile( OnMediaLocation( filename ) );
592 break;
593 case filesystem::FT_DIR: // newer directory.yast contain at least directory info
594 if ( recurse_r ) {
595 getDir( filename, recurse_r );
596 } else {
597 res = assert_dir( localPath( filename ) );
598 if ( res ) {
599 WAR << "Ignore error (" << res << ") on creating local directory '" << localPath( filename ) << "'" << endl;
600 }
601 }
602 break;
603 default:
604 // don't provide devices, sockets, etc.
605 break;
606 }
607 }
608 }
609
610 void MediaNetwork::getDirInfo( std::list<std::string> & retlist,
611 const Pathname & dirname, bool dots ) const
612 {
613 getDirectoryYast( retlist, dirname, dots );
614 }
615
617 const Pathname & dirname, bool dots ) const
618 {
619 getDirectoryYast( retlist, dirname, dots );
620 }
621
622 } // namespace media
623} // namespace zypp
624//
std::string asString() const
Definition: CheckSum.cc:176
static CheckSum md5FromString(const std::string &input_r)
Definition: CheckSum.h:103
static MediaConfig & instance()
Definition: mediaconfig.cc:46
Describes a resource file located on a medium.
const ByteCount & downloadSize() const
The size of the resource on the server.
const Pathname & filename() const
The path to the resource on the medium.
const Pathname & deltafile() const
The existing deltafile that can be used to reduce download size ( zchunk or metalink )
const ByteCount & headerSize() const
The size of the header prepending the resource (e.g.
const CheckSum & headerChecksum() const
The checksum of the header prepending the resource (e.g.
Url manipulation class.
Definition: Url.h:92
std::string getScheme() const
Returns the scheme name of the URL.
Definition: Url.cc:533
std::string asCompleteString() const
Returns a complete string representation of the Url object.
Definition: Url.cc:505
std::string asString() const
Returns a default string representation of the Url object.
Definition: Url.cc:497
std::string getUsername(EEncoding eflag=zypp::url::E_DECODED) const
Returns the username from the URL authority.
Definition: Url.cc:572
std::string getPathName(EEncoding eflag=zypp::url::E_DECODED) const
Returns the path name from the URL.
Definition: Url.cc:604
bool isValid() const
Verifies the Url.
Definition: Url.cc:489
static ZConfig & instance()
Singleton ctor.
Definition: ZConfig.cc:922
Wrapper class for stat/lstat.
Definition: PathInfo.h:221
bool userMayRWX() const
Definition: PathInfo.h:353
const Pathname & path() const
Return current Pathname.
Definition: PathInfo.h:246
Pathname dirname() const
Return all but the last component od this path.
Definition: Pathname.h:124
const std::string & asString() const
String representation.
Definition: Pathname.h:91
Pathname absolutename() const
Return this path, adding a leading '/' if relative.
Definition: Pathname.h:139
Provide a new empty temporary directory and recursively delete it when no longer needed.
Definition: TmpPath.h:178
static const Pathname & defaultLocation()
Definition: TmpPath.cc:157
void save()
Saves any unsaved credentials added via addUserCred() or addGlobalCred() methods.
AuthData_Ptr getCred(const Url &url)
Get credentials for the specified url.
void addCred(const AuthData &cred)
Add new credentials with user callbacks.
Curl HTTP authentication data.
Definition: curlauthdata.h:22
Just inherits Exception to separate media exceptions.
bool isUseableAttachPoint(const Pathname &path, bool mtab=true) const
Ask media manager, if the specified path is already used as attach point or if there are another atta...
virtual bool checkAttachPoint(const Pathname &apoint) const
Verify if the specified directory as attach point (root) as requires by the particular media handler ...
void disconnect()
Use concrete handler to isconnect media.
Pathname createAttachPoint() const
Try to create a default / temporary attach point.
void setMediaSource(const MediaSourceRef &ref)
Set new media source reference.
Pathname localPath(const Pathname &pathname) const
Files provided will be available at 'localPath(filename)'.
const Url _url
Url to handle.
Definition: MediaHandler.h:113
void getDirectoryYast(std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const
Retrieve and if available scan dirname/directory.yast.
void setAttachPoint(const Pathname &path, bool temp)
Set a new attach point.
Pathname attachPoint() const
Return the currently used attach point.
Common baseclass for MediaCurl and MediaNetwork.
Url getFileUrl(const Pathname &filename) const
concatenate the attach url and the filename to a complete download url
bool checkAttachPoint(const Pathname &apoint) const override
Verify if the specified directory as attach point (root) as requires by the particular media handler ...
void disconnectFrom() override
void attachTo(bool next=false) override
Call concrete handler to attach the media.
void getDirInfo(std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const override
Call concrete handler to provide a content list of directory on media via retlist.
void getDir(const Pathname &dirname, bool recurse_r) const override
Call concrete handler to provide directory content (not recursive!) below attach point.
bool getDoesFileExist(const Pathname &filename) const override
void runRequest(const zyppng::DownloadSpec &spec, callback::SendReport< DownloadProgressReport > *report=nullptr) const
MediaNetwork(const Url &url_r, const Pathname &attach_point_hint_r)
void releaseFrom(const std::string &ejectDev) override
Call concrete handler to release the media.
void getFile(const OnMediaLocation &file) const override
Call concrete handler to provide file below attach point.
void getFileCopy(const OnMediaLocation &file, const Pathname &targetFilename) const override
Call concrete handler to provide a file under a different place in the file system (usually not under...
std::shared_ptr<::internal::SharedData > _shared
Definition: MediaNetwork.h:77
Media source internally used by MediaManager and MediaHandler.
Definition: MediaSource.h:37
Regular expression.
Definition: Regex.h:95
DownloadSpec & setDeltaFile(const zypp::Pathname &file)
Definition: downloadspec.cc:94
DownloadSpec & setCheckExistsOnly(bool set=true)
Definition: downloadspec.cc:83
DownloadSpec & setHeaderChecksum(const zypp::CheckSum &sum)
DownloadSpec & setHeaderSize(const zypp::ByteCount &bc)
const zypp::Pathname & targetPath() const
Definition: downloadspec.cc:61
const Url & url() const
Definition: downloadspec.cc:50
DownloadSpec & setTransferSettings(TransferSettings &&set)
zypp::ByteCount expectedFileSize() const
constexpr std::string_view MEDIACACHE_REGEX("^\\/media\\.[1-9][0-9]*\\/media$")
Definition: Arch.h:361
int unlink(const Pathname &path)
Like 'unlink'.
Definition: PathInfo.cc:700
int hardlinkCopy(const Pathname &oldpath, const Pathname &newpath)
Create newpath as hardlink or copy of oldpath.
Definition: PathInfo.cc:883
std::list< DirEntry > DirContent
Returned by readdir.
Definition: PathInfo.h:518
shared_ptr< CurlAuthData > CurlAuthData_Ptr
Definition: curlauthdata.h:102
shared_ptr< AuthData > AuthData_Ptr
Definition: authdata.h:79
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
zypp::media::CurlAuthData NetworkAuthData
Definition: authdata.h:24
double _drateLast
Download rate in last period.
Definition: MediaNetwork.cc:60
double _drateTotal
Download rate so far.
Definition: MediaNetwork.cc:59
void updateStats(double dltotal=0.0, double dlnow=0.0)
Definition: MediaNetwork.cc:62
double _dnlTotal
Bytes to download or 0 if unknown.
Definition: MediaNetwork.cc:53
double _dnlLast
Bytes downloaded at period start.
Definition: MediaNetwork.cc:54
std::chrono::steady_clock clock
Definition: MediaNetwork.cc:48
double _dnlNow
Bytes downloaded now.
Definition: MediaNetwork.cc:55
int _dnlPercent
Percent completed or 0 if _dnlTotal is unknown.
Definition: MediaNetwork.cc:57
std::optional< clock::time_point > _timeStart
Start total stats.
Definition: MediaNetwork.cc:50
std::optional< clock::time_point > _timeLast
Start last period(~1sec)
Definition: MediaNetwork.cc:51
std::chrono::steady_clock::time_point _creationTime
MediaFileCacheEntry(zypp::ManagedFile &&file)
zypp::filesystem::TmpDir _mediaCacheDir
static std::shared_ptr< SharedData > instance()
static const zypp::str::regex & mediaRegex()
std::unordered_map< std::string, MediaFileCacheEntry > _mediaCacheEntries
zyppng::DownloaderRef _downloader
zyppng::EventDispatcherRef _dispatcher
auto findInCache(const std::string &mediaCacheKey)
Convenient building of std::string with boost::format.
Definition: String.h:253
#define ZYPP_RETHROW(EXCPT)
Drops a logline and rethrows, updating the CodeLocation.
Definition: Exception.h:440
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
Definition: Exception.h:436
#define ZYPP_EXCPT_PTR(EXCPT)
Drops a logline and returns Exception as a std::exception_ptr.
Definition: Exception.h:432
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:428
#define _(MSG)
Definition: Gettext.h:37
#define DBG
Definition: Logger.h:95
#define MIL
Definition: Logger.h:96
#define WAR
Definition: Logger.h:97