libzypp 17.37.3
ZYppCommitPolicy.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12
13#include <iostream>
14
17
18#include <zypp/ZConfig.h>
19#include <zypp-core/APIConfig.h>
22#include <zypp-core/TriBool.h>
23#include <zypp/PathInfo.h>
24#include <zypp/ZYppCallbacks.h>
25#include <zypp/ZYppFactory.h>
26
28namespace zypp
29{
30
31 inline bool ImZYPPER()
32 {
33 static bool ret = filesystem::readlink( "/proc/self/exe" ).basename() == "zypper";
34 return ret;
35 }
36
37 inline bool singleTransInEnv()
38 {
39 const char *val = ::getenv("ZYPP_SINGLE_RPMTRANS");
40 return ( val && str::strToFalse( val ) );
41 }
42
43 inline bool singleTransEnabled()
44 {
45#if APIConfig(LIBZYPP_CONFIG_USE_CLASSIC_RPMTRANS_BY_DEFAULT)
46 return ImZYPPER() && singleTransInEnv();
47#else
48 return ImZYPPER();
49#endif
50 }
51
52
53 inline bool isPreUsrmerge( const Pathname & root_r )
54 {
55 // If systems /lib is a directory and not a symlink.
56 return PathInfo( root_r / "lib", PathInfo::LSTAT ).isDir();
57 }
58
60 {
61 // A package providing "may-perform-usrmerge" is going to be installed.
62 const sat::WhatProvides q { Capability("may-perform-usrmerge") };
63 for ( const auto & pi : q.poolItem() ) {
64 if ( pi.status().isToBeInstalled() )
65 return true;
66 }
67 return false;
68 }
69
70 inline bool pendingUsrmerge()
71 {
72 // NOTE: Bug 1189788 - UsrMerge: filesystem package breaks system when
73 // upgraded in a single rpm transaction. Target::Commit must amend this
74 // request depending on whether a UsrMerge may be performed by the
75 // transaction.
76 Target_Ptr target { getZYpp()->getTarget() };
77 bool ret = target && isPreUsrmerge( target->root() ) && transactionWillUsrmerge();
78 return ret;
79 }
80
82 //
83 // CLASS NAME : ZYppCommitPolicy::Impl
84 //
86
88 {
89 public:
91 : _restrictToMedia ( 0 )
92 , _downloadMode ( ZConfig::instance().commit_downloadMode() )
93 , _rpmInstFlags ( ZConfig::instance().rpmInstallFlags() )
94 , _syncPoolAfterCommit ( true )
96 {}
97
98 public:
101 target::rpm::RpmInstFlags _rpmInstFlags;
103 mutable bool _singleTransMode; // mutable: [bsc#1189788] pending usrmerge must disable singletrans
104
105 private:
106 friend Impl * rwcowClone<Impl>( const Impl * rhs );
108 Impl * clone() const { return new Impl( *this ); }
109 };
110
112 //
113 // CLASS NAME : ZYppCommitPolicy
114 //
116
120
121
123 { _pimpl->_restrictToMedia = ( mediaNr_r == 1 ) ? 1 : 0; return *this; }
124
126 { return _pimpl->_restrictToMedia; }
127
128
130 { _pimpl->_rpmInstFlags.setFlag( target::rpm::RPMINST_TEST, yesNo_r ); return *this; }
131
133 { return _pimpl->_rpmInstFlags.testFlag( target::rpm::RPMINST_TEST );}
134
136 { _pimpl->_downloadMode = val_r; return *this; }
137
139 {
140 if ( singleTransModeEnabled() && _pimpl->_downloadMode == DownloadAsNeeded ) {
141 DBG << _pimpl->_downloadMode << " is not compatible with singleTransMode, falling back to " << DownloadInAdvance << std::endl;
142 return DownloadInAdvance;
143 }
144 return _pimpl->_downloadMode;
145 }
146
147 ZYppCommitPolicy & ZYppCommitPolicy::rpmInstFlags( target::rpm::RpmInstFlags newFlags_r )
148 { _pimpl->_rpmInstFlags = newFlags_r; return *this; }
149
151 { _pimpl->_rpmInstFlags.setFlag( target::rpm::RPMINST_NOSIGNATURE, yesNo_r ); return *this; }
152
154 { _pimpl->_rpmInstFlags.setFlag( target::rpm::RPMINST_EXCLUDEDOCS, yesNo_r ); return *this; }
155
156 target::rpm::RpmInstFlags ZYppCommitPolicy::rpmInstFlags() const
157 { return _pimpl->_rpmInstFlags; }
158
160 { return _pimpl->_rpmInstFlags.testFlag( target::rpm::RPMINST_NOSIGNATURE ); }
161
163 { return _pimpl->_rpmInstFlags.testFlag( target::rpm::RPMINST_EXCLUDEDOCS ); }
164
166 { _pimpl->_rpmInstFlags.setFlag( target::rpm::RPMINST_ALLOWDOWNGRADE, yesNo_r ); return *this; }
167
169 { return _pimpl->_rpmInstFlags.testFlag( target::rpm::RPMINST_ALLOWDOWNGRADE ); }
170
172 { _pimpl->_rpmInstFlags.setFlag( target::rpm::RPMINST_REPLACEFILES, yesNo_r ); return *this; }
173
175 { return _pimpl->_rpmInstFlags.testFlag( target::rpm::RPMINST_REPLACEFILES ); }
176
178 { _pimpl->_syncPoolAfterCommit = yesNo_r; return *this; }
179
181 { return _pimpl->_syncPoolAfterCommit; }
182
184 {
185 if ( _pimpl->_singleTransMode and pendingUsrmerge() ) {
186 WAR << "Ignore $ZYPP_SINGLE_RPMTRANS=1: Bug 1189788 - UsrMerge: filesystem package breaks system when upgraded in a single rpm transaction" << std::endl;
188 "[bsc#1189788] The filesystem package seems to be unable to perform the pending\n"
189 " UsrMerge reliably in a single transaction. The single_rpmtrans\n"
190 " backend will therefore be IGNORED and the transaction is performed\n"
191 " by the classic_rpmtrans backend."
192 , JobReport::UserData( "cmdout", "[bsc#1189788]" ) );
193 _pimpl->_singleTransMode = false;
194 }
195 return _pimpl->_singleTransMode;
196 }
197
198 std::ostream & operator<<( std::ostream & str, const ZYppCommitPolicy & obj )
199 {
200 str << "CommitPolicy(";
201 if ( obj.restrictToMedia() )
202 str << " restrictToMedia:" << obj.restrictToMedia();
203 if ( obj.dryRun() )
204 str << " dryRun";
205 str << " " << obj.downloadMode();
206 if ( obj.syncPoolAfterCommit() )
207 str << " syncPoolAfterCommit";
208 if ( obj.rpmInstFlags() )
209 str << " rpmInstFlags{" << str::hexstring(obj.rpmInstFlags()) << "}";
210 return str << " )";
211 }
212
214} // namespace zypp
A sat capability.
Definition Capability.h:63
Interim helper class to collect global options and settings.
Definition ZConfig.h:69
Impl * clone() const
clone for RWCOW_pointer
friend Impl * rwcowClone(const Impl *rhs)
target::rpm::RpmInstFlags _rpmInstFlags
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
RWCOW_pointer< Impl > _pimpl
Pointer to data.
ZYpp::Ptr getZYpp()
Convenience to get the Pointer to the ZYpp instance.
Definition ZYppFactory.h:77
Wrapper class for stat/lstat.
Definition PathInfo.h:226
Container of Solvable providing a Capability (read only).
String related utilities and Regular expression matching.
int readlink(const Pathname &symlink_r, Pathname &target_r)
Like 'readlink'.
Definition PathInfo.cc:929
std::string hexstring(char n, int w=4)
Definition String.h:325
bool strToFalse(const C_Str &str)
Return false if str is 0, false, no, off, never.
Definition String.cc:84
Easy-to use interface to the ZYPP dependency resolver.
bool pendingUsrmerge()
bool isPreUsrmerge(const Pathname &root_r)
bool ImZYPPER()
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
bool singleTransEnabled()
bool singleTransInEnv()
bool transactionWillUsrmerge()
DownloadMode
Supported commit download policies.
@ DownloadAsNeeded
Alternating download and install.
@ DownloadInAdvance
First download all packages to the local cache.
callback::UserData UserData
typsafe map of userdata
static bool info(const std::string &msg_r, const UserData &userData_r=UserData())
send message text
#define DBG
Definition Logger.h:99
#define WAR
Definition Logger.h:101