libzypp
10.5.0
|
00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00012 //#include <iostream> 00013 //#include "zypp/base/LogTools.h" 00014 #include "zypp/base/String.h" 00015 00016 #include "zypp/InstanceId.h" 00017 #include "zypp/ResPool.h" 00018 00019 using std::endl; 00020 00022 namespace zypp 00023 { 00024 00025 std::string InstanceId::getIdFor( sat::Solvable slv_r ) const 00026 { 00027 if ( ! slv_r ) 00028 return std::string(); 00029 00030 std::string ret( _namespace ); 00031 if ( ! ret.empty() ) 00032 ret += ':'; 00033 00034 if ( slv_r.isKind<SrcPackage>() ) // libsolv uses no namespace in SrcPackage ident! 00035 { 00036 ret += ResKind::srcpackage.c_str(); 00037 ret += ':'; 00038 } 00039 00040 ret += str::form( "%s-%s-%s.%s@%s", 00041 slv_r.ident().c_str(), 00042 slv_r.edition().version().c_str(), 00043 slv_r.edition().release().c_str(), 00044 slv_r.arch().c_str(), 00045 slv_r.repository().alias().c_str() ); 00046 return ret; 00047 } 00048 00049 PoolItem InstanceId::findPoolItem( const std::string str_r ) const 00050 { 00051 // [namespace:]<name>-<version>-<release>.<arch>@<repoalias> 00052 std::string::size_type namespaceOff( _namespace.size() ); 00053 00054 if ( namespaceOff ) 00055 { 00056 if ( ! str::hasPrefix( str_r, _namespace ) || str_r[namespaceOff] != ':' ) 00057 return PoolItem(); 00058 ++namespaceOff; // for the ':' 00059 } 00060 00061 // check repo 00062 std::string::size_type rdelim( str_r.find( "@" ) ); 00063 if ( rdelim == std::string::npos ) 00064 return PoolItem(); 00065 00066 Repository repo( sat::Pool::instance().reposFind( str_r.substr( rdelim+1) ) ); 00067 if ( ! repo ) 00068 return PoolItem(); 00069 00070 // check n-v-r.a from behind 00071 std::string::size_type delim = str_r.rfind( ".", rdelim ); 00072 if ( delim == std::string::npos ) 00073 return PoolItem(); 00074 00075 Arch arch( str_r.substr( delim+1, rdelim-delim-1 ) ); 00076 00077 // v-r starts at one but last '-' 00078 rdelim = delim; 00079 delim = str_r.rfind( "-", rdelim ); 00080 if ( delim == std::string::npos ) 00081 return PoolItem(); 00082 00083 if ( delim == rdelim-1 ) // supress an empty release 00084 rdelim = delim; 00085 00086 delim = str_r.rfind( "-", delim-1 ); 00087 if ( delim == std::string::npos ) 00088 return PoolItem(); 00089 00090 Edition ed( str_r.substr( delim+1, rdelim-delim-1 ) ); 00091 00092 // eveythig before is name (except the leading "<namespace>:") 00093 std::string identstring( str_r.substr( namespaceOff, delim-namespaceOff ) ); 00094 00095 // now lookup in pool.. 00096 sat::Solvable::SplitIdent ident( (IdString(identstring)) ); 00097 ResPool pool( ResPool::instance() ); 00098 for_( it, pool.byIdentBegin( ident.kind(), ident.name() ), pool.byIdentEnd( ident.kind(), ident.name() ) ) 00099 { 00100 sat::Solvable solv( (*it).satSolvable() ); 00101 if ( solv.repository() == repo && solv.arch() == arch && solv.edition() == ed ) 00102 { 00103 return *it; 00104 } 00105 } 00106 return PoolItem(); 00107 } 00108 00109 bool InstanceId::isSystemId( const std::string str_r ) const 00110 { return str::hasSuffix( str_r, Repository::systemRepoAlias() ); } 00111 00113 } // namespace zypp