1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/zypp_detail/ZYppImpl.cc
13 #include <sys/utsname.h>
15 //#include "zypp/base/Logger.h"
17 #include "zypp/zypp_detail/ZYppImpl.h"
18 #include "zypp/detail/LanguageImpl.h"
19 #include "zypp/detail/ResImplTraits.h"
20 #include "zypp/NVRAD.h"
21 #include "zypp/Language.h"
25 ///////////////////////////////////////////////////////////////////
27 { /////////////////////////////////////////////////////////////////
28 ///////////////////////////////////////////////////////////////////
30 { /////////////////////////////////////////////////////////////////
32 inline Locale defaultTextLocale()
35 char * envlist[] = { "LC_ALL", "LC_CTYPE", "LANG", NULL };
36 for ( char ** envvar = envlist; *envvar; ++envvar )
38 char * envlang = getenv( *envvar );
41 std::string envstr( envlang );
42 if ( envstr != "POSIX" && envstr != "C" )
44 Locale lang( envlang );
45 if ( lang != Locale::noCode )
56 ///////////////////////////////////////////////////////////////////
58 // METHOD NAME : ZYppImpl::ZYppImpl
59 // METHOD TYPE : Constructor
62 : _textLocale( defaultTextLocale() )
64 , _sourceFeed( _pool )
65 , _resolver( new Resolver(_pool.accessor()) )
67 MIL << "defaultTextLocale: '" << _textLocale << "'" << endl;
70 if (uname (&buf) < 0) {
71 ERR << "Can't determine system architecture" << endl;
74 MIL << "System architecture is '" << buf.machine << "'" << endl;
75 _architecture = Arch(buf.machine);
80 ///////////////////////////////////////////////////////////////////
82 // METHOD NAME : ZYppImpl::~ZYppImpl
83 // METHOD TYPE : Destructor
89 //------------------------------------------------------------------------
90 // add/remove resolvables
92 void ZYppImpl::addResolvables (const ResStore& store, bool installed)
94 _pool.insert(store.begin(), store.end(), installed);
97 void ZYppImpl::removeResolvables (const ResStore& store)
99 for (ResStore::iterator it = store.begin(); it != store.end(); ++it)
105 void ZYppImpl::removeInstalledResolvables ()
107 for (ResPool::const_iterator it = pool().begin(); it != pool().end(); ++it)
109 if (it->status().isInstalled())
114 //------------------------------------------------------------------------
117 Target_Ptr ZYppImpl::target() const
120 ZYPP_THROW(Exception("Target not initialized."));
124 void ZYppImpl::initTarget(const Pathname & root, bool commit_only)
127 if (_target->root() == root) {
128 MIL << "Repeated call to initTarget()" << endl;
131 removeInstalledResolvables( );
133 _target = new Target( root );
136 _target->enableStorage( root );
137 addResolvables( _target->resolvables(), true );
141 void ZYppImpl::finishTarget()
144 removeInstalledResolvables();
148 //------------------------------------------------------------------------
151 /** \todo Remove workflow from target, lot's of it could be done here,
152 * and target used for transact. */
153 ZYpp::CommitResult ZYppImpl::commit( int medianr_r )
155 MIL << "Attempt to commit (medianr " << medianr_r << ")" << endl;
157 ZYPP_THROW( Exception("Target not initialized.") );
159 ZYpp::CommitResult res;
161 // must redirect to Target::Impl. This kind of commit should not be
162 // in the Target interface.
164 res._result = _target->commit( pool(), medianr_r,
165 res._errors, res._remaining, res._srcremaining );
167 // reload new status from target
169 removeInstalledResolvables();
170 addResolvables( _target->resolvables(), true );
172 MIL << "Commit (medianr " << medianr_r << ") returned: "
174 << " (errors " << res._errors.size()
175 << ", remaining " << res._remaining.size()
176 << ", srcremaining " << res._srcremaining.size()
183 //------------------------------------------------------------------------
187 void ZYppImpl::setPossibleLocales( const LocaleSet & locales_r )
189 removeResolvables( _possible_locales );
190 _possible_locales.clear();
192 for (LocaleSet::const_iterator it = locales_r.begin(); it != locales_r.end(); ++it) {
193 NVRA nvra( it->code(), Edition(), Arch_noarch );
194 NVRAD ldata( nvra, Dependencies() );
195 detail::ResImplTraits<detail::LanguageImpl>::Ptr limpl = new detail::LanguageImpl();
196 Language::Ptr language = detail::makeResolvableFromImpl( ldata, limpl );
197 _possible_locales.insert( language );
199 addResolvables( _possible_locales, false );
203 ZYppImpl::LocaleSet ZYppImpl::getPossibleLocales() const
206 for (ResStore::const_iterator it = _possible_locales.begin(); it != _possible_locales.end(); ++it) {
207 lset.insert( Locale( (*it)->name() ) );
212 //------------------------------------------------------------------------
215 void ZYppImpl::setArchitecture( const Arch & arch )
217 _architecture = arch;
218 if (_resolver) _resolver->setArchitecture( arch );
221 //------------------------------------------------------------------------
224 Pathname ZYppImpl::homePath() const
225 { return _home_path.empty() ? Pathname("/var/lib/zypp") : _home_path; }
227 void ZYppImpl::setHomePath( const Pathname & path )
228 { _home_path = path; }
230 /******************************************************************
232 ** FUNCTION NAME : operator<<
233 ** FUNCTION TYPE : std::ostream &
235 std::ostream & operator<<( std::ostream & str, const ZYppImpl & obj )
237 return str << "ZYppImpl";
240 /////////////////////////////////////////////////////////////////
241 } // namespace zypp_detail
242 ///////////////////////////////////////////////////////////////////
243 /////////////////////////////////////////////////////////////////
245 ///////////////////////////////////////////////////////////////////