libzypp  17.27.0
ZYppCommitPolicy.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
13 #include <iostream>
14 
15 #include <zypp-core/base/String.h>
16 #include <zypp-core/base/StringV.h>
17 
18 #include <zypp/ZConfig.h>
19 #include <zypp/ZYppCommitPolicy.h>
20 #include <zypp-core/base/LogControl.h>
21 #include <zypp-core/TriBool.h>
22 
24 namespace zypp
25 {
26 
27 
29  {
30  static TriBool singleTrans = indeterminate;
31  if ( indeterminate(singleTrans) ) {
32  const char *val = ::getenv("ZYPP_SINGLE_RPMTRANS");
33  if ( val && std::string_view( val ) == "1" )
34  singleTrans = true;
35  else
36  singleTrans = false;
37  }
38  // for some reason some compilers do not accept the implicit conversion to bool here.
39  return bool( singleTrans );
40  }
41 
43  //
44  // CLASS NAME : ZYppCommitPolicy::Impl
45  //
47 
49  {
50  public:
51  Impl()
52  : _restrictToMedia ( 0 )
53  , _downloadMode ( ZConfig::instance().commit_downloadMode() )
54  , _rpmInstFlags ( ZConfig::instance().rpmInstallFlags() )
55  , _syncPoolAfterCommit ( true )
57  {}
58 
59  public:
60  unsigned _restrictToMedia;
62  target::rpm::RpmInstFlags _rpmInstFlags;
64  bool _singleTransMode; //< run everything in one big rpm transaction
65 
66  private:
67  friend Impl * rwcowClone<Impl>( const Impl * rhs );
69  Impl * clone() const { return new Impl( *this ); }
70  };
71 
73  //
74  // CLASS NAME : ZYppCommitPolicy
75  //
77 
79  : _pimpl( new Impl )
80  {}
81 
82 
84  { _pimpl->_restrictToMedia = ( mediaNr_r == 1 ) ? 1 : 0; return *this; }
85 
87  { return _pimpl->_restrictToMedia; }
88 
89 
91  { _pimpl->_rpmInstFlags.setFlag( target::rpm::RPMINST_TEST, yesNo_r ); return *this; }
92 
94  { return _pimpl->_rpmInstFlags.testFlag( target::rpm::RPMINST_TEST );}
95 
97  {
98  if ( singleTransModeEnabled() && val_r == DownloadAsNeeded ) {
99  DBG << val_r << " is not compatible with singleTransMode, falling back to " << DownloadInAdvance << std::endl;
101  }
102  _pimpl->_downloadMode = val_r; return *this;
103  }
104 
106  {
108  DBG << _pimpl->_downloadMode << " is not compatible with singleTransMode, falling back to " << DownloadInAdvance << std::endl;
109  return DownloadInAdvance;
110  }
111  return _pimpl->_downloadMode;
112  }
113 
114  ZYppCommitPolicy & ZYppCommitPolicy::rpmInstFlags( target::rpm::RpmInstFlags newFlags_r )
115  { _pimpl->_rpmInstFlags = newFlags_r; return *this; }
116 
118  { _pimpl->_rpmInstFlags.setFlag( target::rpm::RPMINST_NOSIGNATURE, yesNo_r ); return *this; }
119 
121  { _pimpl->_rpmInstFlags.setFlag( target::rpm::RPMINST_EXCLUDEDOCS, yesNo_r ); return *this; }
122 
123  target::rpm::RpmInstFlags ZYppCommitPolicy::rpmInstFlags() const
124  { return _pimpl->_rpmInstFlags; }
125 
127  { return _pimpl->_rpmInstFlags.testFlag( target::rpm::RPMINST_NOSIGNATURE ); }
128 
130  { return _pimpl->_rpmInstFlags.testFlag( target::rpm::RPMINST_EXCLUDEDOCS ); }
131 
133  { _pimpl->_rpmInstFlags.setFlag( target::rpm::RPMINST_ALLOWDOWNGRADE, yesNo_r ); return *this; }
134 
137 
139  { _pimpl->_rpmInstFlags.setFlag( target::rpm::RPMINST_REPLACEFILES, yesNo_r ); return *this; }
140 
143 
145  { _pimpl->_syncPoolAfterCommit = yesNo_r; return *this; }
146 
148  { return _pimpl->_syncPoolAfterCommit; }
149 
151  { return _pimpl->_singleTransMode; }
152 
153  std::ostream & operator<<( std::ostream & str, const ZYppCommitPolicy & obj )
154  {
155  str << "CommitPolicy(";
156  if ( obj.restrictToMedia() )
157  str << " restrictToMedia:" << obj.restrictToMedia();
158  if ( obj.dryRun() )
159  str << " dryRun";
160  str << " " << obj.downloadMode();
161  if ( obj.syncPoolAfterCommit() )
162  str << " syncPoolAfterCommit";
163  if ( obj.rpmInstFlags() )
164  str << " rpmInstFlags{" << str::hexstring(obj.rpmInstFlags()) << "}";
165  return str << " )";
166  }
167 
169 } // namespace zypp
Interim helper class to collect global options and settings.
Definition: ZConfig.h:62
Impl * clone() const
clone for RWCOW_pointer
target::rpm::RpmInstFlags _rpmInstFlags
Options and policies for ZYpp::commit.
ZYppCommitPolicy & rpmInstFlags(target::rpm::RpmInstFlags newFlags_r)
The default target::rpm::RpmInstFlags.
bool singleTransModeEnabled() const
ZYppCommitPolicy & syncPoolAfterCommit(bool yesNo_r)
Kepp pool in sync with the Target databases after commit (default: true)
ZYppCommitPolicy & dryRun(bool yesNo_r)
Set dry run (default: false).
ZYppCommitPolicy & restrictToMedia(unsigned mediaNr_r)
Restrict commit to media 1.
DownloadMode downloadMode() const
target::rpm::RpmInstFlags rpmInstFlags() const
ZYppCommitPolicy & downloadMode(DownloadMode val_r)
Commit download policy to use.
unsigned restrictToMedia() const
bool syncPoolAfterCommit() const
RWCOW_pointer< Impl > _pimpl
Pointer to data.
boost::logic::tribool TriBool
3-state boolean logic (true, false and indeterminate).
Definition: String.h:30
String related utilities and Regular expression matching.
std::string hexstring(char n, int w=4)
Definition: String.h:324
@ RPMINST_ALLOWDOWNGRADE
Definition: RpmFlags.h:51
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
bool singleTransInEnv()
std::ostream & operator<<(std::ostream &str, const InputStream &obj)
Definition: InputStream.cc:166
DownloadMode
Supported commit download policies.
Definition: DownloadMode.h:23
@ DownloadAsNeeded
Alternating download and install.
Definition: DownloadMode.h:32
@ DownloadInAdvance
First download all packages to the local cache.
Definition: DownloadMode.h:27
#define DBG
Definition: Logger.h:95