~thopiekar/zypper/libzypp-manual-import

« back to all changes in this revision

Viewing changes to zypp/InstanceId.cc

  • Committer: Thomas-Karl Pietrowski
  • Date: 2014-01-29 22:44:28 UTC
  • Revision ID: thopiekar@googlemail.com-20140129224428-gpcqnsdakby362n8
firstĀ import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*---------------------------------------------------------------------\
 
2
|                          ____ _   __ __ ___                          |
 
3
|                         |__  / \ / / . \ . \                         |
 
4
|                           / / \ V /|  _/  _/                         |
 
5
|                          / /__ | | | | | |                           |
 
6
|                         /_____||_| |_| |_|                           |
 
7
|                                                                      |
 
8
\---------------------------------------------------------------------*/
 
9
/** \file       zypp/InstanceId.cc
 
10
 *
 
11
*/
 
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
 
 
21
///////////////////////////////////////////////////////////////////
 
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
 
 
112
  /////////////////////////////////////////////////////////////////
 
113
} // namespace zypp
 
114
///////////////////////////////////////////////////////////////////