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"
27 #include "zypp/ZYppCallbacks.h" // JobReport::instance
31 ///////////////////////////////////////////////////////////////////
33 { /////////////////////////////////////////////////////////////////
35 callback::SendReport<JobReport> & JobReport::instance()
37 static callback::SendReport<JobReport> _report;
41 ///////////////////////////////////////////////////////////////////
43 { /////////////////////////////////////////////////////////////////
45 ///////////////////////////////////////////////////////////////////
47 // METHOD NAME : ZYppImpl::ZYppImpl
48 // METHOD TYPE : Constructor
52 , _resolver( new Resolver( ResPool::instance()) )
54 ZConfig::instance().about( MIL );
55 MIL << "Initializing keyring..." << std::endl;
56 _keyring = new KeyRing(tmpPath());
59 ///////////////////////////////////////////////////////////////////
61 // METHOD NAME : ZYppImpl::~ZYppImpl
62 // METHOD TYPE : Destructor
67 //------------------------------------------------------------------------
68 // add/remove resolvables
70 DiskUsageCounter::MountPointSet ZYppImpl::diskUsage()
74 setPartitions( DiskUsageCounter::detectMountPoints() );
76 return _disk_usage->disk_usage(pool());
79 void ZYppImpl::setPartitions(const DiskUsageCounter::MountPointSet &mp)
81 _disk_usage.reset(new DiskUsageCounter());
82 _disk_usage->setMountPoints(mp);
85 DiskUsageCounter::MountPointSet ZYppImpl::getPartitions() const
88 return _disk_usage->getMountPoints();
90 return DiskUsageCounter::detectMountPoints();
93 //------------------------------------------------------------------------
96 Target_Ptr ZYppImpl::target() const
99 ZYPP_THROW(Exception("Target not initialized."));
103 void ZYppImpl::initializeTarget( const Pathname & root, bool doRebuild_r )
105 MIL << "initTarget( " << root << (doRebuild_r?", rebuilddb":"") << ")" << endl;
107 if (_target->root() == root) {
108 MIL << "Repeated call to initializeTarget()" << endl;
115 _target = new Target( root, doRebuild_r );
116 _target->buildCache();
119 void ZYppImpl::finishTarget()
127 //------------------------------------------------------------------------
130 /** \todo Remove workflow from target, lot's of it could be done here,
131 * and target used for transact. */
132 ZYppCommitResult ZYppImpl::commit( const ZYppCommitPolicy & policy_r )
134 setenv( "ZYPP_IS_RUNNING", str::numstring(getpid()).c_str(), 1 );
136 if ( getenv("ZYPP_TESTSUITE_FAKE_ARCH") )
138 ZYPP_THROW( Exception("ZYPP_TESTSUITE_FAKE_ARCH set. Commit not allowed and disabled.") );
141 MIL << "Attempt to commit (" << policy_r << ")" << endl;
143 ZYPP_THROW( Exception("Target not initialized.") );
145 ZYppCommitResult res = _target->_pimpl->commit( pool(), policy_r );
147 if (! policy_r.dryRun() )
149 if ( policy_r.syncPoolAfterCommit() )
151 // reload new status from target
152 DBG << "reloading " << sat::Pool::instance().systemRepoAlias() << " repo to pool" << endl;
157 DBG << "unloading " << sat::Pool::instance().systemRepoAlias() << " repo from pool" << endl;
162 MIL << "Commit (" << policy_r << ") returned: "
167 void ZYppImpl::installSrcPackage( const SrcPackage_constPtr & srcPackage_r )
170 ZYPP_THROW( Exception("Target not initialized.") );
171 _target->_pimpl->installSrcPackage( srcPackage_r );
174 ManagedFile ZYppImpl::provideSrcPackage( const SrcPackage_constPtr & srcPackage_r )
177 ZYPP_THROW( Exception("Target not initialized.") );
178 return _target->_pimpl->provideSrcPackage( srcPackage_r );
181 //------------------------------------------------------------------------
184 Pathname ZYppImpl::homePath() const
185 { return _home_path.empty() ? Pathname("/var/lib/zypp") : _home_path; }
187 void ZYppImpl::setHomePath( const Pathname & path )
188 { _home_path = path; }
190 Pathname ZYppImpl::tmpPath() const
192 static TmpDir zypp_tmp_dir( TmpPath::defaultLocation(), "zypp." );
193 return zypp_tmp_dir.path();
196 /******************************************************************
198 ** FUNCTION NAME : operator<<
199 ** FUNCTION TYPE : std::ostream &
201 std::ostream & operator<<( std::ostream & str, const ZYppImpl & obj )
203 return str << "ZYppImpl";
206 /////////////////////////////////////////////////////////////////
207 } // namespace zypp_detail
208 ///////////////////////////////////////////////////////////////////
209 /////////////////////////////////////////////////////////////////
211 ///////////////////////////////////////////////////////////////////