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"
21 ///////////////////////////////////////////////////////////////////
23 { /////////////////////////////////////////////////////////////////
24 ///////////////////////////////////////////////////////////////////
26 { /////////////////////////////////////////////////////////////////
28 inline Locale defaultTextLocale()
31 char * envlist[] = { "LC_ALL", "LC_CTYPE", "LANG", NULL };
32 for ( char ** envvar = envlist; *envvar; ++envvar )
34 char * envlang = getenv( *envvar );
37 std::string envstr( envlang );
38 if ( envstr != "POSIX" && envstr != "C" )
40 Locale lang( envlang );
41 if ( lang != Locale::noCode )
52 ///////////////////////////////////////////////////////////////////
54 // METHOD NAME : ZYppImpl::ZYppImpl
55 // METHOD TYPE : Constructor
58 : _textLocale( defaultTextLocale() )
60 , _sourceFeed( _pool )
61 , _resolver( new Resolver(_pool.accessor()) )
63 MIL << "defaultTextLocale: '" << _textLocale << "'" << endl;
66 if (uname (&buf) < 0) {
67 ERR << "Can't determine system architecture" << endl;
70 MIL << "System architecture is '" << buf.machine << "'" << endl;
71 _architecture = Arch(buf.machine);
76 ///////////////////////////////////////////////////////////////////
78 // METHOD NAME : ZYppImpl::~ZYppImpl
79 // METHOD TYPE : Destructor
85 void ZYppImpl::addResolvables (const ResStore& store, bool installed)
87 _pool.insert(store.begin(), store.end(), installed);
90 void ZYppImpl::removeResolvables (const ResStore& store)
92 for (ResStore::iterator it = store.begin(); it != store.end(); it++)
98 Target_Ptr ZYppImpl::target() const
101 ZYPP_THROW(Exception("Target not initialized."));
105 void ZYppImpl::initTarget(const Pathname & root, bool commit_only)
108 WAR << "Repeated call to initTarget()" << endl;
112 _target = new Target(root);
115 _target->enableStorage(root);
116 addResolvables (_target->resolvables(), true);
120 void ZYppImpl::finishTarget()
122 #warning not removing target resolvables for now
124 // removeResolvables (_target->resolvables());
128 /** \todo Remove workflow from target, lot's of it could be done here,
129 * and target used for transact. */
130 ZYpp::CommitResult ZYppImpl::commit( int medianr_r )
132 MIL << "Attempt to commit (medianr " << medianr_r << ")" << endl;
134 ZYPP_THROW( Exception("Target not initialized.") );
136 ZYpp::CommitResult res;
137 // must redirect to Target::Impl. This kind of commit should not be
138 // in the Target interface.
139 res._result = _target->commit( pool(), medianr_r,
140 res._errors, res._remaining, res._srcremaining );
142 MIL << "Commit (medianr " << medianr_r << ") returned: "
144 << " (errors " << res._errors.size()
145 << ", remaining " << res._remaining.size()
146 << ", srcremaining " << res._srcremaining.size()
152 void ZYppImpl::setArchitecture( const Arch & arch )
154 _architecture = arch;
155 if (_resolver) _resolver->setArchitecture( arch );
158 Pathname ZYppImpl::homePath() const
159 { return _home_path.empty() ? Pathname("/var/lib/zypp") : _home_path; }
160 void ZYppImpl::setHomePath( const Pathname & path )
161 { _home_path = path; }
163 /******************************************************************
165 ** FUNCTION NAME : operator<<
166 ** FUNCTION TYPE : std::ostream &
168 std::ostream & operator<<( std::ostream & str, const ZYppImpl & obj )
170 return str << "ZYppImpl";
173 /////////////////////////////////////////////////////////////////
174 } // namespace zypp_detail
175 ///////////////////////////////////////////////////////////////////
176 /////////////////////////////////////////////////////////////////
178 ///////////////////////////////////////////////////////////////////