libzypp  17.32.4
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, zypp::RepoManagerOptions &&opts )
20  : _zyppContext( std::move(zyppContext) )
21  , _repoInfo( std::move(info) )
22  , _rawCachePath( std::move(rawCachePath) )
23  , _tmpDir( std::move(tempDir) )
24  , _repoManagerOptions( std::move(opts) )
25  {}
26 
27  template<typename ZyppContextRefType>
28  expected<RefreshContextRef<ZyppContextRefType>> RefreshContext<ZyppContextRefType>::create( ZyppContextRefType zyppContext, zypp::RepoInfo info, zypp::RepoManagerOptions opts )
29  {
30  using CtxType = RefreshContext<ZyppContextRefType>;
31  using CtxRefType = RefreshContextRef<ZyppContextRefType>;
32 
33  zypp::Pathname rawCachePath = zypp::rawcache_path_for_repoinfo ( opts, info );
34 #if LEGACY(173205)
35  using zypp::PathInfo;
36  L_DBG("1222398") << "rawCachePath " << PathInfo( rawCachePath ) << std::endl;
37 #endif
39 #if LEGACY(173205)
40  L_DBG("1222398") << "siblinghPath " << PathInfo( tmpdir.path() ) << std::endl;
41 #endif
42 
43  if( tmpdir.path().empty() ) {
44  return expected<CtxRefType>::error( ZYPP_EXCPT_PTR(zypp::Exception(_("Can't create metadata cache directory."))) );
45  }
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(opts)));
53  }
54 
55  template<typename ZyppContextRefType>
57  {
58  MIL << "Deleting RefreshContext" << std::endl;
59  }
60 
61  template<typename ZyppContextRefType>
63  {
64 #if LEGACY(173205)
65  using zypp::PathInfo;
66  L_DBG("1222398") << "PREEX rawCachePath " << PathInfo( _rawCachePath ) << std::endl;
67  L_DBG("1222398") << "PREEX siblinghPath " << PathInfo( _tmpDir.path() ) << std::endl;
68 #endif
69  zypp::filesystem::exchange( _tmpDir.path(), _rawCachePath );
70 #if LEGACY(173205)
71  L_DBG("1222398") << "PSTEX rawCachePath " << PathInfo( _rawCachePath ) << std::endl;
72  L_DBG("1222398") << "PSTEX siblinghPath " << PathInfo( _tmpDir.path() ) << std::endl;
73 #endif
74  }
75 
76  template<typename ZyppContextRefType>
78  {
79  return _rawCachePath;
80  }
81 
82  template<typename ZyppContextRefType>
84  {
85  return _tmpDir.path();
86  }
87 
88  template<typename ZyppContextRefType>
89  const ZyppContextRefType &RefreshContext<ZyppContextRefType>::zyppContext() const
90  {
91  return _zyppContext;
92  }
93 
94  template<typename ZyppContextRefType>
96  {
97  return _repoInfo;
98  }
99 
100  template<typename ZyppContextRefType>
102  {
103  return _repoInfo;
104  }
105 
106  template<typename ZyppContextRefType>
108  {
109  return _repoManagerOptions;
110  }
111 
112  template<typename ZyppContextRefType>
114  {
115  return _policy;
116  }
117 
118  template<typename ZyppContextRefType>
120  {
121  _policy = newPolicy;
122  }
123 
124  template<typename ZyppContextRefType>
125  const std::optional<typename RefreshContext<ZyppContextRefType>::PluginRepoverification> &RefreshContext<ZyppContextRefType>::pluginRepoverification() const
126  {
127  return _pluginRepoverification;
128  }
129 
130  template<typename ZyppContextRefType>
132  {
133  if ( _probedType && *_probedType == rType )
134  return;
135 
136  _probedType = rType;
137  _sigProbedTypeChanged.emit(rType);
138  }
139 
140  template<typename ZyppContextRefType>
141  const std::optional<zypp::repo::RepoType> &RefreshContext<ZyppContextRefType>::probedType() const
142  {
143  return _probedType;
144  }
145 
146  template<typename ZyppContextRefType>
147  SignalProxy<void (zypp::repo::RepoType)> RefreshContext<ZyppContextRefType>::sigProbedTypeChanged()
148  {
149  return _sigProbedTypeChanged;
150  }
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:96
int exchange(const Pathname &lpath, const Pathname &rpath)
Exchanges two files or directories.
Definition: PathInfo.cc:757
#define _(MSG)
Definition: Gettext.h:37
static TmpDir makeSibling(const Pathname &sibling_r)
Provide a new empty temporary directory as sibling.
Definition: TmpPath.cc:301
Definition: Arch.h:363
What is known about a repository.
Definition: RepoInfo.h:71
Pathname path() const
Definition: TmpPath.cc:150
#define ZYPP_EXCPT_PTR(EXCPT)
Drops a logline and returns Exception as a std::exception_ptr.
Definition: Exception.h:433
ZyppContextRefType _zyppContext
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.
bool empty() const
Test for an empty path.
Definition: Pathname.h:114
Provide a new empty temporary directory and recursively delete it when no longer needed.
Definition: TmpPath.h:181
RawMetadataRefreshPolicy
Definition: refresh.h:30
#define L_DBG(GROUP)
Definition: Logger.h:104
Base class for Exception.
Definition: Exception.h:146
Wrapper class for ::stat/::lstat.
Definition: PathInfo.h:221
Repository type enumeration.
Definition: RepoType.h:27