libzypp  17.37.10
attachedmediainfo.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \----------------------------------------------------------------------/
9 */
11 
12 namespace zyppng {
13 
14  IMPL_PTR_TYPE( AttachedMediaInfo )
15 
16 
17  AttachedMediaInfo::AttachedMediaInfo(const std::string &id, ProvideQueue::Config::WorkerType workerType, const zypp::MirroredOrigin &originConfig, ProvideMediaSpec &spec )
18  : AttachedMediaInfo( id, {}, workerType, originConfig, spec )
19  { }
20 
21  AttachedMediaInfo::AttachedMediaInfo(const std::string &id, ProvideQueueWeakRef backingQueue, ProvideQueue::Config::WorkerType workerType, const zypp::MirroredOrigin &originConfig, const ProvideMediaSpec &mediaSpec , const std::optional<zypp::Pathname> &mnt )
22  : _name(id)
23  , _backingQueue( std::move(backingQueue) )
24  , _workerType( workerType )
25  , _originConfig( originConfig )
26  , _spec( mediaSpec )
27  , _localMountPoint( mnt )
28  {
29  // idle on construction, since only the Provide has a reference atm
30  _idleSince = std::chrono::steady_clock::now();
31  }
32 
33  void AttachedMediaInfo::setName(std::string &&name)
34  {
35  _name = std::move(name);
36  }
37 
38  const std::string &AttachedMediaInfo::name() const
39  {
40  return _name;
41  }
42 
44  {
45  if ( !_originConfig.isValid() )
46  return {};
47 
48  return _originConfig.authority().url();
49  }
50 
51  void AttachedMediaInfo::unref_to(unsigned int refCnt) const {
52  // last reference is always owned by the Provide instance
53  if ( refCnt == 1 )
54  _idleSince = std::chrono::steady_clock::now();
55  }
56 
57  void AttachedMediaInfo::ref_to(unsigned int refCnt) const {
58  if ( _idleSince && refCnt > 1 ) _idleSince.reset();
59  }
60 
62  return isSameMedium( _originConfig, _spec, origin, spec );
63  }
64 
65  bool AttachedMediaInfo::isSameMedium( const zypp::MirroredOrigin &originA, const ProvideMediaSpec &specA, const zypp::MirroredOrigin &originB, const ProvideMediaSpec &specB )
66  {
67  const auto check = specA.isSameMedium(specB);
68  if ( !zypp::indeterminate (check) )
69  return (bool)check;
70 
71  // if the endpoints intersect we assume same medium
72  const auto &intersects = []( const zypp::MirroredOrigin &l1, const zypp::MirroredOrigin &l2 ){
73  bool intersect = false;
74  for ( const auto &u: l1 ) {
75  intersect = ( std::find( l2.begin (), l2.end(), u ) != l2.end() );
76  if ( intersect )
77  break;
78  }
79  return intersect;
80  };
81 
82  return intersects( originA, originB );
83  }
84 
85 }
IMPL_PTR_TYPE(AttachedSyncMediaInfo)
const std::string & name() const
void unref_to(unsigned int refCnt) const override
Definition: Arch.h:363
const zypp::Url & url() const
zypp::Url attachedUrl() const
Manages a data source characterized by an authoritative URL and a list of mirror URLs.
void setName(std::string &&name)
zypp::MirroredOrigin _originConfig
std::optional< std::chrono::steady_clock::time_point > _idleSince
Set if the medium is idle.
zypp::TriBool isSameMedium(const ProvideMediaSpec &other) const
Definition: providespec.cc:146
bool check(const std::string &sequenceinfo_r, bool quick_r)
Check via sequence info.
void ref_to(unsigned refCnt) const override
Trigger derived classes after refCount was increased.
Easy-to use interface to the ZYPP dependency resolver.
Definition: Application.cc:19
const OriginEndpoint & authority() const
bool isSameMedium(const zypp::MirroredOrigin &origin, const ProvideMediaSpec &spec)
Url manipulation class.
Definition: Url.h:92
AttachedMediaInfo(const std::string &id, ProvideQueue::Config::WorkerType workerType, const zypp::MirroredOrigin &originConfig, ProvideMediaSpec &spec)