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/target/TargetImpl.h"
20 #include "zypp/ZYpp.h"
21 #include "zypp/DiskUsageCounter.h"
22 #include "zypp/ZConfig.h"
23 #include "zypp/sat/Pool.h"
24 #include "zypp/PoolItem.h"
26 #include "zypp/ZYppCallbacks.h" // JobReport::instance
30 ///////////////////////////////////////////////////////////////////
32 { /////////////////////////////////////////////////////////////////
34 ///////////////////////////////////////////////////////////////////
37 ScopedDisableMediaChangeReport::ScopedDisableMediaChangeReport( bool condition_r )
39 static weak_ptr<callback::TempConnect<media::MediaChangeReport> > globalguard;
40 if ( condition_r && ! (_guard = globalguard.lock()) )
42 // aquire a new one....
43 _guard.reset( new callback::TempConnect<media::MediaChangeReport>() );
48 ///////////////////////////////////////////////////////////////////
50 callback::SendReport<JobReport> & JobReport::instance()
52 static callback::SendReport<JobReport> _report;
57 ///////////////////////////////////////////////////////////////////
59 { /////////////////////////////////////////////////////////////////
61 ///////////////////////////////////////////////////////////////////
63 // METHOD NAME : ZYppImpl::ZYppImpl
64 // METHOD TYPE : Constructor
68 , _resolver( new Resolver( ResPool::instance()) )
70 ZConfig::instance().about( MIL );
71 MIL << "Initializing keyring..." << std::endl;
72 _keyring = new KeyRing(tmpPath());
75 ///////////////////////////////////////////////////////////////////
77 // METHOD NAME : ZYppImpl::~ZYppImpl
78 // METHOD TYPE : Destructor
83 //------------------------------------------------------------------------
84 // add/remove resolvables
86 DiskUsageCounter::MountPointSet ZYppImpl::diskUsage()
90 setPartitions( DiskUsageCounter::detectMountPoints() );
92 return _disk_usage->disk_usage(pool());
95 void ZYppImpl::setPartitions(const DiskUsageCounter::MountPointSet &mp)
97 _disk_usage.reset(new DiskUsageCounter());
98 _disk_usage->setMountPoints(mp);
101 DiskUsageCounter::MountPointSet ZYppImpl::getPartitions() const
104 return _disk_usage->getMountPoints();
106 return DiskUsageCounter::detectMountPoints();
109 //------------------------------------------------------------------------
112 Target_Ptr ZYppImpl::target() const
115 ZYPP_THROW(Exception("Target not initialized."));
119 void ZYppImpl::initializeTarget( const Pathname & root, bool doRebuild_r )
121 MIL << "initTarget( " << root << (doRebuild_r?", rebuilddb":"") << ")" << endl;
123 if (_target->root() == root) {
124 MIL << "Repeated call to initializeTarget()" << endl;
131 _target = new Target( root, doRebuild_r );
132 _target->buildCache();
135 void ZYppImpl::finishTarget()
143 //------------------------------------------------------------------------
146 /** \todo Remove workflow from target, lot's of it could be done here,
147 * and target used for transact. */
148 ZYppCommitResult ZYppImpl::commit( const ZYppCommitPolicy & policy_r )
150 setenv( "ZYPP_IS_RUNNING", str::numstring(getpid()).c_str(), 1 );
152 if ( getenv("ZYPP_TESTSUITE_FAKE_ARCH") )
154 ZYPP_THROW( Exception("ZYPP_TESTSUITE_FAKE_ARCH set. Commit not allowed and disabled.") );
157 MIL << "Attempt to commit (" << policy_r << ")" << endl;
159 ZYPP_THROW( Exception("Target not initialized.") );
161 ZYppCommitResult res = _target->_pimpl->commit( pool(), policy_r );
163 if (! policy_r.dryRun() )
165 if ( policy_r.syncPoolAfterCommit() )
167 // reload new status from target
168 DBG << "reloading " << sat::Pool::instance().systemRepoAlias() << " repo to pool" << endl;
173 DBG << "unloading " << sat::Pool::instance().systemRepoAlias() << " repo from pool" << endl;
178 MIL << "Commit (" << policy_r << ") returned: "
183 void ZYppImpl::installSrcPackage( const SrcPackage_constPtr & srcPackage_r )
186 ZYPP_THROW( Exception("Target not initialized.") );
187 _target->_pimpl->installSrcPackage( srcPackage_r );
190 ManagedFile ZYppImpl::provideSrcPackage( const SrcPackage_constPtr & srcPackage_r )
193 ZYPP_THROW( Exception("Target not initialized.") );
194 return _target->_pimpl->provideSrcPackage( srcPackage_r );
197 //------------------------------------------------------------------------
200 Pathname ZYppImpl::homePath() const
201 { return _home_path.empty() ? Pathname("/var/lib/zypp") : _home_path; }
203 void ZYppImpl::setHomePath( const Pathname & path )
204 { _home_path = path; }
206 Pathname ZYppImpl::tmpPath() const
208 static TmpDir zypp_tmp_dir( TmpPath::defaultLocation(), "zypp." );
209 return zypp_tmp_dir.path();
212 /******************************************************************
214 ** FUNCTION NAME : operator<<
215 ** FUNCTION TYPE : std::ostream &
217 std::ostream & operator<<( std::ostream & str, const ZYppImpl & obj )
219 return str << "ZYppImpl";
222 /////////////////////////////////////////////////////////////////
223 } // namespace zypp_detail
224 ///////////////////////////////////////////////////////////////////
225 /////////////////////////////////////////////////////////////////
227 ///////////////////////////////////////////////////////////////////