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 Repository Repository::nextInPool() const
129 NO_REPOSITORY_RETURN( noRepository );
130 for_( it, sat::Pool::instance().reposBegin(), sat::Pool::instance().reposEnd() )
134 if ( ++it != _for_end )
142 #warning NEED POOL MANIP EXEPTIONS
143 void Repository::addSolv( const Pathname & file_r )
145 NO_REPOSITORY_THROW( Exception( "Can't add solvables to norepo." ) );
147 AutoDispose<FILE*> file( ::fopen( file_r.c_str(), "r" ), ::fclose );
151 ZYPP_THROW( Exception( "Can't open solv-file: "+file_r.asString() ));
154 if ( myPool()._addSolv( _repo, file, isSystemRepo() ) != 0 )
156 ZYPP_THROW( Exception( "Error reading solv-file: "+file_r.asString() ));
160 sat::detail::SolvableIdType Repository::addSolvables( unsigned count_r )
162 NO_REPOSITORY_THROW( Exception( "Can't add solvables to norepo.") );
163 return myPool()._addSolvables( _repo, count_r );
166 /******************************************************************
168 ** FUNCTION NAME : operator<<
169 ** FUNCTION TYPE : std::ostream &
171 std::ostream & operator<<( std::ostream & str, const Repository & obj )
174 return str << "noRepository";
176 return str << "sat::repo(" << obj.name() << ")"
178 << "prio " << obj.get()->priority
179 << ", size " << obj.solvablesSize()
184 /////////////////////////////////////////////////////////////////
186 ///////////////////////////////////////////////////////////////////