libzypp  10.5.0
DefaultLoadSystem.cc
Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #include <iostream>
00013 
00014 #include "zypp/base/LogTools.h"
00015 #include "zypp/PathInfo.h"
00016 
00017 #include "zypp/misc/DefaultLoadSystem.h"
00018 
00019 #include "zypp/ZYppFactory.h"
00020 #include "zypp/zypp_detail/ZYppReadOnlyHack.h"
00021 #include "zypp/Target.h"
00022 #include "zypp/RepoManager.h"
00023 #include "zypp/sat/Pool.h"
00024 
00025 using std::endl;
00026 
00027 #undef ZYPP_BASE_LOGGER_LOGGROUP
00028 #define ZYPP_BASE_LOGGER_LOGGROUP "zypp::misc"
00029 
00031 namespace zypp
00032 { 
00033 
00034   namespace misc
00035   { 
00036 
00037     void defaultLoadSystem( const Pathname & sysRoot_r, LoadSystemFlags flags_r )
00038     {
00039       MIL << str::form( "*** Load system at '%s' (%lx)", sysRoot_r.c_str(), (unsigned long)flags_r ) << endl;
00040 
00041       if ( ! PathInfo( sysRoot_r ).isDir() )
00042         ZYPP_THROW( Exception(str::form("sysRoot_r argument needs to be a directory. (%s)", sysRoot_r.c_str())) );
00043 
00044       if ( ZYppFactory::instance().haveZYpp() )
00045         ZYPP_THROW( Exception("ZYpp instance is already created. (Call this method earlier.)") );
00046 
00047       if ( flags_r.testFlag( LS_READONLY ) )
00048         zypp_readonly_hack::IWantIt ();
00049 
00050       sat::Pool satpool( sat::Pool::instance() );
00051 
00052       if ( 1 )
00053       {
00054         MIL << "*** load target '" << Repository::systemRepoAlias() << "'\t" << endl;
00055         getZYpp()->initializeTarget( sysRoot_r );
00056         getZYpp()->target()->load();
00057         MIL << satpool.systemRepo() << endl;
00058       }
00059 
00060       if ( 1 )
00061       {
00062         RepoManager repoManager( sysRoot_r );
00063         RepoInfoList repos = repoManager.knownRepositories();
00064         for_( it, repos.begin(), repos.end() )
00065         {
00066           RepoInfo & nrepo( *it );
00067 
00068           if ( ! nrepo.enabled() )
00069             continue;
00070 
00071           if ( ! flags_r.testFlag( LS_NOREFRESH ) )
00072           {
00073             if ( repoManager.isCached( nrepo )
00074                && ( nrepo.type() == repo::RepoType::RPMPLAINDIR // refreshes always
00075                   || repoManager.checkIfToRefreshMetadata( nrepo, nrepo.url() ) == RepoManager::REFRESH_NEEDED ) )
00076             {
00077               MIL << str::form( "*** clean cache for repo '%s'\t", nrepo.name().c_str() ) << endl;
00078               repoManager.cleanCache( nrepo );
00079               MIL << str::form( "*** refresh repo '%s'\t", nrepo.name().c_str() ) << endl;
00080               repoManager.refreshMetadata( nrepo );
00081             }
00082           }
00083 
00084           if ( ! repoManager.isCached( nrepo ) )
00085           {
00086             MIL << str::form( "*** build cache for repo '%s'\t", nrepo.name().c_str() ) << endl;
00087             repoManager.buildCache( nrepo );
00088           }
00089 
00090           MIL << str::form( "*** load repo '%s'\t", nrepo.name().c_str() ) << std::flush;
00091           try
00092           {
00093             repoManager.loadFromCache( nrepo );
00094             MIL << satpool.reposFind( nrepo.alias() ) << endl;
00095           }
00096           catch ( const Exception & exp )
00097           {
00098             ERR << "*** load repo failed: " << exp.asString() + "\n" + exp.historyAsString() << endl;
00099             ZYPP_RETHROW ( exp );
00100           }
00101         }
00102       }
00103       MIL << str::form( "*** Read system at '%s'", sysRoot_r.c_str() ) << endl;
00104     }
00105 
00107   } // namespace misc
00110 } // namespace zypp