1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/zypp_detail/ZYppImpl.cc
14 #include "zypp/TmpPath.h"
15 #include "zypp/base/Logger.h"
16 #include "zypp/base/String.h"
18 #include "zypp/zypp_detail/ZYppImpl.h"
19 #include "zypp/solver/detail/Helper.h"
20 #include "zypp/target/TargetImpl.h"
21 #include "zypp/ZYpp.h"
22 #include "zypp/DiskUsageCounter.h"
23 #include "zypp/ZConfig.h"
24 #include "zypp/sat/Pool.h"
25 #include "zypp/PoolItem.h"
29 ///////////////////////////////////////////////////////////////////
31 { /////////////////////////////////////////////////////////////////
32 ///////////////////////////////////////////////////////////////////
34 { /////////////////////////////////////////////////////////////////
36 ///////////////////////////////////////////////////////////////////
38 // METHOD NAME : ZYppImpl::ZYppImpl
39 // METHOD TYPE : Constructor
43 , _resolver( new Resolver( ResPool::instance()) )
45 ZConfig::instance().about( MIL );
46 MIL << "Initializing keyring..." << std::endl;
47 _keyring = new KeyRing(tmpPath());
50 ///////////////////////////////////////////////////////////////////
52 // METHOD NAME : ZYppImpl::~ZYppImpl
53 // METHOD TYPE : Destructor
58 //------------------------------------------------------------------------
59 // add/remove resolvables
61 DiskUsageCounter::MountPointSet ZYppImpl::diskUsage()
65 setPartitions( DiskUsageCounter::detectMountPoints() );
67 return _disk_usage->disk_usage(pool());
70 void ZYppImpl::setPartitions(const DiskUsageCounter::MountPointSet &mp)
72 _disk_usage.reset(new DiskUsageCounter());
73 _disk_usage->setMountPoints(mp);
76 DiskUsageCounter::MountPointSet ZYppImpl::getPartitions() const
79 return _disk_usage->getMountPoints();
81 return DiskUsageCounter::detectMountPoints();
84 //------------------------------------------------------------------------
87 Target_Ptr ZYppImpl::target() const
90 ZYPP_THROW(Exception("Target not initialized."));
94 void ZYppImpl::initializeTarget( const Pathname & root, bool doRebuild_r )
96 MIL << "initTarget( " << root << (doRebuild_r?", rebuilddb":"") << ")" << endl;
98 if (_target->root() == root) {
99 MIL << "Repeated call to initializeTarget()" << endl;
106 _target = new Target( root, doRebuild_r );
107 _target->buildCache();
110 void ZYppImpl::finishTarget()
118 //------------------------------------------------------------------------
121 /** \todo Remove workflow from target, lot's of it could be done here,
122 * and target used for transact. */
123 ZYppCommitResult ZYppImpl::commit( const ZYppCommitPolicy & policy_r )
125 setenv( "ZYPP_IS_RUNNING", str::numstring(getpid()).c_str(), 1 );
127 if ( getenv("ZYPP_TESTSUITE_FAKE_ARCH") )
129 ZYPP_THROW( Exception("ZYPP_TESTSUITE_FAKE_ARCH set. Commit not allowed and disabled.") );
132 MIL << "Attempt to commit (" << policy_r << ")" << endl;
134 ZYPP_THROW( Exception("Target not initialized.") );
136 ZYppCommitResult res = _target->_pimpl->commit( pool(), policy_r );
138 if (! policy_r.dryRun() )
140 if ( policy_r.syncPoolAfterCommit() )
142 // reload new status from target
143 DBG << "reloading " << sat::Pool::instance().systemRepoAlias() << " repo to pool" << endl;
148 DBG << "unloading " << sat::Pool::instance().systemRepoAlias() << " repo from pool" << endl;
153 MIL << "Commit (" << policy_r << ") returned: "
158 void ZYppImpl::installSrcPackage( const SrcPackage_constPtr & srcPackage_r )
161 ZYPP_THROW( Exception("Target not initialized.") );
162 _target->_pimpl->installSrcPackage( srcPackage_r );
165 //------------------------------------------------------------------------
168 Pathname ZYppImpl::homePath() const
169 { return _home_path.empty() ? Pathname("/var/lib/zypp") : _home_path; }
171 void ZYppImpl::setHomePath( const Pathname & path )
172 { _home_path = path; }
174 Pathname ZYppImpl::tmpPath() const
176 static TmpDir zypp_tmp_dir( TmpPath::defaultLocation(), "zypp." );
177 return zypp_tmp_dir.path();
180 /******************************************************************
182 ** FUNCTION NAME : operator<<
183 ** FUNCTION TYPE : std::ostream &
185 std::ostream & operator<<( std::ostream & str, const ZYppImpl & obj )
187 return str << "ZYppImpl";
190 /////////////////////////////////////////////////////////////////
191 } // namespace zypp_detail
192 ///////////////////////////////////////////////////////////////////
193 /////////////////////////////////////////////////////////////////
195 ///////////////////////////////////////////////////////////////////