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"
17 #include "zypp/base/Env.h"
19 #include "zypp/zypp_detail/ZYppImpl.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 ///////////////////////////////////////////////////////////////////
38 ScopedDisableMediaChangeReport::ScopedDisableMediaChangeReport( bool condition_r )
40 static weak_ptr<callback::TempConnect<media::MediaChangeReport> > globalguard;
41 if ( condition_r && ! (_guard = globalguard.lock()) )
43 // aquire a new one....
44 _guard.reset( new callback::TempConnect<media::MediaChangeReport>() );
49 ///////////////////////////////////////////////////////////////////
51 callback::SendReport<JobReport> & JobReport::instance()
53 static callback::SendReport<JobReport> _report;
58 ///////////////////////////////////////////////////////////////////
60 { /////////////////////////////////////////////////////////////////
62 ///////////////////////////////////////////////////////////////////
64 // METHOD NAME : ZYppImpl::ZYppImpl
65 // METHOD TYPE : Constructor
69 , _resolver( new Resolver( ResPool::instance()) )
71 ZConfig::instance().about( MIL );
72 MIL << "Initializing keyring..." << std::endl;
73 _keyring = new KeyRing(tmpPath());
76 ///////////////////////////////////////////////////////////////////
78 // METHOD NAME : ZYppImpl::~ZYppImpl
79 // METHOD TYPE : Destructor
84 //------------------------------------------------------------------------
85 // add/remove resolvables
87 DiskUsageCounter::MountPointSet ZYppImpl::diskUsage()
91 setPartitions( DiskUsageCounter::detectMountPoints() );
93 return _disk_usage->disk_usage(pool());
96 void ZYppImpl::setPartitions(const DiskUsageCounter::MountPointSet &mp)
98 _disk_usage.reset(new DiskUsageCounter());
99 _disk_usage->setMountPoints(mp);
102 DiskUsageCounter::MountPointSet ZYppImpl::getPartitions() const
105 return _disk_usage->getMountPoints();
107 return DiskUsageCounter::detectMountPoints();
110 //------------------------------------------------------------------------
113 Target_Ptr ZYppImpl::target() const
116 ZYPP_THROW(Exception("Target not initialized."));
120 void ZYppImpl::initializeTarget( const Pathname & root, bool doRebuild_r )
122 MIL << "initTarget( " << root << (doRebuild_r?", rebuilddb":"") << ")" << endl;
124 if (_target->root() == root) {
125 MIL << "Repeated call to initializeTarget()" << endl;
132 _target = new Target( root, doRebuild_r );
133 _target->buildCache();
136 void ZYppImpl::finishTarget()
144 //------------------------------------------------------------------------
147 /** \todo Remove workflow from target, lot's of it could be done here,
148 * and target used for transact. */
149 ZYppCommitResult ZYppImpl::commit( const ZYppCommitPolicy & policy_r )
151 if ( getenv("ZYPP_TESTSUITE_FAKE_ARCH") )
153 ZYPP_THROW( Exception("ZYPP_TESTSUITE_FAKE_ARCH set. Commit not allowed and disabled.") );
156 MIL << "Attempt to commit (" << policy_r << ")" << endl;
158 ZYPP_THROW( Exception("Target not initialized.") );
161 env::ScopedSet ea { "ZYPP_IS_RUNNING", str::numstring(getpid()).c_str() };
163 if ( _target->chrooted() )
164 eb = env::ScopedSet( "SYSTEMD_OFFLINE", "1" ); // bsc#1118758 - indicate no systemd if chrooted install
166 ZYppCommitResult res = _target->_pimpl->commit( pool(), policy_r );
168 if (! policy_r.dryRun() )
170 if ( policy_r.syncPoolAfterCommit() )
172 // reload new status from target
173 DBG << "reloading " << sat::Pool::instance().systemRepoAlias() << " repo to pool" << endl;
178 DBG << "unloading " << sat::Pool::instance().systemRepoAlias() << " repo from pool" << endl;
183 MIL << "Commit (" << policy_r << ") returned: "
188 void ZYppImpl::installSrcPackage( const SrcPackage_constPtr & srcPackage_r )
191 ZYPP_THROW( Exception("Target not initialized.") );
192 _target->_pimpl->installSrcPackage( srcPackage_r );
195 ManagedFile ZYppImpl::provideSrcPackage( const SrcPackage_constPtr & srcPackage_r )
198 ZYPP_THROW( Exception("Target not initialized.") );
199 return _target->_pimpl->provideSrcPackage( srcPackage_r );
202 //------------------------------------------------------------------------
205 Pathname ZYppImpl::homePath() const
206 { return _home_path.empty() ? Pathname("/var/lib/zypp") : _home_path; }
208 void ZYppImpl::setHomePath( const Pathname & path )
209 { _home_path = path; }
211 Pathname ZYppImpl::tmpPath() const
212 { return zypp::myTmpDir(); }
214 /******************************************************************
216 ** FUNCTION NAME : operator<<
217 ** FUNCTION TYPE : std::ostream &
219 std::ostream & operator<<( std::ostream & str, const ZYppImpl & obj )
221 return str << "ZYppImpl";
224 /////////////////////////////////////////////////////////////////
225 } // namespace zypp_detail
226 ///////////////////////////////////////////////////////////////////
228 Pathname myTmpDir() // from TmpPath.h
230 static filesystem::TmpDir _tmpdir( TmpPath::defaultLocation(), "zypp." );
231 return _tmpdir.path();
234 /////////////////////////////////////////////////////////////////
236 ///////////////////////////////////////////////////////////////////