1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/InstanceId.cc
13 //#include "zypp/base/LogTools.h"
14 #include "zypp/base/String.h"
16 #include "zypp/InstanceId.h"
17 #include "zypp/ResPool.h"
21 ///////////////////////////////////////////////////////////////////
23 { /////////////////////////////////////////////////////////////////
25 std::string InstanceId::getIdFor( sat::Solvable slv_r ) const
30 std::string ret( _namespace );
34 if ( slv_r.isKind<SrcPackage>() ) // satsolver uses no namespace in SrcPackage ident!
36 ret += ResKind::srcpackage.c_str();
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(),
45 slv_r.repository().alias().c_str() );
49 PoolItem InstanceId::findPoolItem( const std::string str_r ) const
51 // [namespace:]<name>-<version>-<release>.<arch>@<repoalias>
52 std::string::size_type namespaceOff( _namespace.size() );
56 if ( ! str::hasPrefix( str_r, _namespace ) || str_r[namespaceOff] != ':' )
58 ++namespaceOff; // for the ':'
62 std::string::size_type rdelim( str_r.find( "@" ) );
63 if ( rdelim == std::string::npos )
66 Repository repo( sat::Pool::instance().reposFind( str_r.substr( rdelim+1) ) );
70 // check n-v-r.a from behind
71 std::string::size_type delim = str_r.rfind( ".", rdelim );
72 if ( delim == std::string::npos )
75 Arch arch( str_r.substr( delim+1, rdelim-delim-1 ) );
77 // v-r starts at one but last '-'
79 delim = str_r.rfind( "-", rdelim );
80 if ( delim == std::string::npos )
83 if ( delim == rdelim-1 ) // supress an empty release
86 delim = str_r.rfind( "-", delim-1 );
87 if ( delim == std::string::npos )
90 Edition ed( str_r.substr( delim+1, rdelim-delim-1 ) );
92 // eveythig before is name (except the leading "<namespace>:")
93 std::string identstring( str_r.substr( namespaceOff, delim-namespaceOff ) );
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() ) )
100 sat::Solvable solv( (*it).satSolvable() );
101 if ( solv.repository() == repo && solv.arch() == arch && solv.edition() == ed )
109 bool InstanceId::isSystemId( const std::string str_r ) const
110 { return str::hasSuffix( str_r, Repository::systemRepoAlias() ); }
112 /////////////////////////////////////////////////////////////////
114 ///////////////////////////////////////////////////////////////////