libzypp 17.36.7

refresh.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
9#include "refresh.h"
10#include <zypp-media/ng/providespec.h>
11#include <zypp/ng/Context>
12#include <zypp/ng/workflows/contextfacade.h>
13#include <zypp-core/fs/PathInfo.h>
14#include <zypp-core/base/Gettext.h>
15
16 namespace zyppng::repo {
17
18 template<typename ZyppContextRefType>
19 RefreshContext<ZyppContextRefType>::RefreshContext( private_constr_t, ZyppContextRefType &&zyppContext, zypp::RepoInfo &&info, zypp::Pathname &&rawCachePath, zypp::filesystem::TmpDir &&tempDir, RepoManagerRef<ContextRefType> &&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 template<typename ZyppContextRefType>
31 expected<RefreshContextRef<ZyppContextRefType>> RefreshContext<ZyppContextRefType>::create( ZyppContextRefType zyppContext, zypp::RepoInfo info, RepoManagerRef<ZyppContextRefType> repoManager )
32 {
33 using namespace operators;
34 using CtxType = RefreshContext<ZyppContextRefType>;
35 using CtxRefType = RefreshContextRef<ZyppContextRefType>;
36
37 return rawcache_path_for_repoinfo ( repoManager->options(), info )
38 | and_then( [&]( zypp::Pathname rawCachePath ) {
39
40 zypp::filesystem::TmpDir tmpdir( zypp::filesystem::TmpDir::makeSibling( rawCachePath, 0755 ) );
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 template<typename ZyppContextRefType>
60 RefreshContext<ZyppContextRefType>::~RefreshContext()
61 {
62 MIL << "Deleting RefreshContext" << std::endl;
63 }
64
65 template<typename ZyppContextRefType>
66 void RefreshContext<ZyppContextRefType>::saveToRawCache()
67 {
68 zypp::filesystem::exchange( _tmpDir.path(), _rawCachePath );
69 }
70
71 template<typename ZyppContextRefType>
72 const zypp::Pathname &RefreshContext<ZyppContextRefType>::rawCachePath() const
73 {
74 return _rawCachePath;
75 }
76
77 template<typename ZyppContextRefType>
78 zypp::Pathname RefreshContext<ZyppContextRefType>::targetDir() const
79 {
80 return _tmpDir.path();
81 }
82
83 template<typename ZyppContextRefType>
84 const ZyppContextRefType &RefreshContext<ZyppContextRefType>::zyppContext() const
85 {
86 return _zyppContext;
87 }
88
89 template<typename ZyppContextRefType>
90 const zypp::RepoInfo &RefreshContext<ZyppContextRefType>::repoInfo() const
91 {
92 return _repoInfo;
93 }
94
95 template<typename ZyppContextRefType>
96 zypp::RepoInfo &RefreshContext<ZyppContextRefType>::repoInfo()
97 {
98 return _repoInfo;
99 }
100
101 template<typename ZyppContextRefType>
102 const RepoManagerRef<ZyppContextRefType> &RefreshContext<ZyppContextRefType>::repoManager() const
103 {
104 return _repoManager;
105 }
106
107 template<typename ZyppContextRefType>
108 const zypp::RepoManagerOptions &RefreshContext<ZyppContextRefType>::repoManagerOptions() const
109 {
110 return _repoManager->options();
111 }
112
113 template<typename ZyppContextRefType>
114 repo::RawMetadataRefreshPolicy RefreshContext<ZyppContextRefType>::policy() const
115 {
116 return _policy;
117 }
118
119 template<typename ZyppContextRefType>
120 void RefreshContext<ZyppContextRefType>::setPolicy(RawMetadataRefreshPolicy newPolicy)
121 {
122 _policy = newPolicy;
123 }
124
125 template<typename ZyppContextRefType>
126 const std::optional<typename RefreshContext<ZyppContextRefType>::PluginRepoverification> &RefreshContext<ZyppContextRefType>::pluginRepoverification() const
127 {
128 return _pluginRepoverification;
129 }
130
131 template<typename ZyppContextRefType>
132 void RefreshContext<ZyppContextRefType>::setProbedType(zypp::repo::RepoType rType)
133 {
134 if ( _probedType && *_probedType == rType )
135 return;
136
137 _probedType = rType;
138 _sigProbedTypeChanged.emit(rType);
139 }
140
141 template<typename ZyppContextRefType>
142 const std::optional<zypp::repo::RepoType> &RefreshContext<ZyppContextRefType>::probedType() const
143 {
144 return _probedType;
145 }
146
147 template<typename ZyppContextRefType>
148 SignalProxy<void (zypp::repo::RepoType)> RefreshContext<ZyppContextRefType>::sigProbedTypeChanged()
149 {
150 return _sigProbedTypeChanged;
151 }
152
153 // explicitely intantiate the template types we want to work with
154 template class RefreshContext<SyncContextRef>;
155 template class RefreshContext<ContextRef>;
156
157}
zypp::Exception
Base class for Exception.
Definition Exception.h:147
zypp::RepoInfo
What is known about a repository.
Definition RepoInfo.h:72
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:47
zypp::filesystem::Pathname::empty
bool empty() const
Test for an empty path.
Definition Pathname.h:116
zypp::filesystem::TmpDir
Provide a new empty temporary directory and recursively delete it when no longer needed.
Definition TmpPath.h:188
zypp::filesystem::TmpDir::makeSibling
static TmpDir makeSibling(const Pathname &sibling_r)
Provide a new empty temporary directory as sibling.
Definition TmpPath.cc:308
zypp::filesystem::TmpPath::path
Pathname path() const
Definition TmpPath.cc:152
zyppng::SignalProxy
Definition signals.h:325
zyppng::expected
Definition expected.h:27
zyppng::expected::success
static expected success(ConsParams &&...params)
Definition expected.h:115
zyppng::expected::error
static expected error(ConsParams &&...params)
Definition expected.h:126
zyppng::repo::RefreshContext
Definition refresh.h:43
zyppng::repo::RefreshContext::_repoInfo
zypp::RepoInfo _repoInfo
Definition refresh.h:128
zyppng::repo::RefreshContext::repoManagerOptions
const zypp::RepoManagerOptions & repoManagerOptions() const
Definition refresh.cc:108
zyppng::repo::RefreshContext::~RefreshContext
~RefreshContext() override
Definition refresh.cc:60
zyppng::repo::RefreshContext::repoManager
const RepoManagerRef< ZyppContextRefType > & repoManager() const
Definition refresh.cc:102
zyppng::repo::RefreshContext::setProbedType
void setProbedType(zypp::repo::RepoType rType)
Definition refresh.cc:132
zyppng::repo::RefreshContext::probedType
const std::optional< zypp::repo::RepoType > & probedType() const
Definition refresh.cc:142
zyppng::repo::RefreshContext::targetDir
zypp::Pathname targetDir() const
Definition refresh.cc:78
zyppng::repo::RefreshContext::_pluginRepoverification
std::optional< PluginRepoverification > _pluginRepoverification
Definition refresh.h:132
zyppng::repo::RefreshContext::_probedType
std::optional< zypp::repo::RepoType > _probedType
Definition refresh.h:134
zyppng::repo::RefreshContext< SyncContextRef >::_tmpDir
zypp::filesystem::TmpDir _tmpDir
Definition refresh.h:130
zyppng::repo::RefreshContext::policy
RawMetadataRefreshPolicy policy() const
Definition refresh.cc:114
zyppng::repo::RefreshContext::pluginRepoverification
const std::optional< PluginRepoverification > & pluginRepoverification() const
Definition refresh.cc:126
zyppng::repo::RefreshContext::create
static expected< repo::RefreshContextRef< ZyppContextRefType > > create(ZyppContextRefType zyppContext, zypp::RepoInfo info, RepoManagerRef< ContextRefType > repoManager)
Definition refresh.cc:31
zyppng::repo::RefreshContext::saveToRawCache
void saveToRawCache()
Definition refresh.cc:66
zyppng::repo::RefreshContext::setPolicy
void setPolicy(RawMetadataRefreshPolicy newPolicy)
Definition refresh.cc:120
zyppng::repo::RefreshContext::zyppContext
const ZyppContextRefType & zyppContext() const
Definition refresh.cc:84
zyppng::repo::RefreshContext::_policy
repo::RawMetadataRefreshPolicy _policy
Definition refresh.h:131
zyppng::repo::RefreshContext::_zyppContext
ZyppContextRefType _zyppContext
Definition refresh.h:126
zyppng::repo::RefreshContext::repoInfo
const zypp::RepoInfo & repoInfo() const
Definition refresh.cc:90
zyppng::repo::RefreshContext::_repoManager
RepoManagerRef< ContextRefType > _repoManager
Definition refresh.h:127
zyppng::repo::RefreshContext::rawCachePath
const zypp::Pathname & rawCachePath() const
Definition refresh.cc:72
zyppng::repo::RefreshContext::_sigProbedTypeChanged
Signal< void(zypp::repo::RepoType)> _sigProbedTypeChanged
Definition refresh.h:135
zyppng::repo::RefreshContext< SyncContextRef >::_rawCachePath
zypp::Pathname _rawCachePath
Definition refresh.h:129
zyppng::repo::RefreshContext::sigProbedTypeChanged
SignalProxy< void(zypp::repo::RepoType)> sigProbedTypeChanged()
Definition refresh.cc:148
contextfacade.h
zypp::filesystem::exchange
int exchange(const Pathname &lpath, const Pathname &rpath)
Exchanges two files or directories.
Definition PathInfo.cc:761
zyppng::operators
Definition asyncresult.h:279
zyppng::operators::and_then
auto and_then(Fun &&function)
Definition expected.h:623
zyppng::repo
Definition downloader.cc:25
zyppng::repo::RawMetadataRefreshPolicy
zypp::RepoManagerFlags::RawMetadataRefreshPolicy RawMetadataRefreshPolicy
Definition refresh.h:33
zyppng::rawcache_path_for_repoinfo
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.
Definition repomanager.h:172
providespec.h
refresh.h
zypp::RepoManagerOptions
Repo manager settings.
Definition RepoManagerOptions.h:26
zypp::repo::RepoType
Repository type enumeration.
Definition RepoType.h:29
ZYPP_EXCPT_PTR
#define ZYPP_EXCPT_PTR(EXCPT)
Drops a logline and returns Exception as a std::exception_ptr.
Definition Exception.h:428
Gettext.h
_
#define _(MSG)
Definition Gettext.h:39
MIL
#define MIL
Definition Logger.h:100
PathInfo.h