libzypp 17.31.7
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>
20#include <zypp-core/base/LogControl.h>
21#include <zypp-core/TriBool.h>
22#include <zypp/PathInfo.h>
23#include <zypp/ZYppCallbacks.h>
24
26namespace zypp
27{
28
29 inline bool ImZYPPER()
30 { return filesystem::readlink( "/proc/self/exe" ).basename() == "zypper"; }
31
33 {
34#ifdef SINGLE_RPMTRANS_AS_DEFAULT_FOR_ZYPPER
35 static bool singleTrans = ImZYPPER();
36#else // SINGLE_RPMTRANS_AS_DEFAULT_FOR_ZYPPER
37 static bool singleTrans = ImZYPPER() && ([]()->bool{
38 const char *val = ::getenv("ZYPP_SINGLE_RPMTRANS");
39 bool ret = ( val && std::string_view( val ) == "1" );
40#ifdef NO_SINGLETRANS_USERMERGE
41 // Bug 1189788 - UsrMerge: filesystem package breaks system when upgraded in a single rpm transaction
42 // While the bug is not fixed, we don't allow ZYPP_SINGLE_RPMTRANS=1 on a not UsrMerged system.
43 // I.e. if /lib is a directory and not a symlink.
44 if ( ret && PathInfo( "/lib", PathInfo::LSTAT ).isDir() ) {
45 WAR << "Ignore $ZYPP_SINGLE_RPMTRANS=1: Bug 1189788 - UsrMerge: filesystem package breaks system when upgraded in a single rpm transaction" << std::endl;
47 "[boo#1189788] Tumbleweeds filesystem package seems to be unable to perform the\n"
48 " UsrMerge reliably in a single transaction. The requested\n"
49 " $ZYPP_SINGLE_RPMTRANS=1 will therefore be IGNORED because\n"
50 " the UsrMerge did not yet happen on this system."
51 , JobReport::UserData( "cmdout", "[boo#1189788]" ) );
52 return false;
53 }
54#endif
55 if ( ret ) {
57 "[TechPreview] $ZYPP_SINGLE_RPMTRANS=1 : New rpm install backend is enabled\n"
58 " If you find any bugs or issues please let us know:\n"
59 " https://bugzilla.opensuse.org/\n"
60 " Component: libzypp (or zypper)\n"
61 " And please attach the /var/log/zypper.log to the bug report."
62 , JobReport::UserData( "cmdout" ) );
63 }
64 return ret;
65 })();
66#endif // SINGLE_RPMTRANS_AS_DEFAULT_FOR_ZYPPER
67 return singleTrans;
68 }
69
71 //
72 // CLASS NAME : ZYppCommitPolicy::Impl
73 //
75
77 {
78 public:
80 : _restrictToMedia ( 0 )
81 , _downloadMode ( ZConfig::instance().commit_downloadMode() )
82 , _rpmInstFlags ( ZConfig::instance().rpmInstallFlags() )
83 , _syncPoolAfterCommit ( true )
85 {}
86
87 public:
90 target::rpm::RpmInstFlags _rpmInstFlags;
92 bool _singleTransMode; //< run everything in one big rpm transaction
93
94 private:
95 friend Impl * rwcowClone<Impl>( const Impl * rhs );
97 Impl * clone() const { return new Impl( *this ); }
98 };
99
101 //
102 // CLASS NAME : ZYppCommitPolicy
103 //
105
107 : _pimpl( new Impl )
108 {}
109
110
112 { _pimpl->_restrictToMedia = ( mediaNr_r == 1 ) ? 1 : 0; return *this; }
113
115 { return _pimpl->_restrictToMedia; }
116
117
119 { _pimpl->_rpmInstFlags.setFlag( target::rpm::RPMINST_TEST, yesNo_r ); return *this; }
120
122 { return _pimpl->_rpmInstFlags.testFlag( target::rpm::RPMINST_TEST );}
123
125 {
126 if ( singleTransModeEnabled() && val_r == DownloadAsNeeded ) {
127 DBG << val_r << " is not compatible with singleTransMode, falling back to " << DownloadInAdvance << std::endl;
128 _pimpl->_downloadMode = DownloadInAdvance;
129 }
130 _pimpl->_downloadMode = val_r; return *this;
131 }
132
134 {
135 if ( singleTransModeEnabled() && _pimpl->_downloadMode == DownloadAsNeeded ) {
136 DBG << _pimpl->_downloadMode << " is not compatible with singleTransMode, falling back to " << DownloadInAdvance << std::endl;
137 return DownloadInAdvance;
138 }
139 return _pimpl->_downloadMode;
140 }
141
142 ZYppCommitPolicy & ZYppCommitPolicy::rpmInstFlags( target::rpm::RpmInstFlags newFlags_r )
143 { _pimpl->_rpmInstFlags = newFlags_r; return *this; }
144
146 { _pimpl->_rpmInstFlags.setFlag( target::rpm::RPMINST_NOSIGNATURE, yesNo_r ); return *this; }
147
149 { _pimpl->_rpmInstFlags.setFlag( target::rpm::RPMINST_EXCLUDEDOCS, yesNo_r ); return *this; }
150
151 target::rpm::RpmInstFlags ZYppCommitPolicy::rpmInstFlags() const
152 { return _pimpl->_rpmInstFlags; }
153
155 { return _pimpl->_rpmInstFlags.testFlag( target::rpm::RPMINST_NOSIGNATURE ); }
156
158 { return _pimpl->_rpmInstFlags.testFlag( target::rpm::RPMINST_EXCLUDEDOCS ); }
159
161 { _pimpl->_rpmInstFlags.setFlag( target::rpm::RPMINST_ALLOWDOWNGRADE, yesNo_r ); return *this; }
162
164 { return _pimpl->_rpmInstFlags.testFlag( target::rpm::RPMINST_ALLOWDOWNGRADE ); }
165
167 { _pimpl->_rpmInstFlags.setFlag( target::rpm::RPMINST_REPLACEFILES, yesNo_r ); return *this; }
168
170 { return _pimpl->_rpmInstFlags.testFlag( target::rpm::RPMINST_REPLACEFILES ); }
171
173 { _pimpl->_syncPoolAfterCommit = yesNo_r; return *this; }
174
176 { return _pimpl->_syncPoolAfterCommit; }
177
179 { return _pimpl->_singleTransMode; }
180
181 std::ostream & operator<<( std::ostream & str, const ZYppCommitPolicy & obj )
182 {
183 str << "CommitPolicy(";
184 if ( obj.restrictToMedia() )
185 str << " restrictToMedia:" << obj.restrictToMedia();
186 if ( obj.dryRun() )
187 str << " dryRun";
188 str << " " << obj.downloadMode();
189 if ( obj.syncPoolAfterCommit() )
190 str << " syncPoolAfterCommit";
191 if ( obj.rpmInstFlags() )
192 str << " rpmInstFlags{" << str::hexstring(obj.rpmInstFlags()) << "}";
193 return str << " )";
194 }
195
197} // namespace zypp
Interim helper class to collect global options and settings.
Definition: ZConfig.h:64
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.
Typesafe passing of user data via callbacks.
Definition: UserData.h:39
Wrapper class for ::stat/::lstat.
Definition: PathInfo.h:221
String related utilities and Regular expression matching.
int readlink(const Pathname &symlink_r, Pathname &target_r)
Like 'readlink'.
Definition: PathInfo.cc:924
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 ImZYPPER()
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
Definition: SerialNumber.cc:52
bool singleTransInEnv()
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
static bool info(const std::string &msg_r, const UserData &userData_r=UserData())
send message text
#define DBG
Definition: Logger.h:95
#define WAR
Definition: Logger.h:97