1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/target/TargetImpl.cc
13 #include "zypp/base/Logger.h"
14 #include "zypp/base/Exception.h"
16 #include "zypp/target/TargetImpl.h"
17 #include "zypp/target/TargetCallbackReceiver.h"
19 #include "zypp/solver/detail/Types.h"
20 #include "zypp/solver/detail/InstallOrder.h"
23 using zypp::solver::detail::InstallOrder;
25 ///////////////////////////////////////////////////////////////////
27 { /////////////////////////////////////////////////////////////////
28 ///////////////////////////////////////////////////////////////////
30 { /////////////////////////////////////////////////////////////////
32 IMPL_PTR_TYPE(TargetImpl);
34 TargetImpl_Ptr TargetImpl::_nullimpl;
36 /** Null implementation */
37 TargetImpl_Ptr TargetImpl::nullimpl()
40 _nullimpl = new TargetImpl;
45 ///////////////////////////////////////////////////////////////////
47 // METHOD NAME : TargetImpl::TargetImpl
50 TargetImpl::TargetImpl(const Pathname & root_r)
53 _rpm.initDatabase(_root);
54 MIL << "Initialized target on " << _root << endl;
57 ///////////////////////////////////////////////////////////////////
59 // METHOD NAME : TargetImpl::~TargetImpl
62 TargetImpl::~TargetImpl()
65 MIL << "Targets closed" << endl;
68 const ResStore & TargetImpl::resolvables()
72 std::list<Package::Ptr> packages = _rpm.getPackages();
73 for (std::list<Package::Ptr>::const_iterator it = packages.begin();
79 // TODO objects from the XML store
83 void TargetImpl::commit(ResPool pool_r)
85 PoolItemList to_uninstall;
86 PoolItemList to_install;
87 PoolItemList installed;
88 for (ResPool::const_iterator it = pool_r.begin();
89 it != pool_r.end(); it++)
91 if (it->status().isToBeInstalled())
93 to_install.push_back(*it);
95 else if (it->status().isToBeUninstalled())
97 to_uninstall.push_back(*it);
99 else if (it->status().isInstalled())
101 installed.push_back(*it);
104 // first uninstall what is to be uninstalled
105 #warning FIXME this orderding doesn't honor the dependencies for removals
106 commit(to_uninstall);
107 // now install what is to be installed
108 InstallOrder order(pool_r, to_install, installed);
110 const PoolItemList & installorder(order.getTopSorted());
111 commit(installorder);
114 void TargetImpl::commit(const PoolItemList & items_r)
116 for (PoolItemList::const_iterator it = items_r.begin();
117 it != items_r.end(); it++)
119 if (isKind<Package>(it->resolvable()))
121 Package::constPtr p = dynamic_pointer_cast<const Package>(it->resolvable());
122 if (it->status().isToBeInstalled())
124 #warning Exception handling
125 // create a progress report proxy
126 RpmInstallPackageReceiver progress(it->resolvable());
131 rpm().installPackage(p->getPlainRpm(),
132 p->installOnly() ? rpm::RpmDb::RPMINST_NOUPGRADE : 0);
134 catch (Exception & excpt_r) {
135 ZYPP_CAUGHT(excpt_r);
137 WAR << "Install failed, retrying with --nodeps" << endl;
139 rpm().installPackage(p->getPlainRpm(),
140 p->installOnly() ? rpm::RpmDb::RPMINST_NOUPGRADE : rpm::RpmDb::RPMINST_NODEPS);
142 catch (Exception & excpt_r) {
143 ZYPP_CAUGHT(excpt_r);
144 WAR << "Install failed again, retrying with --force --nodeps" << endl;
147 rpm().installPackage(p->getPlainRpm(),
148 p->installOnly() ? rpm::RpmDb::RPMINST_NOUPGRADE : (rpm::RpmDb::RPMINST_NODEPS|rpm::RpmDb::RPMINST_FORCE));
150 catch (Exception & excpt_r) {
151 progress.disconnect();
152 ZYPP_RETHROW(excpt_r);
157 progress.disconnect();
163 rpm().removePackage(p);
165 catch (Exception & excpt_r) {
166 ZYPP_CAUGHT(excpt_r);
167 WAR << "Remove failed, retrying with --nodeps" << endl;
168 rpm().removePackage(p, rpm::RpmDb::RPMINST_NODEPS);
171 MIL << "Successful, resetting transact for " << *it << endl;
172 it->status().setNoTransact(ResStatus::USER);
174 #warning FIXME other resolvables
179 rpm::RpmDb & TargetImpl::rpm()
182 bool TargetImpl::providesFile (const std::string & name_str, const std::string & path_str) const
183 { return _rpm.hasFile(path_str); }
185 /////////////////////////////////////////////////////////////////
186 } // namespace target
187 ///////////////////////////////////////////////////////////////////
188 /////////////////////////////////////////////////////////////////
190 ///////////////////////////////////////////////////////////////////