libzypp  17.38.7
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>
13 #include <zypp-core/fs/PathInfo.h>
14 #include <zypp-core/base/Gettext.h>
15 
16 namespace 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 
31  expected<RefreshContextRef> RefreshContext::create( ContextRef zyppContext, zypp::RepoInfo info, RepoManagerRef repoManager )
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 
106  {
107  return _repoInfo;
108  }
109 
110 
111  const RepoManagerRef &RefreshContext::repoManager() const
112  {
113  return _repoManager;
114  }
115 
116 
118  {
119  return _repoManager->options();
120  }
121 
122 
124  {
125  return _policy;
126  }
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 
158  {
159  return _sigProbedTypeChanged;
160  }
161 
162 }
#define MIL
Definition: Logger.h:103
int exchange(const Pathname &lpath, const Pathname &rpath)
Exchanges two files or directories.
Definition: PathInfo.cc:775
std::optional< PluginRepoverification > _pluginRepoverification
Definition: refresh.h:127
static TmpDir makeSibling(const Pathname &sibling_r)
Provide a new empty temporary directory as sibling.
Definition: TmpPath.cc:250
zypp::RepoInfo _repoInfo
Definition: refresh.h:123
zypp::Pathname _rawCachePath
Definition: refresh.h:124
void setProbedType(zypp::repo::RepoType rType)
Definition: refresh.cc:141
Definition: ansi.h:854
What is known about a repository.
Definition: RepoInfo.h:71
Pathname path() const
Definition: TmpPath.cc:124
repo::RawMetadataRefreshPolicy _policy
Definition: refresh.h:126
#define ZYPP_EXCPT_PTR(EXCPT)
Drops a logline and returns Exception as a std::exception_ptr.
Definition: Exception.h:463
int hardlinkCopy(const Pathname &oldpath, const Pathname &newpath)
Create newpath as hardlink or copy of oldpath.
Definition: PathInfo.cc:902
Repo manager settings.
Signal< void(zypp::repo::RepoType)> _sigProbedTypeChanged
Definition: refresh.h:130
bool empty() const
Test for an empty path.
Definition: Pathname.h:117
SignalProxy< void(zypp::repo::RepoType)> sigProbedTypeChanged()
Definition: refresh.cc:157
zypp::Pathname targetDir() const
Definition: refresh.cc:87
std::optional< zypp::repo::RepoType > _probedType
Definition: refresh.h:129
Provide a new empty temporary directory and recursively delete it when no longer needed.
Definition: TmpPath.h:172
static constexpr const char * cacheFileName()
ContextRef _zyppContext
static expected< repo::RefreshContextRef > create(ContextRef zyppContext, zypp::RepoInfo info, RepoManagerRef repoManager)
Definition: refresh.cc:31
zypp::filesystem::TmpDir _tmpDir
Definition: refresh.h:125
#define _(MSG)
Definition: Gettext.h:39
static expected success(ConsParams &&...params)
Definition: expected.h:178
const std::optional< PluginRepoverification > & pluginRepoverification() const
Definition: refresh.cc:135
void setPolicy(RawMetadataRefreshPolicy newPolicy)
Definition: refresh.cc:129
Base class for Exception.
Definition: Exception.h:152
RepoManagerRef _repoManager
Definition: refresh.h:122
const RepoManagerRef & repoManager() const
Definition: refresh.cc:111
static constexpr const char * cookieFileName()
Wrapper class for ::stat/::lstat.
Definition: PathInfo.h:225
RawMetadataRefreshPolicy policy() const
Definition: refresh.cc:123
const ContextRef & zyppContext() const
Definition: refresh.cc:93
const std::optional< zypp::repo::RepoType > & probedType() const
Definition: refresh.cc:151
ResultType and_then(const expected< T, E > &exp, Function &&f)
Definition: expected.h:520
const zypp::RepoManagerOptions & repoManagerOptions() const
Definition: refresh.cc:117
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:166
const zypp::RepoInfo & repoInfo() const
Definition: refresh.cc:99
const zypp::Pathname & rawCachePath() const
Definition: refresh.cc:81
std::optional< PluginRepoverification > _pluginRepoverification
Definition: downloader.h:63
Repository type enumeration.
Definition: RepoType.h:28