commit 903cf1a0aaf30e053baf6d7093e412ad93d3e8f0
Author: Michael Andres
Date: Wed Jan 28 14:13:27 2009 +0100
Add test for isSystemSoftwareIdentityInstanceId and protect tests against NULL pointer arg.
---
src/SUSE_zypp.cc | 26 ++++++++++++++++----------
src/SUSE_zypp.h | 4 +++-
2 files changed, 19 insertions(+), 11 deletions(-)
diff --git a/src/SUSE_zypp.cc b/src/SUSE_zypp.cc
index dc04869..bd8d12b 100644
--- a/src/SUSE_zypp.cc
+++ b/src/SUSE_zypp.cc
@@ -128,42 +128,43 @@ namespace cmpizypp
slv.repository().alias().c_str() ) );
}
- PoolItem ZyppAC::findSoftwareIdentityInstanceId( const std::string & id_r ) const
+ PoolItem ZyppAC::findSoftwareIdentityInstanceId( const C_Str & id_r ) const
{
// SoftwareIdentity::InstanceId = SUSE:<name>-<version>-<release>.<arch>@<repoalias>
+ const std::string id( id_r );
- if ( ! str::hasPrefix( id_r, "SUSE:" ) )
+ if ( ! str::hasPrefix( id, "SUSE:" ) )
return PoolItem();
// check repo
- std::string::size_type rdelim( id_r.find( "@" ) );
+ std::string::size_type rdelim( id.find( "@" ) );
if ( rdelim == std::string::npos )
return PoolItem();
- Repository repo( sat::Pool::instance().reposFind( id_r.substr( rdelim+1) ) );
+ Repository repo( sat::Pool::instance().reposFind( id.substr( rdelim+1) ) );
if ( ! repo )
return PoolItem();
// check n-v-r.a from behind
- std::string::size_type delim = id_r.rfind( ".", rdelim );
+ std::string::size_type delim = id.rfind( ".", rdelim );
if ( delim == std::string::npos )
return PoolItem();
- Arch arch( id_r.substr( delim+1, rdelim-delim-1 ) );
+ Arch arch( id.substr( delim+1, rdelim-delim-1 ) );
// v-r starts at one but last '-'
rdelim = delim;
- delim = id_r.rfind( "-", rdelim );
+ delim = id.rfind( "-", rdelim );
if ( delim == std::string::npos )
return PoolItem();
- delim = id_r.rfind( "-", delim-1 );
+ delim = id.rfind( "-", delim-1 );
if ( delim == std::string::npos )
return PoolItem();
- Edition ed( id_r.substr( delim+1, rdelim-delim-1 ) );
+ Edition ed( id.substr( delim+1, rdelim-delim-1 ) );
// eveythig before is name (except the leading "SUSE:")
- std::string identstring( id_r.substr( 5, delim-5 ) );
+ std::string identstring( id.substr( 5, delim-5 ) );
DBG << "Lookup:" << endl;
DBG << identstring << endl;
@@ -185,4 +186,9 @@ namespace cmpizypp
return PoolItem();
}
+ bool ZyppAC::isSystemSoftwareIdentityInstanceId( const C_Str & id_r )
+ {
+ return str::hasSuffix( id_r, Repository::systemRepoAlias() );
+ }
+
}
diff --git a/src/SUSE_zypp.h b/src/SUSE_zypp.h
index 6f84e4b..69812bc 100644
--- a/src/SUSE_zypp.h
+++ b/src/SUSE_zypp.h
@@ -32,9 +32,11 @@ namespace cmpizypp
std::string SoftwareIdentityInstanceId( const zypp::sat::Solvable & slv ) const;
std::string SoftwareIdentityInstanceId( const zypp::PoolItem & pi ) const
{ return SoftwareIdentityInstanceId( pi.satSolvable() ); }
+
/** \see \ref SoftwareIdentityInstanceId */
- zypp::PoolItem findSoftwareIdentityInstanceId( const std::string & id_r ) const;
+ zypp::PoolItem findSoftwareIdentityInstanceId( const zypp::C_Str & id_r ) const;
+ static bool isSystemSoftwareIdentityInstanceId( const zypp::C_Str & id_r );
};
}
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org