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"
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  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 
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>
61  {
62  MIL << "Deleting RefreshContext" << std::endl;
63  }
64 
65  template<typename ZyppContextRefType>
67  {
68  zypp::filesystem::exchange( _tmpDir.path(), _rawCachePath );
69  }
70 
71  template<typename ZyppContextRefType>
73  {
74  return _rawCachePath;
75  }
76 
77  template<typename ZyppContextRefType>
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>
91  {
92  return _repoInfo;
93  }
94 
95  template<typename ZyppContextRefType>
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>
109  {
110  return _repoManager->options();
111  }
112 
113  template<typename ZyppContextRefType>
115  {
116  return _policy;
117  }
118 
119  template<typename ZyppContextRefType>
121  {
122  _policy = newPolicy;
123  }
124 
125  template<typename ZyppContextRefType>
127  {
128  return _pluginRepoverification;
129  }
130 
131  template<typename ZyppContextRefType>
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>
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 }
#define MIL
Definition: Logger.h:100
int exchange(const Pathname &lpath, const Pathname &rpath)
Exchanges two files or directories.
Definition: PathInfo.cc:761
#define _(MSG)
Definition: Gettext.h:39
static TmpDir makeSibling(const Pathname &sibling_r)
Provide a new empty temporary directory as sibling.
Definition: TmpPath.cc:308
Definition: Arch.h:363
What is known about a repository.
Definition: RepoInfo.h:71
Pathname path() const
Definition: TmpPath.cc:152
#define ZYPP_EXCPT_PTR(EXCPT)
Drops a logline and returns Exception as a std::exception_ptr.
Definition: Exception.h:428
ZyppContextRefType _zyppContext
Repo manager settings.
bool empty() const
Test for an empty path.
Definition: Pathname.h:116
Provide a new empty temporary directory and recursively delete it when no longer needed.
Definition: TmpPath.h:187
static expected success(ConsParams &&...params)
Definition: expected.h:115
zypp::RepoManagerFlags::CacheBuildPolicy _policy
Base class for Exception.
Definition: Exception.h:146
zypp_private::repo::PluginRepoverification PluginRepoverification
Definition: repomanager.h:41
auto and_then(Fun &&function)
Definition: expected.h:623
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
Repository type enumeration.
Definition: RepoType.h:28