enable storage on target
[platform/upstream/libzypp.git] / zypp / zypp_detail / ZYppImpl.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/zypp_detail/ZYppImpl.cc
10  *
11 */
12 #include <iostream>
13 //#include "zypp/base/Logger.h"
14
15 #include "zypp/zypp_detail/ZYppImpl.h"
16
17 using std::endl;
18
19 ///////////////////////////////////////////////////////////////////
20 namespace zypp
21 { /////////////////////////////////////////////////////////////////
22   ///////////////////////////////////////////////////////////////////
23   namespace zypp_detail
24   { /////////////////////////////////////////////////////////////////
25
26     inline Locale defaultTextLocale()
27     {
28       Locale ret( "en" );
29       char * envlist[] = { "LC_ALL", "LC_CTYPE", "LANG", NULL };
30       for ( char ** envvar = envlist; *envvar; ++envvar )
31         {
32           char * envlang = getenv( *envvar );
33           if ( envlang )
34             {
35               std::string envstr( envlang );
36               if ( envstr != "POSIX" && envstr != "C" )
37                 {
38                   Locale lang( envlang );
39                   if ( lang != Locale::noCode )
40                     {
41                       ret = lang;
42                       break;
43                     }
44                 }
45             }
46         }
47       return ret;
48     }
49
50     ///////////////////////////////////////////////////////////////////
51     //
52     //  METHOD NAME : ZYppImpl::ZYppImpl
53     //  METHOD TYPE : Constructor
54     //
55     ZYppImpl::ZYppImpl()
56     : _textLocale( defaultTextLocale() )
57     , _pool()
58     , _sourceFeed( _pool )
59     , _resolver( new Resolver(_pool.accessor()) )
60     {
61       MIL << "defaultTextLocale: '" << _textLocale << "'" << endl;
62     }
63
64     ///////////////////////////////////////////////////////////////////
65     //
66     //  METHOD NAME : ZYppImpl::~ZYppImpl
67     //  METHOD TYPE : Destructor
68     //
69     ZYppImpl::~ZYppImpl()
70     {
71     }
72
73     void ZYppImpl::addResolvables (const ResStore& store, bool installed)
74     {
75         _pool.insert(store.begin(), store.end(), installed);
76     }
77
78     void ZYppImpl::removeResolvables (const ResStore& store)
79     {
80         for (ResStore::iterator it = store.begin(); it != store.end(); it++)
81         {
82             _pool.erase(*it);
83         }
84     }
85
86     Target_Ptr ZYppImpl::target() const
87     {
88       if (! _target)
89         ZYPP_THROW(Exception("Target not initialized."));
90       return _target;
91      }
92
93     void ZYppImpl::initTarget(const Pathname & root, bool commit_only)
94     {
95       if (_target)
96         _target = Target_Ptr();
97       _target = new Target(root);
98       if (!commit_only)
99       {
100         _target->enableStorage(root);
101         addResolvables (_target->resolvables(), true);
102       }
103     }
104
105     void ZYppImpl::finishTarget()
106     {
107 #warning not removing target resolvables for now
108 //      if (_target)
109 //      removeResolvables (_target->resolvables());
110       _target = 0;
111     }
112
113     /** \todo Remove workflow from target, lot's of it could be done here,
114     * and target used for transact. */
115     ZYpp::CommitResult ZYppImpl::commit( int medianr_r )
116     {
117       MIL << "Attempt to commit (medianr " << medianr_r << ")" << endl;
118       if (! _target)
119         ZYPP_THROW( Exception("Target not initialized.") );
120
121       ZYpp::CommitResult res;
122       // must redirect to Target::Impl. This kind of commit should not be
123       // in the Target interface.
124       res._result = _target->commit( pool(), medianr_r,
125                                      res._errors, res._remaining, res._srcremaining );
126
127       MIL << "Commit (medianr " << medianr_r << ") returned: "
128           << res._result
129           << " (errors " << res._errors.size()
130           << ", remaining " << res._remaining.size()
131           << ", srcremaining " << res._srcremaining.size()
132           << ")" << endl;
133       return res;
134     }
135
136     /******************************************************************
137      **
138      ** FUNCTION NAME : operator<<
139      ** FUNCTION TYPE : std::ostream &
140     */
141     std::ostream & operator<<( std::ostream & str, const ZYppImpl & obj )
142     {
143       return str << "ZYppImpl";
144     }
145
146     /////////////////////////////////////////////////////////////////
147   } // namespace zypp_detail
148   ///////////////////////////////////////////////////////////////////
149   /////////////////////////////////////////////////////////////////
150 } // namespace zypp
151 ///////////////////////////////////////////////////////////////////