libzypp 17.37.2
attachedmediainfo.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\----------------------------------------------------------------------/
9*/
11
12namespace zyppng {
13
15
16
17 AttachedMediaInfo::AttachedMediaInfo(const std::string &id, ProvideQueue::Config::WorkerType workerType, const zypp::Url &baseUrl, const std::vector<zypp::Url> &mirrors, ProvideMediaSpec &spec )
18 : AttachedMediaInfo( id, {}, workerType, baseUrl, mirrors, spec )
19 { }
20
21 AttachedMediaInfo::AttachedMediaInfo(const std::string &id, ProvideQueueWeakRef backingQueue, ProvideQueue::Config::WorkerType workerType, const zypp::Url &baseUrl, const std::vector<zypp::Url> &mirrors, const ProvideMediaSpec &mediaSpec , const std::optional<zypp::Pathname> &mnt )
22 : _name(id)
23 , _backingQueue( std::move(backingQueue) )
24 , _workerType( workerType )
25 , _mirrors( mirrors )
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 // make sure attach URL is in front
33 if ( _mirrors.empty () ) {
34 _mirrors.push_back ( baseUrl );
35 } else {
36 auto i = std::find( _mirrors.begin(), _mirrors.end(), baseUrl );
37 if ( i != _mirrors.begin() ) {
38 if ( i != _mirrors.end() )
39 _mirrors.erase(i);
40 _mirrors.insert( _mirrors.begin(), baseUrl );
41 }
42 }
43 }
44
45 void AttachedMediaInfo::setName(std::string &&name)
46 {
47 _name = std::move(name);
48 }
49
50 const std::string &AttachedMediaInfo::name() const
51 {
52 return _name;
53 }
54
56 {
57 if ( !_mirrors.size() )
58 return {};
59
60 return _mirrors.at(0);
61 }
62
63 void AttachedMediaInfo::unref_to(unsigned int refCnt) const {
64 // last reference is always owned by the Provide instance
65 if ( refCnt == 1 )
66 _idleSince = std::chrono::steady_clock::now();
67 }
68
69 void AttachedMediaInfo::ref_to(unsigned int refCnt) const {
70 if ( _idleSince && refCnt > 1 ) _idleSince.reset();
71 }
72
73 bool AttachedMediaInfo::isSameMedium(const std::vector<zypp::Url> &urls, const ProvideMediaSpec &spec) {
74 return isSameMedium( _mirrors, _spec, urls, spec );
75 }
76
77 bool AttachedMediaInfo::isSameMedium(const std::vector<zypp::Url> &mirrorsA, const ProvideMediaSpec &specA, const std::vector<zypp::Url> &mirrorsB, const ProvideMediaSpec &specB)
78 {
79 const auto check = specA.isSameMedium(specB);
80 if ( !zypp::indeterminate (check) )
81 return (bool)check;
82
83 // if the mirrors intersect we assume same medium
84 const auto &intersects = []( const std::vector<zypp::Url> &l1, const std::vector<zypp::Url> &l2 ){
85 bool intersect = false;
86 for ( const auto &u: l1 ) {
87 intersect = ( std::find( l2.begin (), l2.end(), u ) != l2.end() );
88 if ( intersect )
89 break;
90 }
91 return intersect;
92 };
93
94 return intersects( mirrorsA, mirrorsB );
95 }
96
97}
Url manipulation class.
Definition Url.h:93
void unref_to(unsigned int refCnt) const override
bool isSameMedium(const std::vector< zypp::Url > &urls, const ProvideMediaSpec &spec)
const std::string & name() const
std::optional< zypp::Pathname > _localMountPoint
AttachedMediaInfo(const std::string &id, ProvideQueue::Config::WorkerType workerType, const zypp::Url &baseUrl, const std::vector< zypp::Url > &mirrors, ProvideMediaSpec &spec)
std::optional< std::chrono::steady_clock::time_point > _idleSince
Set if the medium is idle.
void ref_to(unsigned refCnt) const override
Trigger derived classes after refCount was increased.
ProvideQueueWeakRef _backingQueue
void setName(std::string &&name)
std::vector< zypp::Url > _mirrors
ProvideQueue::Config::WorkerType _workerType
zypp::TriBool isSameMedium(const ProvideMediaSpec &other) const
Definition Arch.h:364
Easy-to use interface to the ZYPP dependency resolver.
#define IMPL_PTR_TYPE(NAME)