1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/misc/DefaultLoadSystem.cc
14 #include <zypp/base/LogTools.h>
15 #include <zypp/PathInfo.h>
17 #include <zypp/misc/DefaultLoadSystem.h>
19 #include <zypp/ZYppFactory.h>
20 #include <zypp/zypp_detail/ZYppReadOnlyHack.h>
21 #include <zypp/Target.h>
22 #include <zypp/RepoManager.h>
23 #include <zypp/sat/Pool.h>
27 #undef ZYPP_BASE_LOGGER_LOGGROUP
28 #define ZYPP_BASE_LOGGER_LOGGROUP "zypp::misc"
30 ///////////////////////////////////////////////////////////////////
32 { /////////////////////////////////////////////////////////////////
33 ///////////////////////////////////////////////////////////////////
35 { /////////////////////////////////////////////////////////////////
37 void defaultLoadSystem( const Pathname & sysRoot_r, LoadSystemFlags flags_r )
39 MIL << str::form( "*** Load system at '%s' (%lx)", sysRoot_r.c_str(), (unsigned long)flags_r ) << endl;
41 if ( ! PathInfo( sysRoot_r ).isDir() )
42 ZYPP_THROW( Exception(str::form("sysRoot_r argument needs to be a directory. (%s)", sysRoot_r.c_str())) );
44 if ( ZYppFactory::instance().haveZYpp() )
45 ZYPP_THROW( Exception("ZYpp instance is already created. (Call this method earlier.)") );
47 if ( flags_r.testFlag( LS_READONLY ) )
48 zypp_readonly_hack::IWantIt ();
50 sat::Pool satpool( sat::Pool::instance() );
54 MIL << "*** load target '" << Repository::systemRepoAlias() << "'\t" << endl;
55 getZYpp()->initializeTarget( sysRoot_r );
56 getZYpp()->target()->load();
57 MIL << satpool.systemRepo() << endl;
62 RepoManager repoManager( sysRoot_r );
63 RepoInfoList repos = repoManager.knownRepositories();
64 for_( it, repos.begin(), repos.end() )
66 RepoInfo & nrepo( *it );
68 if ( ! nrepo.enabled() )
71 if ( ! flags_r.testFlag( LS_NOREFRESH ) )
73 if ( repoManager.isCached( nrepo )
74 && ( nrepo.type() == repo::RepoType::RPMPLAINDIR // refreshes always
75 || repoManager.checkIfToRefreshMetadata( nrepo, nrepo.url() ) == RepoManager::REFRESH_NEEDED ) )
77 MIL << str::form( "*** clean cache for repo '%s'\t", nrepo.name().c_str() ) << endl;
78 repoManager.cleanCache( nrepo );
79 MIL << str::form( "*** refresh repo '%s'\t", nrepo.name().c_str() ) << endl;
80 repoManager.refreshMetadata( nrepo );
84 if ( ! repoManager.isCached( nrepo ) )
86 MIL << str::form( "*** build cache for repo '%s'\t", nrepo.name().c_str() ) << endl;
87 repoManager.buildCache( nrepo );
90 MIL << str::form( "*** load repo '%s'\t", nrepo.name().c_str() ) << std::flush;
93 repoManager.loadFromCache( nrepo );
94 MIL << satpool.reposFind( nrepo.alias() ) << endl;
96 catch ( const Exception & exp )
98 ERR << "*** load repo failed: " << exp.asString() + "\n" + exp.historyAsString() << endl;
103 MIL << str::form( "*** Read system at '%s'", sysRoot_r.c_str() ) << endl;
106 /////////////////////////////////////////////////////////////////
108 ///////////////////////////////////////////////////////////////////
109 /////////////////////////////////////////////////////////////////
111 ///////////////////////////////////////////////////////////////////