ZYppImpl.cc

Go to the documentation of this file.
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       setenv( "ZYPP_IS_RUNNING", str::numstring(getpid()).c_str(), 1 );
00126 
00127       if ( getenv("ZYPP_TESTSUITE_FAKE_ARCH") )
00128       {
00129         ZYPP_THROW( Exception("ZYPP_TESTSUITE_FAKE_ARCH set. Commit not allowed and disabled.") );
00130       }
00131 
00132       MIL << "Attempt to commit (" << policy_r << ")" << endl;
00133       if (! _target)
00134         ZYPP_THROW( Exception("Target not initialized.") );
00135 
00136       ZYppCommitResult res = _target->_pimpl->commit( pool(), policy_r );
00137 
00138       if (! policy_r.dryRun() )
00139       {
00140         if ( policy_r.syncPoolAfterCommit() )
00141           {
00142             // reload new status from target
00143             DBG << "reloading " << sat::Pool::instance().systemRepoAlias() << " repo to pool" << endl;
00144             _target->load();
00145           }
00146         else
00147           {
00148             DBG << "unloading " << sat::Pool::instance().systemRepoAlias() << " repo from pool" << endl;
00149             _target->unload();
00150           }
00151       }
00152 
00153       MIL << "Commit (" << policy_r << ") returned: "
00154           << res << endl;
00155       return res;
00156     }
00157 
00158     void ZYppImpl::installSrcPackage( const SrcPackage_constPtr & srcPackage_r )
00159     {
00160       if (! _target)
00161         ZYPP_THROW( Exception("Target not initialized.") );
00162       _target->_pimpl->installSrcPackage( srcPackage_r );
00163     }
00164 
00165     //------------------------------------------------------------------------
00166     // target store path
00167 
00168     Pathname ZYppImpl::homePath() const
00169     { return _home_path.empty() ? Pathname("/var/lib/zypp") : _home_path; }
00170 
00171     void ZYppImpl::setHomePath( const Pathname & path )
00172     { _home_path = path; }
00173 
00174     Pathname ZYppImpl::tmpPath() const
00175     {
00176       static TmpDir zypp_tmp_dir( TmpPath::defaultLocation(), "zypp." );
00177       return zypp_tmp_dir.path();
00178     }
00179 
00180     /******************************************************************
00181      **
00182      ** FUNCTION NAME : operator<<
00183      ** FUNCTION TYPE : std::ostream &
00184     */
00185     std::ostream & operator<<( std::ostream & str, const ZYppImpl & obj )
00186     {
00187       return str << "ZYppImpl";
00188     }
00189 
00191   } // namespace zypp_detail
00194 } // namespace zypp

Generated on Tue May 5 14:43:20 2015 for libzypp by  doxygen 1.5.6