1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/sat/Repository.cc
14 #include "zypp/base/Logger.h"
15 #include "zypp/base/Gettext.h"
16 #include "zypp/base/Exception.h"
18 #include "zypp/AutoDispose.h"
19 #include "zypp/Pathname.h"
21 #include "zypp/sat/detail/PoolImpl.h"
22 #include "zypp/Repository.h"
23 #include "zypp/sat/Pool.h"
27 ///////////////////////////////////////////////////////////////////
29 { /////////////////////////////////////////////////////////////////
30 ///////////////////////////////////////////////////////////////////
32 const Repository Repository::noRepository;
34 /////////////////////////////////////////////////////////////////
36 ::_Repo * Repository::get() const
37 { return myPool().getRepo( _id ); }
39 #define NO_REPOSITORY_RETURN( VAL ) \
40 ::_Repo * _repo( get() ); \
41 if ( ! _repo ) return VAL
43 #define NO_REPOSITORY_THROW( VAL ) \
44 ::_Repo * _repo( get() ); \
45 if ( ! _repo ) ZYPP_THROW( VAL )
47 bool Repository::isSystemRepo() const
49 NO_REPOSITORY_RETURN( false );
50 return( sat::Pool::systemRepoName() == _repo->name );
53 std::string Repository::name() const
55 NO_REPOSITORY_RETURN( std::string() );
61 bool Repository::solvablesEmpty() const
63 NO_REPOSITORY_RETURN( true );
64 return _repo->nsolvables;
67 Repository::size_type Repository::solvablesSize() const
69 NO_REPOSITORY_RETURN( 0 );
70 return _repo->nsolvables;
73 Repository::SolvableIterator Repository::solvablesBegin() const
75 NO_REPOSITORY_RETURN( make_filter_iterator( detail::ByRepository( *this ),
76 sat::detail::SolvableIterator(),
77 sat::detail::SolvableIterator() ) );
78 return make_filter_iterator( detail::ByRepository( *this ),
79 sat::detail::SolvableIterator(_repo->start),
80 sat::detail::SolvableIterator(_repo->end) );
83 Repository::SolvableIterator Repository::solvablesEnd() const
85 NO_REPOSITORY_RETURN( make_filter_iterator( detail::ByRepository( *this ),
86 sat::detail::SolvableIterator(),
87 sat::detail::SolvableIterator() ) );
88 return make_filter_iterator(detail::ByRepository( *this ),
89 sat::detail::SolvableIterator(_repo->end),
90 sat::detail::SolvableIterator(_repo->end) );
93 RepoInfo Repository::info() const
95 NO_REPOSITORY_RETURN( RepoInfo() );
96 return myPool().repoInfo( _repo );
99 void Repository::setInfo( const RepoInfo & info_r )
101 NO_REPOSITORY_THROW( Exception( _("Can't set RepoInfo for norepo.") ) );
102 if ( info_r.alias() != name() )
104 ZYPP_THROW( Exception( str::form( _("RepoInfo alias (%s) does not match repository name (%s)"),
105 info_r.alias().c_str(), name().c_str() ) ) );
107 myPool().setRepoInfo( _repo, info_r );
109 // satsolver priority is based on '<', while yum's repoinfo
110 // uses 1(highest)->99(lowest). Thus we use -info_r.priority.
111 _repo->priority = -info_r.priority();
114 void Repository::clearInfo()
116 NO_REPOSITORY_RETURN();
117 myPool().setRepoInfo( _repo, RepoInfo() );
120 void Repository::eraseFromPool()
122 NO_REPOSITORY_RETURN();
123 myPool()._deleteRepo( _repo );
124 _id = sat::detail::noRepoId;
127 #warning NEED POOL MANIP EXEPTIONS
128 void Repository::addSolv( const Pathname & file_r )
130 NO_REPOSITORY_THROW( Exception( _("Can't add solvables to norepo.") ) );
132 AutoDispose<FILE*> file( ::fopen( file_r.c_str(), "r" ), ::fclose );
136 ZYPP_THROW( Exception( _("Can't open solv-file: ")+file_r.asString() ) );
139 if ( myPool()._addSolv( _repo, file, isSystemRepo() ) != 0 )
141 ZYPP_THROW( Exception( _("Error reading solv-file: ")+file_r.asString() ) );
145 sat::detail::SolvableIdType Repository::addSolvables( unsigned count_r )
147 NO_REPOSITORY_THROW( Exception( _("Can't add solvables to norepo.") ) );
148 return myPool()._addSolvables( _repo, count_r );
151 /******************************************************************
153 ** FUNCTION NAME : operator<<
154 ** FUNCTION TYPE : std::ostream &
156 std::ostream & operator<<( std::ostream & str, const Repository & obj )
159 return str << "sat::repo()";
161 return str << "sat::repo(" << obj.name() << ")"
163 << "prio " << obj.get()->priority
164 << ", size " << obj.solvablesSize()
169 /////////////////////////////////////////////////////////////////
171 ///////////////////////////////////////////////////////////////////