libzypp 17.31.0
InstanceId.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12//#include <iostream>
13//#include <zypp/base/LogTools.h>
14#include <zypp/base/String.h>
15
16#include <zypp/InstanceId.h>
17#include <zypp/ResPool.h>
18
19using std::endl;
20
22namespace zypp
23{
24
25 std::string InstanceId::getIdFor( sat::Solvable slv_r ) const
26 {
27 if ( ! slv_r )
28 return std::string();
29
30 std::string ret( _namespace );
31 if ( ! ret.empty() )
32 ret += ':';
33
34 if ( slv_r.isKind<SrcPackage>() ) // libsolv uses no namespace in SrcPackage ident!
35 {
37 ret += ':';
38 }
39
40 ret += str::form( "%s-%s-%s.%s@%s",
41 slv_r.ident().c_str(),
42 slv_r.edition().version().c_str(),
43 slv_r.edition().release().c_str(),
44 slv_r.arch().c_str(),
45 slv_r.repository().alias().c_str() );
46 return ret;
47 }
48
49 PoolItem InstanceId::findPoolItem( const std::string str_r ) const
50 {
51 // [namespace:]<name>-<version>-<release>.<arch>@<repoalias>
52 std::string::size_type namespaceOff( _namespace.size() );
53
54 if ( namespaceOff )
55 {
56 if ( ! str::hasPrefix( str_r, _namespace ) || str_r[namespaceOff] != ':' )
57 return PoolItem();
58 ++namespaceOff; // for the ':'
59 }
60
61 // check repo
62 std::string::size_type rdelim( str_r.find( "@" ) );
63 if ( rdelim == std::string::npos )
64 return PoolItem();
65
66 Repository repo( sat::Pool::instance().reposFind( str_r.substr( rdelim+1) ) );
67 if ( ! repo )
68 return PoolItem();
69
70 // check n-v-r.a from behind
71 std::string::size_type delim = str_r.rfind( ".", rdelim );
72 if ( delim == std::string::npos )
73 return PoolItem();
74
75 Arch arch( str_r.substr( delim+1, rdelim-delim-1 ) );
76
77 // v-r starts at one but last '-'
78 rdelim = delim;
79 delim = str_r.rfind( "-", rdelim );
80 if ( delim == std::string::npos )
81 return PoolItem();
82
83 if ( delim == rdelim-1 ) // supress an empty release
84 rdelim = delim;
85
86 delim = str_r.rfind( "-", delim-1 );
87 if ( delim == std::string::npos )
88 return PoolItem();
89
90 Edition ed( str_r.substr( delim+1, rdelim-delim-1 ) );
91
92 // eveythig before is name (except the leading "<namespace>:")
93 std::string identstring( str_r.substr( namespaceOff, delim-namespaceOff ) );
94
95 // now lookup in pool..
96 sat::Solvable::SplitIdent ident( (IdString(identstring)) );
97 ResPool pool( ResPool::instance() );
98 for_( it, pool.byIdentBegin( ident.kind(), ident.name() ), pool.byIdentEnd( ident.kind(), ident.name() ) )
99 {
100 sat::Solvable solv( (*it).satSolvable() );
101 if ( solv.repository() == repo && solv.arch() == arch && solv.edition() == ed )
102 {
103 return *it;
104 }
105 }
106 return PoolItem();
107 }
108
109 bool InstanceId::isSystemId( const std::string str_r ) const
110 { return str::hasSuffix( str_r, Repository::systemRepoAlias() ); }
111
113} // namespace zypp
Architecture.
Definition: Arch.h:37
const char * c_str() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: Arch.h:59
Edition represents [epoch:]version[-release]
Definition: Edition.h:61
std::string version() const
Version.
Definition: Edition.cc:94
std::string release() const
Release.
Definition: Edition.cc:110
const char * c_str() const
Definition: IdStringType.h:105
Access to the sat-pools string space.
Definition: IdString.h:43
const char * c_str() const
Conversion to const char *
Definition: IdString.cc:50
std::string getIdFor(sat::Solvable slv_r) const
Solvable to InstanceId string.
Definition: InstanceId.cc:25
bool isSystemId(const std::string str_r) const
Quick test whether the InstanceId string would refer to a system (installed) Solvable.
Definition: InstanceId.cc:109
std::string _namespace
Definition: InstanceId.h:102
PoolItem findPoolItem(const std::string str_r) const
InstanceId string to PoolItem.
Definition: InstanceId.cc:49
Combining sat::Solvable and ResStatus.
Definition: PoolItem.h:51
std::string alias() const
Short unique string to identify a repo.
Definition: Repository.cc:59
static const std::string & systemRepoAlias()
Reserved system repository alias @System .
Definition: Repository.cc:37
static const ResKind srcpackage
Definition: ResKind.h:44
Global ResObject pool.
Definition: ResPool.h:61
static ResPool instance()
Singleton ctor.
Definition: ResPool.cc:37
byIdent_iterator byIdentBegin(const ByIdent &ident_r) const
Definition: ResPool.h:166
byIdent_iterator byIdentEnd(const ByIdent &ident_r) const
Definition: ResPool.h:197
SrcPackage interface.
Definition: SrcPackage.h:30
static Pool instance()
Singleton ctor.
Definition: Pool.h:55
Helper that splits an identifier into kind and name or vice versa.
Definition: Solvable.h:345
A Solvable object within the sat Pool.
Definition: Solvable.h:54
Edition edition() const
The edition (version-release).
Definition: Solvable.cc:337
Arch arch() const
The architecture.
Definition: Solvable.cc:343
bool isKind(const ResKind &kind_r) const
Test whether a Solvable is of a certain ResKind.
Definition: Solvable.cc:302
IdString ident() const
The identifier.
Definition: Solvable.cc:269
Repository repository() const
The Repository this Solvable belongs to.
Definition: Solvable.cc:363
SolvableIdType size_type
Definition: PoolMember.h:126
bool hasSuffix(const C_Str &str_r, const C_Str &suffix_r)
Return whether str_r has suffix suffix_r.
Definition: String.h:1041
bool hasPrefix(const C_Str &str_r, const C_Str &prefix_r)
Return whether str_r has prefix prefix_r.
Definition: String.h:1027
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Definition: String.cc:36
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:28