libzypp  17.38.17
DefaultLoadSystem.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #include <iostream>
13 
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  ZYpp::Ptr defaultLoadSystem( const Pathname & sysRoot_r, LoadSystemFlags flags_r )
38  {
39  if ( not flags_r && geteuid() != 0 ) {
40  flags_r |= LS_NOREFRESH;
41  }
42  MIL << str::form( "*** Load system at '%s' (%lx)", sysRoot_r.c_str(), (unsigned long)flags_r ) << endl;
43 
44  if ( ! PathInfo( sysRoot_r ).isDir() )
45  ZYPP_THROW( Exception(str::form("sysRoot_r argument needs to be a directory. (%s)", sysRoot_r.c_str())) );
46 
48  ZYPP_THROW( Exception("ZYpp instance is already created. (Call this method earlier.)") );
49 
50  if ( flags_r.testFlag( LS_READONLY ) )
52 
53  ZYpp::Ptr zyppPtr = getZYpp();
54  sat::Pool satpool( sat::Pool::instance() );
55 
56  if ( 1 )
57  {
58  MIL << "*** load target '" << Repository::systemRepoAlias() << "'\t" << endl;
59  zyppPtr->initializeTarget( sysRoot_r );
60  zyppPtr->target()->load();
61  MIL << satpool.systemRepo() << endl;
62  }
63 
64  if ( not flags_r.testFlag( LS_NOREPOS ) )
65  {
66  RepoManager repoManager( sysRoot_r );
67  RepoInfoList repos = repoManager.knownRepositories();
68  for_( it, repos.begin(), repos.end() )
69  {
70  RepoInfo & nrepo( *it );
71 
72  if ( ! nrepo.enabled() )
73  continue;
74 
75  if ( ! flags_r.testFlag( LS_NOREFRESH ) )
76  {
77  if ( repoManager.isCached( nrepo )
78  && ( nrepo.type() == repo::RepoType::RPMPLAINDIR // refreshes always
79  || repoManager.checkIfToRefreshMetadata( nrepo, nrepo.url() ) == RepoManager::REFRESH_NEEDED ) )
80  {
81  MIL << str::form( "*** clean cache for repo '%s'\t", nrepo.name().c_str() ) << endl;
82  repoManager.cleanCache( nrepo );
83  MIL << str::form( "*** refresh repo '%s'\t", nrepo.name().c_str() ) << endl;
84  repoManager.refreshMetadata( nrepo );
85  }
86  }
87 
88  if ( ! repoManager.isCached( nrepo ) )
89  {
90  MIL << str::form( "*** build cache for repo '%s'\t", nrepo.name().c_str() ) << endl;
91  repoManager.buildCache( nrepo );
92  }
93 
94  MIL << str::form( "*** load repo '%s'\t", nrepo.name().c_str() ) << std::flush;
95  try
96  {
97  repoManager.loadFromCache( nrepo );
98  MIL << satpool.reposFind( nrepo.alias() ) << endl;
99  }
100  catch ( const Exception & exp )
101  {
102  ERR << "*** load repo failed: " << exp.asString() + "\n" + exp.historyAsString() << endl;
103  ZYPP_RETHROW ( exp );
104  }
105  }
106  }
107  MIL << str::form( "*** Read system at '%s'", sysRoot_r.c_str() ) << endl;
108 
109  return zyppPtr;
110  }
111 
113  } // namespace misc
116 } // namespace zypp
void loadFromCache(const RepoInfo &info, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Load resolvables into the pool.
Definition: RepoManager.cc:171
#define MIL
Definition: Logger.h:130
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:459
bool haveZYpp() const
Whether the ZYpp instance is already created.
Definition: ZYppFactory.cc:464
void IWantIt() ZYPP_DEPRECATED
Definition: ZYppFactory.cc:86
void cleanCache(const RepoInfo &info, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
clean local cache
Definition: RepoManager.cc:165
RefreshCheckStatus checkIfToRefreshMetadata(const RepoInfo &info, const Url &url, RawMetadataRefreshPolicy policy=RefreshIfNeeded)
Checks whether to refresh metadata for specified repository and url.
Definition: RepoManager.cc:133
const char * c_str() const
String representation.
Definition: Pathname.h:113
std::list< RepoInfo > RepoInfoList
relates: RepoInfo
Definition: RepoInfo.h:664
What is known about a repository.
Definition: RepoInfo.h:71
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:27
static ZYppFactory instance()
Singleton ctor.
Definition: ZYppFactory.cc:365
void buildCache(const RepoInfo &info, CacheBuildPolicy policy=BuildIfNeeded, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Refresh local cache.
Definition: RepoManager.cc:158
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Definition: String.cc:39
bool enabled() const
If enabled is false, then this repository must be ignored as if does not exists, except when checking...
#define ERR
Definition: Logger.h:132
void refreshMetadata(const RepoInfo &info, RawMetadataRefreshPolicy policy=RefreshIfNeeded, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Refresh local raw cache.
Definition: RepoManager.cc:142
Repository systemRepo()
Return the system repository, create it if missing.
Definition: Pool.cc:178
Url url() const
Pars pro toto: The first repository url, this is either baseUrls().front() or if no baseUrl is define...
Definition: RepoInfo.cc:894
#define ZYPP_RETHROW(EXCPT)
Drops a logline and rethrows, updating the CodeLocation.
Definition: Exception.h:479
static Pool instance()
Singleton ctor.
Definition: Pool.h:55
ZYpp::Ptr defaultLoadSystem(const Pathname &sysRoot_r, LoadSystemFlags flags_r)
Create the ZYpp instance and load target and enabled repositories.
std::string alias() const
unique identifier for this source.
std::string asString() const
Error message provided by dumpOn as string.
Definition: Exception.cc:124
shared_ptr< ZYpp > Ptr
Definition: ZYpp.h:62
std::string historyAsString() const
The history as string.
Definition: Exception.cc:195
bool isCached(const RepoInfo &info) const
Whether a repository exists in cache.
Definition: RepoManager.cc:168
ZYpp::Ptr getZYpp()
relates: ZYppFactory Convenience to get the Pointer to the ZYpp instance.
Definition: ZYppFactory.h:77
// Don&#39;t refresh existing repos.
// Create readonly ZYpp instance.
Repository reposFind(const std::string &alias_r) const
Find a Repository named alias_r.
Definition: Pool.cc:163
Base class for Exception.
Definition: Exception.h:152
std::list< RepoInfo > knownRepositories() const
List of known repositories.
Definition: RepoManager.h:115
std::string name() const
Repository name.
Global sat-pool.
Definition: Pool.h:46
Wrapper class for ::stat/::lstat.
Definition: PathInfo.h:225
static const RepoType RPMPLAINDIR
Definition: RepoType.h:32
static const std::string & systemRepoAlias()
Reserved system repository alias .
Definition: Repository.cc:43
// Don&#39;t loag existing repos (just Target).
static constexpr RefreshCheckStatus REFRESH_NEEDED
refresh is needed
Definition: RepoManager.h:142
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
repo::RepoType type() const
Type of repository,.
Definition: RepoInfo.cc:831