libzypp 9.41.1
|
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 00034 namespace media 00035 { 00036 ScopedDisableMediaChangeReport::ScopedDisableMediaChangeReport( bool condition_r ) 00037 { 00038 static weak_ptr<callback::TempConnect<media::MediaChangeReport> > globalguard; 00039 if ( condition_r && ! (_guard = globalguard.lock()) ) 00040 { 00041 // aquire a new one.... 00042 _guard.reset( new callback::TempConnect<media::MediaChangeReport>() ); 00043 globalguard = _guard; 00044 } 00045 } 00046 } // namespace media 00048 00050 namespace zypp_detail 00051 { 00052 00054 // 00055 // METHOD NAME : ZYppImpl::ZYppImpl 00056 // METHOD TYPE : Constructor 00057 // 00058 ZYppImpl::ZYppImpl() 00059 : _target(0) 00060 , _resolver( new Resolver( ResPool::instance()) ) 00061 { 00062 ZConfig::instance().about( MIL ); 00063 MIL << "Initializing keyring..." << std::endl; 00064 _keyring = new KeyRing(tmpPath()); 00065 } 00066 00068 // 00069 // METHOD NAME : ZYppImpl::~ZYppImpl 00070 // METHOD TYPE : Destructor 00071 // 00072 ZYppImpl::~ZYppImpl() 00073 {} 00074 00075 //------------------------------------------------------------------------ 00076 // add/remove resolvables 00077 00078 DiskUsageCounter::MountPointSet ZYppImpl::diskUsage() 00079 { 00080 if ( ! _disk_usage ) 00081 { 00082 setPartitions( DiskUsageCounter::detectMountPoints() ); 00083 } 00084 return _disk_usage->disk_usage(pool()); 00085 } 00086 00087 void ZYppImpl::setPartitions(const DiskUsageCounter::MountPointSet &mp) 00088 { 00089 _disk_usage.reset(new DiskUsageCounter()); 00090 _disk_usage->setMountPoints(mp); 00091 } 00092 00093 DiskUsageCounter::MountPointSet ZYppImpl::getPartitions() const 00094 { 00095 if (_disk_usage) 00096 return _disk_usage->getMountPoints(); 00097 else 00098 return DiskUsageCounter::detectMountPoints(); 00099 } 00100 00101 //------------------------------------------------------------------------ 00102 // target 00103 00104 Target_Ptr ZYppImpl::target() const 00105 { 00106 if (! _target) 00107 ZYPP_THROW(Exception("Target not initialized.")); 00108 return _target; 00109 } 00110 00111 void ZYppImpl::initializeTarget( const Pathname & root, bool doRebuild_r ) 00112 { 00113 MIL << "initTarget( " << root << (doRebuild_r?", rebuilddb":"") << ")" << endl; 00114 if (_target) { 00115 if (_target->root() == root) { 00116 MIL << "Repeated call to initializeTarget()" << endl; 00117 return; 00118 } 00119 00120 _target->unload(); 00121 00122 } 00123 _target = new Target( root, doRebuild_r ); 00124 _target->buildCache(); 00125 } 00126 00127 void ZYppImpl::finishTarget() 00128 { 00129 if (_target) 00130 _target->unload(); 00131 00132 _target = 0; 00133 } 00134 00135 //------------------------------------------------------------------------ 00136 // commit 00137 00140 ZYppCommitResult ZYppImpl::commit( const ZYppCommitPolicy & policy_r ) 00141 { 00142 setenv( "ZYPP_IS_RUNNING", str::numstring(getpid()).c_str(), 1 ); 00143 00144 if ( getenv("ZYPP_TESTSUITE_FAKE_ARCH") ) 00145 { 00146 ZYPP_THROW( Exception("ZYPP_TESTSUITE_FAKE_ARCH set. Commit not allowed and disabled.") ); 00147 } 00148 00149 MIL << "Attempt to commit (" << policy_r << ")" << endl; 00150 if (! _target) 00151 ZYPP_THROW( Exception("Target not initialized.") ); 00152 00153 ZYppCommitResult res = _target->_pimpl->commit( pool(), policy_r ); 00154 00155 if (! policy_r.dryRun() ) 00156 { 00157 if ( policy_r.syncPoolAfterCommit() ) 00158 { 00159 // reload new status from target 00160 DBG << "reloading " << sat::Pool::instance().systemRepoAlias() << " repo to pool" << endl; 00161 _target->load(); 00162 } 00163 else 00164 { 00165 DBG << "unloading " << sat::Pool::instance().systemRepoAlias() << " repo from pool" << endl; 00166 _target->unload(); 00167 } 00168 } 00169 00170 MIL << "Commit (" << policy_r << ") returned: " 00171 << res << endl; 00172 return res; 00173 } 00174 00175 void ZYppImpl::installSrcPackage( const SrcPackage_constPtr & srcPackage_r ) 00176 { 00177 if (! _target) 00178 ZYPP_THROW( Exception("Target not initialized.") ); 00179 _target->_pimpl->installSrcPackage( srcPackage_r ); 00180 } 00181 00182 //------------------------------------------------------------------------ 00183 // target store path 00184 00185 Pathname ZYppImpl::homePath() const 00186 { return _home_path.empty() ? Pathname("/var/lib/zypp") : _home_path; } 00187 00188 void ZYppImpl::setHomePath( const Pathname & path ) 00189 { _home_path = path; } 00190 00191 Pathname ZYppImpl::tmpPath() const 00192 { 00193 static TmpDir zypp_tmp_dir( TmpPath::defaultLocation(), "zypp." ); 00194 return zypp_tmp_dir.path(); 00195 } 00196 00197 /****************************************************************** 00198 ** 00199 ** FUNCTION NAME : operator<< 00200 ** FUNCTION TYPE : std::ostream & 00201 */ 00202 std::ostream & operator<<( std::ostream & str, const ZYppImpl & obj ) 00203 { 00204 return str << "ZYppImpl"; 00205 } 00206 00208 } // namespace zypp_detail 00211 } // namespace zypp