libzypp: zypp/misc/DefaultLoadSystem.cc Source File

libzypp 17.38.11

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-core/base/LogTools.h>
15#include <zypp/PathInfo.h>
16
17#include <zypp/misc/DefaultLoadSystem.h>
18
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>
24
25using std::endl;
26
27#undef ZYPP_BASE_LOGGER_LOGGROUP
28#define ZYPP_BASE_LOGGER_LOGGROUP "zypp::misc"
29
31namespace zypp
32{
34 namespace misc
35 {
36
37 void 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
47 if ( ZYppFactory::instance().haveZYpp() )
48 ZYPP_THROW( Exception("ZYpp instance is already created. (Call this method earlier.)") );
49
50 if ( flags_r.testFlag( LS_READONLY ) )
51 zypp_readonly_hack::IWantIt ();
52
53 sat::Pool satpool( sat::Pool::instance() );
54
55 if ( 1 )
56 {
57 MIL << "*** load target '" << Repository::systemRepoAlias() << "'\t" << endl;
58 getZYpp()->initializeTarget( sysRoot_r );
59 getZYpp()->target()->load();
60 MIL << satpool.systemRepo() << endl;
61 }
62
63 if ( not flags_r.testFlag( LS_NOREPOS ) )
64 {
65 RepoManager repoManager( sysRoot_r );
66 RepoInfoList repos = repoManager.knownRepositories();
67 for_( it, repos.begin(), repos.end() )
68 {
69 RepoInfo & nrepo( *it );
70
71 if ( ! nrepo.enabled() )
72 continue;
73
74 if ( ! flags_r.testFlag( LS_NOREFRESH ) )
75 {
76 if ( repoManager.isCached( nrepo )
77 && ( nrepo.type() == repo::RepoType::RPMPLAINDIR // refreshes always
78 || repoManager.checkIfToRefreshMetadata( nrepo, nrepo.url() ) == RepoManager::REFRESH_NEEDED ) )
79 {
80 MIL << str::form( "*** clean cache for repo '%s'\t", nrepo.name().c_str() ) << endl;
81 repoManager.cleanCache( nrepo );
82 MIL << str::form( "*** refresh repo '%s'\t", nrepo.name().c_str() ) << endl;
83 repoManager.refreshMetadata( nrepo );
84 }
85 }
86
87 if ( ! repoManager.isCached( nrepo ) )
88 {
89 MIL << str::form( "*** build cache for repo '%s'\t", nrepo.name().c_str() ) << endl;
90 repoManager.buildCache( nrepo );
91 }
92
93 MIL << str::form( "*** load repo '%s'\t", nrepo.name().c_str() ) << std::flush;
94 try
95 {
96 repoManager.loadFromCache( nrepo );
97 MIL << satpool.reposFind( nrepo.alias() ) << endl;
98 }
99 catch ( const Exception & exp )
100 {
101 ERR << "*** load repo failed: " << exp.asString() + "\n" + exp.historyAsString() << endl;
102 ZYPP_RETHROW ( exp );
103 }
104 }
105 }
106 MIL << str::form( "*** Read system at '%s'", sysRoot_r.c_str() ) << endl;
107 }
108
110 } // namespace misc
111
113} // namespace zypp
DefaultLoadSystem.h
for_
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition Easy.h:27
ZYPP_RETHROW
#define ZYPP_RETHROW(EXCPT)
Drops a logline and rethrows, updating the CodeLocation.
Definition Exception.h:479
ZYPP_THROW
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition Exception.h:459
LogTools.h
MIL
#define MIL
Definition Logger.h:103
ERR
#define ERR
Definition Logger.h:105
Pool.h
RepoManager.h
Target.h
ZYppFactory.h
ZYppReadOnlyHack.h
zypp::Exception
Base class for Exception.
Definition Exception.h:153
zypp::Exception::historyAsString
std::string historyAsString() const
The history as string.
Definition Exception.cc:195
zypp::Exception::asString
std::string asString() const
Error message provided by dumpOn as string.
Definition Exception.cc:124
zypp::RepoInfo
What is known about a repository.
Definition RepoInfo.h:72
zypp::RepoInfo::type
repo::RepoType type() const
Type of repository,.
Definition RepoInfo.cc:846
zypp::RepoInfo::url
Url url() const
Pars pro toto: The first repository url, this is either baseUrls().front() or if no baseUrl is define...
Definition RepoInfo.cc:909
zypp::RepoManager
creates and provides information about known sources.
Definition RepoManager.h:60
zypp::RepoManager::isCached
bool isCached(const RepoInfo &info) const
Whether a repository exists in cache.
Definition RepoManager.cc:168
zypp::RepoManager::cleanCache
void cleanCache(const RepoInfo &info, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
clean local cache
Definition RepoManager.cc:165
zypp::RepoManager::refreshMetadata
void refreshMetadata(const RepoInfo &info, RawMetadataRefreshPolicy policy=RefreshIfNeeded, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Refresh local raw cache.
Definition RepoManager.cc:142
zypp::RepoManager::REFRESH_NEEDED
static constexpr RefreshCheckStatus REFRESH_NEEDED
refresh is needed
Definition RepoManager.h:142
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:133
zypp::RepoManager::knownRepositories
std::list< RepoInfo > knownRepositories() const
List of known repositories.
Definition RepoManager.h:115
zypp::RepoManager::buildCache
void buildCache(const RepoInfo &info, CacheBuildPolicy policy=BuildIfNeeded, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Refresh local cache.
Definition RepoManager.cc:158
zypp::RepoManager::loadFromCache
void loadFromCache(const RepoInfo &info, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Load resolvables into the pool.
Definition RepoManager.cc:171
zypp::Repository::systemRepoAlias
static const std::string & systemRepoAlias()
Reserved system repository alias @System .
Definition Repository.cc:38
zypp::ZYppFactory::instance
static ZYppFactory instance()
Singleton ctor.
Definition ZYppFactory.cc:365
zypp::filesystem::PathInfo
Wrapper class for stat/lstat.
Definition PathInfo.h:226
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:48
zypp::filesystem::Pathname::c_str
const char * c_str() const
String representation.
Definition Pathname.h:113
zypp::repo::RepoInfoBase::name
std::string name() const
Repository name.
Definition RepoInfoBase.cc:116
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::repo::RepoInfoBase::alias
std::string alias() const
unique identifier for this source.
Definition RepoInfoBase.cc:110
zypp::sat::Pool
Global sat-pool.
Definition Pool.h:47
zypp::sat::Pool::reposFind
Repository reposFind(const std::string &alias_r) const
Find a Repository named alias_r.
Definition Pool.cc:163
zypp::sat::Pool::instance
static Pool instance()
Singleton ctor.
Definition Pool.h:55
zypp::sat::Pool::systemRepo
Repository systemRepo()
Return the system repository, create it if missing.
Definition Pool.cc:178
zypp::misc
Definition DefaultLoadSystem.cc:35
zypp::misc::LS_READONLY
@ LS_READONLY
// Create readonly ZYpp instance.
Definition DefaultLoadSystem.h:35
zypp::misc::LS_NOREFRESH
@ LS_NOREFRESH
// Don't refresh existing repos.
Definition DefaultLoadSystem.h:36
zypp::misc::LS_NOREPOS
@ LS_NOREPOS
// Don't loag existing repos (just Target).
Definition DefaultLoadSystem.h:37
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::str::form
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Definition String.cc:39
zypp::zypp_readonly_hack::IWantIt
void IWantIt() ZYPP_DEPRECATED
Definition ZYppFactory.cc:86
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
zypp::RepoInfoList
std::list< RepoInfo > RepoInfoList
relates: RepoInfo
Definition RepoInfo.h:664
zypp::getZYpp
ZYpp::Ptr getZYpp()
relates: ZYppFactory Convenience to get the Pointer to the ZYpp instance.
Definition ZYppFactory.h:77
zypp::repo::RepoType::RPMPLAINDIR
static const RepoType RPMPLAINDIR
Definition RepoType.h:32
PathInfo.h