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/NameKindProxy.h"
24 #include "zypp/ZConfig.h"
25 #include "zypp/sat/Pool.h"
26 #include "zypp/PoolItem.h"
30 ///////////////////////////////////////////////////////////////////
32 { /////////////////////////////////////////////////////////////////
33 ///////////////////////////////////////////////////////////////////
35 { /////////////////////////////////////////////////////////////////
37 ///////////////////////////////////////////////////////////////////
39 // METHOD NAME : ZYppImpl::ZYppImpl
40 // METHOD TYPE : Constructor
44 , _resolver( new Resolver( ResPool::instance()) )
46 MIL << "libzypp: " << VERSION << " built " << __DATE__ << " " << __TIME__ << endl;
47 MIL << "defaultTextLocale: '" << ZConfig::instance().textLocale() << "'" << endl;
48 MIL << "System architecture is '" << ZConfig::instance().systemArchitecture() << "'" << endl;
49 MIL << "Initializing keyring..." << std::endl;
50 _keyring = new KeyRing(tmpPath());
53 ///////////////////////////////////////////////////////////////////
55 // METHOD NAME : ZYppImpl::~ZYppImpl
56 // METHOD TYPE : Destructor
61 //------------------------------------------------------------------------
62 // add/remove resolvables
64 DiskUsageCounter::MountPointSet ZYppImpl::diskUsage()
68 setPartitions( DiskUsageCounter::detectMountPoints() );
70 return _disk_usage->disk_usage(pool());
73 void ZYppImpl::setPartitions(const DiskUsageCounter::MountPointSet &mp)
75 _disk_usage.reset(new DiskUsageCounter());
76 _disk_usage->setMountPoints(mp);
79 DiskUsageCounter::MountPointSet ZYppImpl::getPartitions() const
82 return _disk_usage->getMountPoints();
84 return DiskUsageCounter::detectMountPoints();
87 //------------------------------------------------------------------------
90 Target_Ptr ZYppImpl::target() const
93 ZYPP_THROW(Exception("Target not initialized."));
97 void ZYppImpl::initializeTarget( const Pathname & root, bool doRebuild_r )
99 MIL << "initTarget( " << root << (doRebuild_r?", rebuilddb":"") << ")" << endl;
101 if (_target->root() == root) {
102 MIL << "Repeated call to initializeTarget()" << endl;
109 _target = new Target( root, doRebuild_r );
110 _target->buildCache();
113 void ZYppImpl::finishTarget()
121 //------------------------------------------------------------------------
124 /** \todo Remove workflow from target, lot's of it could be done here,
125 * and target used for transact. */
126 ZYppCommitResult ZYppImpl::commit( const ZYppCommitPolicy & policy_r )
128 if ( getenv("ZYPP_TESTSUITE_FAKE_ARCH") )
130 ZYPP_THROW( Exception("ZYPP_TESTSUITE_FAKE_ARCH set. Commit not allowed and disabled.") );
133 MIL << "Attempt to commit (" << policy_r << ")" << endl;
135 ZYPP_THROW( Exception("Target not initialized.") );
137 ZYppCommitResult res = _target->_pimpl->commit( pool(), policy_r );
139 if (! policy_r.dryRun() ) {
141 DBG << "unloading " << sat::Pool::instance().systemRepoAlias() << " repo from pool" << endl;
145 if ( policy_r.syncPoolAfterCommit() )
147 // reload new status from target
148 DBG << "reloading " << sat::Pool::instance().systemRepoAlias() << " repo to 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 ///////////////////////////////////////////////////////////////////