libzypp 17.38.3
refresh.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
9#include "refresh.h"
11#include <zypp/ng/Context>
15
16namespace zyppng::repo {
17
18
19 RefreshContext::RefreshContext( private_constr_t, ContextRef &&zyppContext, zypp::RepoInfo &&info, zypp::Pathname &&rawCachePath, zypp::filesystem::TmpDir &&tempDir, RepoManagerRef &&repoManager )
20 : _zyppContext( std::move(zyppContext) )
21 , _repoManager( std::move(repoManager) )
22 , _repoInfo( std::move(info) )
23 , _rawCachePath( std::move(rawCachePath) )
24 , _tmpDir( std::move(tempDir) )
25 {
26 if ( _repoManager->pluginRepoverification().checkIfNeeded() )
27 _pluginRepoverification = _repoManager->pluginRepoverification();
28 }
29
30
32 {
33 using namespace operators;
34 using CtxType = RefreshContext;
35 using CtxRefType = RefreshContextRef;
36
37 return rawcache_path_for_repoinfo ( repoManager->options(), info )
39
41 if( tmpdir.path().empty() && geteuid() != 0 ) {
42 tmpdir = zypp::filesystem::TmpDir(); // non-root user may not be able to write the cache
43 }
44 if( tmpdir.path().empty() ) {
45 return expected<CtxRefType>::error( ZYPP_EXCPT_PTR(zypp::Exception(_("Can't create metadata cache directory."))) );
46 }
47
48 MIL << "Creating RefreshContext " << std::endl;
49
50 return expected<CtxRefType>::success( std::make_shared<CtxType>( private_constr_t{}
51 , std::move(zyppContext)
52 , std::move(info)
53 , std::move(rawCachePath)
54 , std::move(tmpdir)
55 , std::move(repoManager)));
56 } );
57 }
58
59
61 {
62 MIL << "Deleting RefreshContext" << std::endl;
63 }
64
65
67 {
68 // RepoMirrorList may have updated the mirrorlist file in the old
69 // metadata dir. We transfer it to the new dir.
72 if ( zypp::PathInfo(oldCache).isExist() && not zypp::PathInfo(newCache).isExist() ) {
75 }
76 }
78 }
79
80
82 {
83 return _rawCachePath;
84 }
85
86
88 {
89 return _tmpDir.path();
90 }
91
92
93 const ContextRef &RefreshContext::zyppContext() const
94 {
95 return _zyppContext;
96 }
97
98
100 {
101 return _repoInfo;
102 }
103
104
109
110
111 const RepoManagerRef &RefreshContext::repoManager() const
112 {
113 return _repoManager;
114 }
115
116
118 {
119 return _repoManager->options();
120 }
121
122
127
128
130 {
131 _policy = newPolicy;
132 }
133
134
135 const std::optional<typename RefreshContext::PluginRepoverification> &RefreshContext::pluginRepoverification() const
136 {
138 }
139
140
142 {
143 if ( _probedType && *_probedType == rType )
144 return;
145
146 _probedType = rType;
147 _sigProbedTypeChanged.emit(rType);
148 }
149
150
151 const std::optional<zypp::repo::RepoType> &RefreshContext::probedType() const
152 {
153 return _probedType;
154 }
155
156
161
162}
#define ZYPP_EXCPT_PTR(EXCPT)
Drops a logline and returns Exception as a std::exception_ptr.
Definition Exception.h:463
#define _(MSG)
Definition Gettext.h:39
#define MIL
Definition Logger.h:100
Base class for Exception.
Definition Exception.h:153
What is known about a repository.
Definition RepoInfo.h:72
Wrapper class for stat/lstat.
Definition PathInfo.h:226
bool empty() const
Test for an empty path.
Definition Pathname.h:117
Provide a new empty temporary directory and recursively delete it when no longer needed.
Definition TmpPath.h:173
static TmpDir makeSibling(const Pathname &sibling_r)
Provide a new empty temporary directory as sibling.
Definition TmpPath.cc:250
Pathname path() const
Definition TmpPath.cc:124
static constexpr const char * cookieFileName()
static constexpr const char * cacheFileName()
static expected success(ConsParams &&...params)
Definition expected.h:178
static expected error(ConsParams &&...params)
Definition expected.h:189
void setPolicy(RawMetadataRefreshPolicy newPolicy)
Definition refresh.cc:129
RepoManagerRef _repoManager
Definition refresh.h:122
const zypp::Pathname & rawCachePath() const
Definition refresh.cc:81
zypp::Pathname targetDir() const
Definition refresh.cc:87
zypp::RepoInfo _repoInfo
Definition refresh.h:123
zypp::Pathname _rawCachePath
Definition refresh.h:124
const zypp::RepoInfo & repoInfo() const
Definition refresh.cc:99
RawMetadataRefreshPolicy policy() const
Definition refresh.cc:123
const std::optional< PluginRepoverification > & pluginRepoverification() const
Definition refresh.cc:135
repo::RawMetadataRefreshPolicy _policy
Definition refresh.h:126
std::optional< zypp::repo::RepoType > _probedType
Definition refresh.h:129
const RepoManagerRef & repoManager() const
Definition refresh.cc:111
std::optional< PluginRepoverification > _pluginRepoverification
Definition refresh.h:127
SignalProxy< void(zypp::repo::RepoType)> sigProbedTypeChanged()
Definition refresh.cc:157
static expected< repo::RefreshContextRef > create(ContextRef zyppContext, zypp::RepoInfo info, RepoManagerRef repoManager)
Definition refresh.cc:31
zypp::filesystem::TmpDir _tmpDir
Definition refresh.h:125
const zypp::RepoManagerOptions & repoManagerOptions() const
Definition refresh.cc:117
void setProbedType(zypp::repo::RepoType rType)
Definition refresh.cc:141
Signal< void(zypp::repo::RepoType)> _sigProbedTypeChanged
Definition refresh.h:130
const ContextRef & zyppContext() const
Definition refresh.cc:93
const std::optional< zypp::repo::RepoType > & probedType() const
Definition refresh.cc:151
int hardlinkCopy(const Pathname &oldpath, const Pathname &newpath)
Create newpath as hardlink or copy of oldpath.
Definition PathInfo.cc:902
int exchange(const Pathname &lpath, const Pathname &rpath)
Exchanges two files or directories.
Definition PathInfo.cc:775
auto and_then(Fun &&function)
Definition expected.h:708
zypp::RepoManagerFlags::RawMetadataRefreshPolicy RawMetadataRefreshPolicy
Definition refresh.h:33
expected< zypp::Pathname > rawcache_path_for_repoinfo(const RepoManagerOptions &opt, const RepoInfo &info)
Calculates the raw cache path for a repository, this is usually /var/cache/zypp/alias.
Repo manager settings.
Repository type enumeration.
Definition RepoType.h:29