libzypp
10.5.0
|
00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00013 #include <iostream> 00014 #include "zypp/TmpPath.h" 00015 #include "zypp/base/Logger.h" 00016 #include "zypp/base/String.h" 00017 00018 #include "zypp/zypp_detail/ZYppImpl.h" 00019 #include "zypp/solver/detail/Helper.h" 00020 #include "zypp/target/TargetImpl.h" 00021 #include "zypp/ZYpp.h" 00022 #include "zypp/DiskUsageCounter.h" 00023 #include "zypp/ZConfig.h" 00024 #include "zypp/sat/Pool.h" 00025 #include "zypp/PoolItem.h" 00026 00027 using std::endl; 00028 00030 namespace zypp 00031 { 00032 00033 namespace zypp_detail 00034 { 00035 00037 // 00038 // METHOD NAME : ZYppImpl::ZYppImpl 00039 // METHOD TYPE : Constructor 00040 // 00041 ZYppImpl::ZYppImpl() 00042 : _target(0) 00043 , _resolver( new Resolver( ResPool::instance()) ) 00044 { 00045 ZConfig::instance().about( MIL ); 00046 MIL << "Initializing keyring..." << std::endl; 00047 _keyring = new KeyRing(tmpPath()); 00048 } 00049 00051 // 00052 // METHOD NAME : ZYppImpl::~ZYppImpl 00053 // METHOD TYPE : Destructor 00054 // 00055 ZYppImpl::~ZYppImpl() 00056 {} 00057 00058 //------------------------------------------------------------------------ 00059 // add/remove resolvables 00060 00061 DiskUsageCounter::MountPointSet ZYppImpl::diskUsage() 00062 { 00063 if ( ! _disk_usage ) 00064 { 00065 setPartitions( DiskUsageCounter::detectMountPoints() ); 00066 } 00067 return _disk_usage->disk_usage(pool()); 00068 } 00069 00070 void ZYppImpl::setPartitions(const DiskUsageCounter::MountPointSet &mp) 00071 { 00072 _disk_usage.reset(new DiskUsageCounter()); 00073 _disk_usage->setMountPoints(mp); 00074 } 00075 00076 DiskUsageCounter::MountPointSet ZYppImpl::getPartitions() const 00077 { 00078 if (_disk_usage) 00079 return _disk_usage->getMountPoints(); 00080 else 00081 return DiskUsageCounter::detectMountPoints(); 00082 } 00083 00084 //------------------------------------------------------------------------ 00085 // target 00086 00087 Target_Ptr ZYppImpl::target() const 00088 { 00089 if (! _target) 00090 ZYPP_THROW(Exception("Target not initialized.")); 00091 return _target; 00092 } 00093 00094 void ZYppImpl::initializeTarget( const Pathname & root, bool doRebuild_r ) 00095 { 00096 MIL << "initTarget( " << root << (doRebuild_r?", rebuilddb":"") << ")" << endl; 00097 if (_target) { 00098 if (_target->root() == root) { 00099 MIL << "Repeated call to initializeTarget()" << endl; 00100 return; 00101 } 00102 00103 _target->unload(); 00104 00105 } 00106 _target = new Target( root, doRebuild_r ); 00107 _target->buildCache(); 00108 } 00109 00110 void ZYppImpl::finishTarget() 00111 { 00112 if (_target) 00113 _target->unload(); 00114 00115 _target = 0; 00116 } 00117 00118 //------------------------------------------------------------------------ 00119 // commit 00120 00123 ZYppCommitResult ZYppImpl::commit( const ZYppCommitPolicy & policy_r ) 00124 { 00125 if ( getenv("ZYPP_TESTSUITE_FAKE_ARCH") ) 00126 { 00127 ZYPP_THROW( Exception("ZYPP_TESTSUITE_FAKE_ARCH set. Commit not allowed and disabled.") ); 00128 } 00129 00130 MIL << "Attempt to commit (" << policy_r << ")" << endl; 00131 if (! _target) 00132 ZYPP_THROW( Exception("Target not initialized.") ); 00133 00134 ZYppCommitResult res = _target->_pimpl->commit( pool(), policy_r ); 00135 00136 if (! policy_r.dryRun() ) 00137 { 00138 if ( policy_r.syncPoolAfterCommit() ) 00139 { 00140 // reload new status from target 00141 DBG << "reloading " << sat::Pool::instance().systemRepoAlias() << " repo to pool" << endl; 00142 _target->load(); 00143 } 00144 else 00145 { 00146 DBG << "unloading " << sat::Pool::instance().systemRepoAlias() << " repo from pool" << endl; 00147 _target->unload(); 00148 } 00149 } 00150 00151 MIL << "Commit (" << policy_r << ") returned: " 00152 << res << endl; 00153 return res; 00154 } 00155 00156 void ZYppImpl::installSrcPackage( const SrcPackage_constPtr & srcPackage_r ) 00157 { 00158 if (! _target) 00159 ZYPP_THROW( Exception("Target not initialized.") ); 00160 _target->_pimpl->installSrcPackage( srcPackage_r ); 00161 } 00162 00163 //------------------------------------------------------------------------ 00164 // target store path 00165 00166 Pathname ZYppImpl::homePath() const 00167 { return _home_path.empty() ? Pathname("/var/lib/zypp") : _home_path; } 00168 00169 void ZYppImpl::setHomePath( const Pathname & path ) 00170 { _home_path = path; } 00171 00172 Pathname ZYppImpl::tmpPath() const 00173 { 00174 static TmpDir zypp_tmp_dir( TmpPath::defaultLocation(), "zypp." ); 00175 return zypp_tmp_dir.path(); 00176 } 00177 00178 /****************************************************************** 00179 ** 00180 ** FUNCTION NAME : operator<< 00181 ** FUNCTION TYPE : std::ostream & 00182 */ 00183 std::ostream & operator<<( std::ostream & str, const ZYppImpl & obj ) 00184 { 00185 return str << "ZYppImpl"; 00186 } 00187 00189 } // namespace zypp_detail 00192 } // namespace zypp