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