libzypp  17.23.0
DefaultLoadSystem.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #include <iostream>
13 
14 #include "zypp/base/LogTools.h"
15 #include "zypp/PathInfo.h"
16 
18 
19 #include "zypp/ZYppFactory.h"
21 #include "zypp/Target.h"
22 #include "zypp/RepoManager.h"
23 #include "zypp/sat/Pool.h"
24 
25 using std::endl;
26 
27 #undef ZYPP_BASE_LOGGER_LOGGROUP
28 #define ZYPP_BASE_LOGGER_LOGGROUP "zypp::misc"
29 
31 namespace zypp
32 {
33  namespace misc
35  {
36 
37  void defaultLoadSystem( const Pathname & sysRoot_r, LoadSystemFlags flags_r )
38  {
39  MIL << str::form( "*** Load system at '%s' (%lx)", sysRoot_r.c_str(), (unsigned long)flags_r ) << endl;
40 
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())) );
43 
45  ZYPP_THROW( Exception("ZYpp instance is already created. (Call this method earlier.)") );
46 
47  if ( flags_r.testFlag( LS_READONLY ) )
49 
50  sat::Pool satpool( sat::Pool::instance() );
51 
52  if ( 1 )
53  {
54  MIL << "*** load target '" << Repository::systemRepoAlias() << "'\t" << endl;
55  getZYpp()->initializeTarget( sysRoot_r );
56  getZYpp()->target()->load();
57  MIL << satpool.systemRepo() << endl;
58  }
59 
60  if ( 1 )
61  {
62  RepoManager repoManager( sysRoot_r );
63  RepoInfoList repos = repoManager.knownRepositories();
64  for_( it, repos.begin(), repos.end() )
65  {
66  RepoInfo & nrepo( *it );
67 
68  if ( ! nrepo.enabled() )
69  continue;
70 
71  if ( ! flags_r.testFlag( LS_NOREFRESH ) )
72  {
73  if ( repoManager.isCached( nrepo )
74  && ( nrepo.type() == repo::RepoType::RPMPLAINDIR // refreshes always
75  || repoManager.checkIfToRefreshMetadata( nrepo, nrepo.url() ) == RepoManager::REFRESH_NEEDED ) )
76  {
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 );
81  }
82  }
83 
84  if ( ! repoManager.isCached( nrepo ) )
85  {
86  MIL << str::form( "*** build cache for repo '%s'\t", nrepo.name().c_str() ) << endl;
87  repoManager.buildCache( nrepo );
88  }
89 
90  MIL << str::form( "*** load repo '%s'\t", nrepo.name().c_str() ) << std::flush;
91  try
92  {
93  repoManager.loadFromCache( nrepo );
94  MIL << satpool.reposFind( nrepo.alias() ) << endl;
95  }
96  catch ( const Exception & exp )
97  {
98  ERR << "*** load repo failed: " << exp.asString() + "\n" + exp.historyAsString() << endl;
99  ZYPP_RETHROW ( exp );
100  }
101  }
102  }
103  MIL << str::form( "*** Read system at '%s'", sysRoot_r.c_str() ) << endl;
104  }
105 
107  } // namespace misc
110 } // namespace zypp
zypp::sat::Pool::instance
static Pool instance()
Singleton ctor.
Definition: Pool.h:55
zypp::RepoManager::buildCache
void buildCache(const RepoInfo &info, CacheBuildPolicy policy=BuildIfNeeded, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Refresh local cache.
Definition: RepoManager.cc:2580
PathInfo.h
zypp::RepoManager::refreshMetadata
void refreshMetadata(const RepoInfo &info, RawMetadataRefreshPolicy policy=RefreshIfNeeded, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Refresh local raw cache.
Definition: RepoManager.cc:2568
repos
RepoInfoList repos
Definition: RepoManager.cc:277
ZYppReadOnlyHack.h
ZYppFactory.h
zypp::Exception
Base class for Exception.
Definition: Exception.h:145
zypp::RepoManager::isCached
bool isCached(const RepoInfo &info) const
Whether a repository exists in cache.
Definition: RepoManager.cc:2586
zypp::RepoInfo
What is known about a repository.
Definition: RepoInfo.h:71
MIL
#define MIL
Definition: Logger.h:79
zypp::repo::RepoInfoBase::enabled
bool enabled() const
If enabled is false, then this repository must be ignored as if does not exists, except when checking...
Definition: RepoInfoBase.cc:104
zypp::misc::defaultLoadSystem
void defaultLoadSystem(const Pathname &sysRoot_r, LoadSystemFlags flags_r)
Create the ZYpp instance and load target and enabled repositories.
Definition: DefaultLoadSystem.cc:37
ZYPP_THROW
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:392
zypp::filesystem::PathInfo::isDir
bool isDir() const
Definition: PathInfo.h:290
zypp::RepoManager::REFRESH_NEEDED
refresh is needed
Definition: RepoManager.h:197
Target.h
zypp::RepoManager::loadFromCache
void loadFromCache(const RepoInfo &info, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Load resolvables into the pool.
Definition: RepoManager.cc:2589
zypp::zypp_readonly_hack::IWantIt
void IWantIt() ZYPP_DEPRECATED
Definition: ZYppFactory.cc:73
zypp::sat::Pool
Global sat-pool.
Definition: Pool.h:46
LogTools.h
zypp::Exception::asString
std::string asString() const
Error message provided by dumpOn as string.
Definition: Exception.cc:75
zypp::Repository::systemRepoAlias
static const std::string & systemRepoAlias()
Reserved system repository alias @System .
Definition: Repository.cc:37
zypp::filesystem::PathInfo
Wrapper class for ::stat/::lstat.
Definition: PathInfo.h:220
zypp::misc::LS_READONLY
// Create readonly ZYpp instance.
Definition: DefaultLoadSystem.h:35
zypp::filesystem::Pathname::c_str
const char * c_str() const
String representation.
Definition: Pathname.h:110
zypp::repo::RepoInfoBase::alias
std::string alias() const
unique identifier for this source.
Definition: RepoInfoBase.cc:111
zypp::str::form
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Definition: String.cc:35
zypp::repo::RepoInfoBase::name
std::string name() const
Repository name.
Definition: RepoInfoBase.cc:117
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
zypp::Exception::historyAsString
std::string historyAsString() const
The history as string.
Definition: Exception.cc:131
Pool.h
zypp::ZYppFactory::haveZYpp
bool haveZYpp() const
Whether the ZYpp instance is already created.
Definition: ZYppFactory.cc:420
zypp::ZYppFactory::instance
static ZYppFactory instance()
Singleton ctor.
Definition: ZYppFactory.cc:342
zypp::misc::LS_NOREFRESH
// Don't refresh existing repos.
Definition: DefaultLoadSystem.h:36
zypp::repo::RepoType::RPMPLAINDIR
static const RepoType RPMPLAINDIR
Definition: RepoType.h:31
zypp::RepoManager::cleanCache
void cleanCache(const RepoInfo &info, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
clean local cache
Definition: RepoManager.cc:2583
ZYPP_RETHROW
#define ZYPP_RETHROW(EXCPT)
Drops a logline and rethrows, updating the CodeLocation.
Definition: Exception.h:400
zypp::RepoInfo::url
Url url() const
Pars pro toto: The first repository url.
Definition: RepoInfo.h:131
for_
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:28
zypp::filesystem::Pathname
Pathname.
Definition: Pathname.h:44
ERR
#define ERR
Definition: Logger.h:81
DefaultLoadSystem.h
zypp::RepoManager::knownRepositories
std::list< RepoInfo > knownRepositories() const
List of known repositories.
Definition: RepoManager.h:167
zypp::sat::Pool::reposFind
Repository reposFind(const std::string &alias_r) const
Find a Repository named alias_r.
Definition: Pool.cc:163
zypp::RepoManager::checkIfToRefreshMetadata
RefreshCheckStatus checkIfToRefreshMetadata(const RepoInfo &info, const Url &url, RawMetadataRefreshPolicy policy=RefreshIfNeeded)
Checks whether to refresh metadata for specified repository and url.
Definition: RepoManager.cc:2559
RepoManager.h
zypp::RepoManager
creates and provides information about known sources.
Definition: RepoManager.h:105
zypp::RepoInfo::type
repo::RepoType type() const
Type of repository,.
Definition: RepoInfo.cc:658
zypp::sat::Pool::systemRepo
Repository systemRepo()
Return the system repository, create it if missing.
Definition: Pool.cc:178