libzypp  17.35.14
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 
27  template<typename ZyppContextRefType>
28  expected<RefreshContextRef<ZyppContextRefType>> RefreshContext<ZyppContextRefType>::create( ZyppContextRefType zyppContext, zypp::RepoInfo info, RepoManagerRef<ZyppContextRefType> repoManager )
29  {
30  using namespace operators;
31  using CtxType = RefreshContext<ZyppContextRefType>;
32  using CtxRefType = RefreshContextRef<ZyppContextRefType>;
33 
34  return rawcache_path_for_repoinfo ( repoManager->options(), info )
35  | and_then( [&]( zypp::Pathname rawCachePath ) {
36 
38  if( tmpdir.path().empty() && geteuid() != 0 ) {
39  tmpdir = zypp::filesystem::TmpDir(); // non-root user may not be able to write the cache
40  }
41  if( tmpdir.path().empty() ) {
42  return expected<CtxRefType>::error( ZYPP_EXCPT_PTR(zypp::Exception(_("Can't create metadata cache directory."))) );
43  }
44 
45  MIL << "Creating RefreshContext " << std::endl;
46 
47  return expected<CtxRefType>::success( std::make_shared<CtxType>( private_constr_t{}
48  , std::move(zyppContext)
49  , std::move(info)
50  , std::move(rawCachePath)
51  , std::move(tmpdir)
52  , std::move(repoManager)));
53  } );
54  }
55 
56  template<typename ZyppContextRefType>
58  {
59  MIL << "Deleting RefreshContext" << std::endl;
60  }
61 
62  template<typename ZyppContextRefType>
64  {
65  zypp::filesystem::exchange( _tmpDir.path(), _rawCachePath );
66  }
67 
68  template<typename ZyppContextRefType>
70  {
71  return _rawCachePath;
72  }
73 
74  template<typename ZyppContextRefType>
76  {
77  return _tmpDir.path();
78  }
79 
80  template<typename ZyppContextRefType>
81  const ZyppContextRefType &RefreshContext<ZyppContextRefType>::zyppContext() const
82  {
83  return _zyppContext;
84  }
85 
86  template<typename ZyppContextRefType>
88  {
89  return _repoInfo;
90  }
91 
92  template<typename ZyppContextRefType>
94  {
95  return _repoInfo;
96  }
97 
98  template<typename ZyppContextRefType>
99  const RepoManagerRef<ZyppContextRefType> &RefreshContext<ZyppContextRefType>::repoManager() const
100  {
101  return _repoManager;
102  }
103 
104  template<typename ZyppContextRefType>
106  {
107  return _repoManager->options();
108  }
109 
110  template<typename ZyppContextRefType>
112  {
113  return _policy;
114  }
115 
116  template<typename ZyppContextRefType>
118  {
119  _policy = newPolicy;
120  }
121 
122  template<typename ZyppContextRefType>
123  const std::optional<typename RefreshContext<ZyppContextRefType>::PluginRepoverification> &RefreshContext<ZyppContextRefType>::pluginRepoverification() const
124  {
125  return _pluginRepoverification;
126  }
127 
128  template<typename ZyppContextRefType>
130  {
131  if ( _probedType && *_probedType == rType )
132  return;
133 
134  _probedType = rType;
135  _sigProbedTypeChanged.emit(rType);
136  }
137 
138  template<typename ZyppContextRefType>
139  const std::optional<zypp::repo::RepoType> &RefreshContext<ZyppContextRefType>::probedType() const
140  {
141  return _probedType;
142  }
143 
144  template<typename ZyppContextRefType>
146  {
147  return _sigProbedTypeChanged;
148  }
149 
150  // explicitely intantiate the template types we want to work with
151  template class RefreshContext<SyncContextRef>;
152  template class RefreshContext<ContextRef>;
153 
154 }
#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:303
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:181
static expected success(ConsParams &&...params)
Definition: expected.h:115
zypp::RepoManagerFlags::CacheBuildPolicy _policy
Base class for Exception.
Definition: Exception.h:146
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:171
Repository type enumeration.
Definition: RepoType.h:28