libzypp 17.37.10

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
19 using std::endl;
20
22 namespace 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 {
36 ret += ResKind::srcpackage.c_str();
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
InstanceId.h
ResPool.h
zypp::Arch
Architecture.
Definition Arch.h:37
zypp::Arch::c_str
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
zypp::Edition
Edition represents [epoch:]version[-release]
Definition Edition.h:61
zypp::Edition::version
std::string version() const
Version.
Definition Edition.cc:94
zypp::Edition::release
std::string release() const
Release.
Definition Edition.cc:110
zypp::IdString
Access to the sat-pools string space.
Definition IdString.h:44
zypp::IdString::c_str
const char * c_str() const
Conversion to const char *
Definition IdString.cc:50
zypp::InstanceId::getIdFor
std::string getIdFor(sat::Solvable slv_r) const
Solvable to InstanceId string.
Definition InstanceId.cc:25
zypp::InstanceId::findPoolItem
PoolItem findPoolItem(const std::string &str_r) const
InstanceId string to PoolItem.
Definition InstanceId.cc:49
zypp::InstanceId::isSystemId
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
zypp::InstanceId::_namespace
std::string _namespace
Definition InstanceId.h:103
zypp::PoolItem
Combining sat::Solvable and ResStatus.
Definition PoolItem.h:51
zypp::Repository
Definition Repository.h:40
zypp::Repository::alias
std::string alias() const
Short unique string to identify a repo.
Definition Repository.cc:60
zypp::Repository::systemRepoAlias
static const std::string & systemRepoAlias()
Reserved system repository alias @System .
Definition Repository.cc:38
zypp::ResKind::srcpackage
static const ResKind srcpackage
Definition ResKind.h:44
zypp::ResPool
Global ResObject pool.
Definition ResPool.h:62
zypp::ResPool::instance
static ResPool instance()
Singleton ctor.
Definition ResPool.cc:38
zypp::SrcPackage
SrcPackage interface.
Definition SrcPackage.h:30
zypp::sat::Pool::instance
static Pool instance()
Singleton ctor.
Definition Pool.h:55
zypp::sat::Solvable::SplitIdent
Helper that splits an identifier into kind and name or vice versa.
Definition Solvable.h:362
zypp::sat::Solvable::SplitIdent::name
IdString name() const
Definition Solvable.h:373
zypp::sat::Solvable::SplitIdent::kind
ResKind kind() const
Definition Solvable.h:372
zypp::sat::Solvable
A Solvable object within the sat Pool.
Definition Solvable.h:54
zypp::sat::Solvable::edition
Edition edition() const
The edition (version-release).
Definition Solvable.cc:338
zypp::sat::Solvable::arch
Arch arch() const
The architecture.
Definition Solvable.cc:344
zypp::sat::Solvable::isKind
bool isKind(const ResKind &kind_r) const
Test whether a Solvable is of a certain ResKind.
Definition Solvable.cc:303
zypp::sat::Solvable::ident
IdString ident() const
The identifier.
Definition Solvable.cc:270
zypp::sat::Solvable::repository
Repository repository() const
The Repository this Solvable belongs to.
Definition Solvable.cc:364
zypp::pool
Definition ByIdent.h:24
zypp::repo
Definition DeltaCandidates.cc:30
zypp::str::hasSuffix
bool hasSuffix(const C_Str &str_r, const C_Str &suffix_r)
Return whether str_r has suffix suffix_r.
Definition String.h:1111
zypp::str::hasPrefix
bool hasPrefix(const C_Str &str_r, const C_Str &prefix_r)
Return whether str_r has prefix prefix_r.
Definition String.h:1097
zypp::str::form
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Definition String.cc:39
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition Application.cc:20
for_
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition Easy.h:27
String.h